const fs = require("fs"); const axios = require("axios") // web3.eth.defaultAccount = '0x50A8e60041A206AcaA5F844a1104896224be6F39' const Web3 = require('web3'); // const jsontxt = fs.readFileSync('./build/contracts/ERC721.json', 'utf-8') // const jsonabi = JSON.parse(jsontxt) const abimodule = require('./abi_code'); // IsDbg = false; IsDbg = true; const RPC = IsDbg? 'https://sepolia.drpc.org': // 'https://eth-sepolia.public.blastapi.io': 'https://ethereum.publicnode.com' // 'https://eth-mainnet.g.alchemy.com/v2/5OZeb3Gly2poPeCFhnK7qVsCMDB_oPwO' //'https://eth-mainnet.public.blastapi.io' //'https://arbitrum-sepolia.infura.io/v3/8ae5bef48da14bbbac03860879a08bd7' // const w3 = new Web3('https://arbitrum-one.public.blastapi.io') const w3 = new Web3(RPC) console.log('start') async function getNonce(addr){ return await w3.eth.getTransactionCount(addr) } const BRIDGE_ADDRESS = IsDbg? "0x0D3C59c779Fd552C27b23F723E80246c840100F5": "0xBa5E35E26Ae59c7aea6F029B68c6460De2d13eB6" const PRIVATE_KEY = '' const MI = { sc: BRIDGE_ADDRESS, abi: [{ "inputs": [{ "internalType": "address", "name": "receiver", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "depositToETH", "outputs": [], "stateMutability": "payable", "type": "function" } ], func: "depositToETH" } let SCInstance = null let FromAddr = null const initInstance = async() => { // let account = w3.eth.accounts.privateKeyToAccount(PRIVATE_KEY); let account = w3.eth.accounts.wallet.add(PRIVATE_KEY); console.log('account:', account) // const accounts = await w3.eth.getAccounts(); // console.log('accounts:', accounts) // if(accounts.length > 0){ // FromAddr = accounts[0] // } FromAddr = account.address SCInstance = new w3.eth.Contract(MI.abi, MI.sc); return SCInstance } const bridge = async() => { if(!SCInstance){ await initInstance() } const amt = Web3.utils.toWei('0.001', 'ether') console.log('amt:', amt) // const val = Web3.utils.fromWei(amt, 'ether') const val = amt console.log('val:', val) const fromaddr = FromAddr console.log('fromaddr:', fromaddr) const toaddr = FromAddr const gp = await w3.eth.getGasPrice() console.log('gp:', gp) const params = [{from: fromaddr, value: val * 2}] // const gc = IsDbg? 21798: await SCInstance.methods.depositToETH(toaddr, amt).estimateGas(...params) const gc = await SCInstance.methods.depositToETH(toaddr, amt).estimateGas(...params) const fee = gp * gc * 2 console.log('fee:', fee, 'gp:', gp, 'gc:', gc) const newval = Web3.utils.toBN(val).add(Web3.utils.toBN(fee)).toString() console.log('val:', newval) // const params2 = [{from: fromaddr}, {value: newval}] const params2 = [{from: fromaddr, value: newval, gas: gc * 10, gasPrice: gp}] try{ // const receipt = await SCInstance.methods.depositToETH(toaddr, amt).send(...params2) // console.log('receipt:', receipt) }catch(err){ console.log('err:', err) } } const checkBalance = async(addr) => { if(!SCInstance){ initInstance() } let banlace = await SCInstance.methods.balanceOf(addr).call(); return parseFloat(banlace); } const getTokenId = async(addr) =>{ if(!SCInstance){ initInstance() } let tokenid = await SCInstance.methods.tokenOfOwnerByIndex(addr, 0).call(); return tokenid; } const checkIsMint = async (address) => { contract = '0x20c095fb98b7F353b859c42589f2322248Ea8A23' url = RPC const data = { id: (Date.now() / 1000) | 0, jsonrpc: '2.0', method: 'eth_call', params: [ { data: `0x425a69cc000000000000000000000000${address.replace('0x', '')}`, from: address, to: contract, }, 'latest', ], } const reqConfig = { method: 'post', url, headers: { 'Content-Type': 'application/json', 'cache-control': 'no-cache', pragma: 'no-cache', }, data: JSON.stringify(data), } let res = await axios(reqConfig).then(response => response.data) if(res && res.result){ let no = parseInt(res.result) return no > 0 }else{ console.log('error:', res) return 0 } } async function checkToken(){ // const str = fs.readFileSync("nft_claim_address_list.txt").toString().trim(); const str = fs.readFileSync("150.txt").toString().trim(); // const str = fs.readFileSync("team.txt").toString().trim(); const walletlst = str.split('\n') let rescount = 0; let cmstr = '' let nomintcount = 0 let mstr = '' let reslst = [] for(let i = 0; i < walletlst.length; i++){ let addr = walletlst[i].trim() // let isOk = await checkIsMint(addr) let ncount = await checkBalance(addr) let isOk = ncount > 0 if(isOk){ let tokenid = await getTokenId(addr) reslst.push( { idx: i, addr: addr, token: `#${tokenid}` } ) // console.log(`${addr}`) rescount++; mstr = mstr + addr + '\n' }else{ console.log(`${addr}`) nomintcount++ cmstr = cmstr + addr + '\n' } // let count = await checkContractMethod(addr) // if(count > 0){ // // console.log(`${addr}:${count}`) // rescount++; // }else{ // nomintcount++ // console.log(`${addr}`) // cmstr = cmstr + addr + '\n' // } } console.log('minted count:', rescount) console.log('not minted count:', nomintcount) fs.writeFileSync("no_claim.txt", cmstr) fs.writeFileSync("claim.txt", mstr) fs.writeFileSync("detail.json", JSON.stringify(reslst)) } function getTokenRare(){ let str = fs.readFileSync('detail.json') let detail = JSON.parse(str) str = fs.readFileSync('rare.json') let rare = JSON.parse(str) let rarecount = 0 let legendcount = 0 for(let i =0; i < detail.length;i++){ let obj = detail[i] let idx = rare.findIndex((item)=>{ let s = '#' + item.id return s === obj.token }) if(idx >= 0){ console.log(rare[idx]) obj.rare = rare[idx].rarity if(obj.rare === 'Rare'){ rarecount++ }else if(obj.rare === 'Legendary'){ legendcount++ } } } console.log(`rare:${rarecount} legend:${legendcount}`) fs.writeFileSync("detail.json", JSON.stringify(detail)) } async function getEthBalance(addr){ let balance = await w3.eth.getBalance(addr) if(balance > 0){ balance = w3.utils.fromWei(balance, 'ether') } return balance } async function checkEth(){ const str = fs.readFileSync("150.txt").toString().trim(); // const str = fs.readFileSync("team.txt").toString().trim(); const walletlst = str.split('\n') let rescount = 0; let cmstr = '' for(let i = 0; i < walletlst.length; i++){ let addr = walletlst[i].trim() // let isOk = await checkIsMint(addr) let neth = await getEthBalance(addr) rescount += parseFloat(neth) cmstr = cmstr + '' + neth + '\n' } console.log(`total:${rescount}`) fs.writeFileSync("eth.txt", cmstr) } async function checkListBalance(filename){ const str = fs.readFileSync(filename).toString().trim(); const walletlst = str.split('\n') let rescount = 0; let cmstr = '' for(let i = 0; i < walletlst.length; i++){ let addr = walletlst[i].trim() if(!addr){ continue } // let isOk = await checkIsMint(addr) let ncount = await checkBalance(addr) rescount += ncount cmstr = cmstr + '' + ncount + '\n' } console.log(`total:${rescount}`) fs.writeFileSync("balance.txt", cmstr) } async function main(){ // const nonce = await getNonce("0x7E8E62EF14E9ae1a0B1dd753b45AA42Faa6208D7") // console.log('nonce:', nonce) // const msg = 'some msg that need sign' // let res = w3.eth.accounts.sign(msg, arbOneKey) // console.log(res) // let hash = w3.eth.accounts.hashMessage(res.signature) // console.log(hash) // let res = await abimodule.getBalance() // console.log(res) // if (res > 0){ // } // let res = await abimodule.getPastEvents() // console.log(res) // await checkToken() // getTokenRare() // await checkEth() // await checkListBalance('checkaddrs.txt') await bridge() console.log("done") } main()