Skip to content

Instantly share code, notes, and snippets.

View earthchie's full-sized avatar

Thanarat Kuawattanaphan earthchie

View GitHub Profile
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 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 = {
@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 {
@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
// 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 / 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;
/**
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 / DLT_applyFields.js
Last active October 1, 2024 15:48
ระบบช่วยกรอกข้อมูล จองทะเบียนรถ ที่ https://reserve.dlt.go.th/reserve/s.php (อ่านรายละเอียดที่คอมเมนต์ด้านล่าง)
DLT_applyFields({
id: '1122334455667',
prefix: 'นาย', // ต้องสะกดให้เหมือนตัวเลือกใน dropdown เป้ะๆ
name: 'ธนารัตน์',
lname: 'นักจองทะเบียน',
phone: '0812345678',
brand: 'LAMBORGHINI', // ต้องสะกดให้เหมือนตัวเลือกใน dropdown เป้ะๆ
cassis: 'MR1234567890',
number: '999' // แนะนำให้แก้โค้ดส่วนนี้ ปรับให้อ่านค่าจาก localStorage จะได้ไม่ต้องรันเลขเองด้วยมือทุกครั้ง
});
@earthchie
earthchie / NostrKeyFinder.js
Last active September 5, 2024 14:54
find a nip19 key with specific prefix for using on Nostr
const {nip19, generatePrivateKey, getPublicKey} = require('nostr-tools');
let found = false;
let counter = 0;
while(!found){
counter++;
if(counter%100000 == 0){
console.log('Reached iteration #' + counter.toLocaleString());
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract ThaiChainSBT is ERC721URIStorage, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;