Skip to content

Instantly share code, notes, and snippets.

View earthchie's full-sized avatar

Thanarat Kuawattanaphan earthchie

View GitHub Profile
const ethers = require('ethers');
async function app() {
const privateKey = '...'; // bridge wallet, has permission to mint and burn
const abi = [
'event Transfer(address indexed from, address indexed to, uint256 value)',
'function mint(address receiver, uint256 amount)',
'function burn(address account, uint256 amount)'
@earthchie
earthchie / nft.sol
Created July 7, 2022 04:54
flatten from openzeppelin
// Sources flattened with hardhat v2.9.9 https://hardhat.org
// File @openzeppelin/contracts/utils/introspection/[email protected]
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
// Sources flattened with hardhat v2.6.8 https://hardhat.org
// File @openzeppelin/contracts/token/ERC20/[email protected]
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
@earthchie
earthchie / memo.js
Last active July 31, 2024 10:44
Add text memo to blockchain transaction with ethers.js
const provider = new ethers.providers.JsonRpcProvider('https://data-seed-prebsc-1-s1.binance.org:8545/'); // TESTNET
const privateKey = '0xea0beba96beab7b2b8a79b2142f89c07a51342d6a2ebb0822267096d5b65abf7'; // address: 0x8526aDDf97F478bEb92223383778A4e8688951D9
const wallet = new ethers.Wallet(privateKey, provider);
let balance = await provider.getBalance(wallet.address);
console.log('My Initial Balance is:', ethers.utils.formatEther(balance));
const trx = await wallet.sendTransaction({
to: '0x4Bd3Cea4dbeCb1bE89e690A049Ce7fa533B1d1eE', // private key: 0x002d370dbb49f65b232c69852f1148232bafd5c4427c0cf8ee52a1bbb72fe2f8
@earthchie
earthchie / election.sol
Created September 8, 2021 09:56
Verify blind signature for e-Election
// SPDX-License-Identifier: COPYRIGHT 2021 DOMECLOUD CO. LTD. ALL RIGHTS RESERVED.
pragma solidity >=0.4.20 <0.6;
import "hardhat/console.sol";
contract Election{
// N factor can be retrived from Election Comission's public key.
// use for Blind Signature verification
bytes public N_factor;
constructor(bytes memory N) public {
const ethers = require('ethers');
const DeFiSDK = require('./defi-sdk/defi-sdk-node');
const DeFi = new DeFiSDK('https://bsc-dataseed.binance.org/', 'your private key or mnemonic keys');
DeFi.loadContracts().then(async () => {
console.log('Ready...');
const offset = 5; // in percent
let DOP = {
pragma solidity ^0.5.16;
interface IERC20 {
function balanceOf(address _owner) external view returns (uint256 balance);
function transfer(address _to, uint256 _value) external returns (bool success);
}
interface IFlashloanReceiver {
function executeOperation(
address sender,
const ethers = require('ethers');
const provider = new ethers.providers.JsonRpcProvider('https://bsc-dataseed.binance.org/');
// you can find pair address from Factory Contract, method getPair(token1Addr, token2Addr).
let Contract = {
PancakePair: new ethers.Contract('0xb694ec7C2a7C433E69200b1dA3EBc86907B4578B',['function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast)'], provider),
TwindexPair: new ethers.Contract('0xC789F6C658809eED4d1769a46fc7BCe5dbB8316E',['function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast)'], provider)
}
@earthchie
earthchie / searchForWalletFromMnemonic.js
Last active May 23, 2021 05:03
ตามหา private key และ path ของกระเป๋าที่สูญหาย จาก mnemonic keys
const ethers = require('ethers');
const mnemonic = `critic seek crop move student season draw fiscal put prevent message cereal`
const target = `0xB1aB1cdC94e4edC8a7cc3187D5CCE0169de7505c`;
let i = -1;
let wallet;
console.log('searching...')
do {
const { ethers } = require('ethers');
const provider = new ethers.providers.JsonRpcProvider('https://bsc-dataseed.binance.org/');
const BEP20 = {
BUSD: '0xe9e7cea3dedca5984780bafc599bd69add087d56',
DOP: '0x844fa82f1e54824655470970f7004dd90546bb28',
};
const Contract = {
router: new ethers.Contract(