Skip to content

Instantly share code, notes, and snippets.

@stonegao
stonegao / amulet.ts
Created September 9, 2021 16:54 — forked from mrbrucespringsteen/amulet.ts
amulet verification code
import { utils } from 'ethers'
export interface Amulet {
value: string;
hash: string;
count: number;
}
const getAmuletCount = (hash: string): number => {
const matches = hash.match(/(8)\1*/g);
/**
* 1. Initialize new node project (npm init -y)
* 2. Run: npm install ethers
* 3. Add private key where PRIVATE_KEY
* 4. Optionally, update gas price (line 29) or chosen gas limit
* 4. Run: node score-claim.js
*/
// Imports
const ethers = require("ethers");
const { parseUnits } = require("@ethersproject/units");
require("dotenv").config();
const ethers = require("ethers");
const axios = require('axios').default;
const provider = new ethers.providers.JsonRpcProvider(`https://eth-mainnet.alchemyapi.io/v2/${process.env.NEXT_PUBLIC_ALCHEMY_API_KEY}`);
const alg = new ethers.Contract(
"0x32353A6C91143bfd6C7d363B546e62a9A2489A20",
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"inde
@stonegao
stonegao / check-settlement.js
Created September 4, 2021 23:52 — forked from mehranhydary/check-settlement.js
check-settlement.js
/*
1. Run `npm init` in a new folder
2. Install ethers.js with `npm i ethers`
3. Create a file called `check-settlement.js`
4. Copy the script below and save it in the file you create
5. In your terminal, run `node check-settlement.js`
*/
require("dotenv").config();
const ethers = require("ethers");
const axios = require('axios').default;
/**
* 1. Initialize new node project (npm init -y)
* 2. Run: npm install ethers
* 3. Add private key where PRIVATE_KEY
* 4. Optionally, update gas price (line 29) or chosen gas limit
* 5. Run: node mint-temporal-loot.js
* 6. NOTE: Don't forget to get an API key fgrom Alchemy and replace the variable in line 15
*/
// Imports
require("dotenv").config();
@stonegao
stonegao / Fee1155NFTLockable.sol
Created August 16, 2021 08:39 — forked from TimTinkers/Fee1155NFTLockable.sol
A gas-efficient mintable, lockable NFT creation contract for OpenSea listing.
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./FeeOwner.sol";
@stonegao
stonegao / eventFilter.js
Created July 15, 2021 08:35 — forked from wschwab/eventFilter.js
a handmade Ethereum event filter that you should never really use
const eventFilter = (contractAddress, contractAbi, eventName, _provider) => {
const provider = _provider
// this will return an array with an object for each event
const events = contractAbi.abi.filter(obj => obj.type ? obj.type === "event" : false);
// getting the Transfer event and pulling it out of its array
const event = events.filter(event => event.name === eventName)[0];
// getting the types for the event signature
const types = event.inputs.map(input => input.type)
// knowing which types are indexed will be useful later
let indexedInputs = [];

Transaction: https://etherscan.io/tx/0xb5c8bd9430b6cc87a0e2fe110ece6bf527fa4f170a4bc8cd032f768fc5219838

Contract Hacker Contract (4f4e)

Eth Transferred:

  • TRANSFER 5,500 Ether From Hacker Contract (4f4e) To Compound (4ddc)
  • TRANSFER 1,300 Ether From Hacker Contract (4f4e) To Unknown token (b020)
  • TRANSFER 1,300 Ether From Unknown token (b020) To 0x Weth (c02a)
  • TRANSFER 5,637.623762376237623786 Ether From 0x Weth (c02a) To Kyber 1 (57f8)
  • TRANSFER 5,637.623762376237623786 Ether From Kyber 1 (57f8) To Kyber 2 (65bf)

深入理解以太坊

-w1544

目标

  • 理解以太坊的底层运行机制
    • 本文主要关注为什么这么做、基本原理、实现效果,2/8法则,花 20% 的精力掌握 80% 的内容
    • 细节实现会留 reference,如果想研究,建议用以下方式:1. 走一遍 demo,搞清楚所有的细节,例如 EVM 合约的执行流程;2. 自己实现一遍,比如 MPT、EVM,甚至整个以太坊客户端。
  • 概览以太坊生态全景
@stonegao
stonegao / psql-error-fix.md
Created March 25, 2020 07:55 — forked from AtulKsol/psql-error-fix.md
Solution of psql: FATAL: Peer authentication failed for user “postgres” (or any user)

psql: FATAL: Peer authentication failed for user “postgres” (or any user)

The connection failed because by default psql connects over UNIX sockets using peer authentication, that requires the current UNIX user to have the same user name as psql. So you will have to create the UNIX user postgres and then login as postgres or use sudo -u postgres psql database-name for accessing the database (and psql should not ask for a password).

If you cannot or do not want to create the UNIX user, like if you just want to connect to your database for ad hoc queries, forcing a socket connection using psql --host=localhost --dbname=database-name --username=postgres (as pointed out by @meyerson answer) will solve your immediate problem.

But if you intend to force password authentication over Unix sockets instead of the peer method, try changing the following pg_hba.conf* line:

from