Skip to content

Instantly share code, notes, and snippets.

View earthchie's full-sized avatar

Thanarat Kuawattanaphan earthchie

View GitHub Profile
@earthchie
earthchie / Sphinx31.bot.js
Last active April 3, 2023 11:30
Sphinx31 automatic obtain
// require ethers@5
const Sphinx31Watcher = provider.on('block', async function(){
const provider = new ethers.providers.JsonRpcProvider('https://rpc-l1.jibchain.net');
const wallet = new Wallet('0x...private_key....');
const Sphinx31 = new ethers.Contract('0xd431d826d7a4380b9259612176f00528b88840a7', [
'function supplier(address addr) view returns (bool isCraft, uint256 machineIndex, uint256 laststamp)',
'function machine(uint256 _machineIndex) view returns (bool active, uint256 duration, uint256 miceCost, uint256 cmjCost, uint256 sx31Reward)',
'function obtain(uint256 _machineIndex)'
@earthchie
earthchie / JBC.getAssetsOfAddress.js
Last active January 23, 2023 11:01
Retrieve all Tokens and NFTs of a specific wallet address on JBC network
async function getAssetsOfAddress(addr){
const parseNFTMetadata = async function (metadata, ipfs_gateway = 'https://cloudflare-ipfs.com/ipfs/'){
const applyIPFSGateway = function(uri){
if(uri instanceof Array){
return uri.map(i=>applyIPFSGateway(i));
}else if(typeof uri === 'object'){
Object.keys(uri).forEach(k=>{
uri[k] = applyIPFSGateway(uri[k]);
});
return uri;
@earthchie
earthchie / parseNFTMetadata.js
Last active March 16, 2023 05:21
Snippet for parsing the NFT metadata using the Fetch API. Supports both URI and IPFS format.
async function parseNFTMetadata(metadata, ipfs_gateway = 'https://ipfs.io/ipfs/'){
const applyIPFSGateway = function(uri){
if(uri instanceof Array){
return uri.map(i=>applyIPFSGateway(i));
}else if(typeof uri === 'object'){
Object.keys(uri).forEach(k=>{
uri[k] = applyIPFSGateway(uri[k]);
});
return uri;
}else if(typeof uri === 'string'){
const slip39 = require('slip39');
const original = 'Secret Message Here';
const shares = splitSLIP39(original);
console.log('Shares', shares);
const recoverd = recoverSLIP39([shares[1], shares[0]]); // pick any two to recover
console.log(recoverd);
// 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;
@earthchie
earthchie / NostrKeyFinder.js
Last active December 28, 2022 16:56
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());
}
@earthchie
earthchie / DLT_applyFields.js
Last active April 12, 2023 17:16
ระบบช่วยกรอกข้อมูล จองทะเบียนรถ ที่ 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 จะได้ไม่ต้องรันเลขเองด้วยมือทุกครั้ง
});
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/IERC165.sol@v4.7.0
// 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/IERC20.sol@v4.3.2
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.