欢迎使用Ledger硬件钱包
lesson1
发布于 7 个月前 作者 insightcj 418 次浏览 来自 技术/人物

const axios = require(‘axios’); const schedule = require(‘node-schedule’);

const url = “https://kovan.infura.io/v3/9fb57308edef40d2940b06e2a60b3bb7”; const data = { “id”: new Date().getTime(), “jsonrpc”: “2.0”, “method”: “eth_getBlockByNumber”, “params”:[“latest”, true] };

const addresses = { “0x627306090abab3a6e1400e9345bc60c78a8bef57”: “c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3”, “0xf17f52151ebef6c7334fad080c5704d77216b732”: “ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f”, “0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef”: “0dbbe8e4ae425a6d2687f1a7e3ba17bc98c673636790f1b8ad91193c05875ef1”, “0x821aea9a577a9b44299b9c15c88cf3087f3b5544”: “c88b703fb08cbea894b6aeff5a544fb92e78a18e19814cd85da83b71f772aa6c”, “0x0d1d4e623d10f9fba5db95830f7d3839406c6af2”: “388c684f0ba1ef5017716adb5d21a053ea8e90277d0868337519f97bede61418”, “0x2932b7a2355d6fecc4b5c0b6bd44cc31df247a2e”: “659cbb0e2411a44db63778987b1e22153c086a95eb6b18bdf89de078917abc63”, “0x2191ef87e392377ec08e7c08eb105ef5448eced5”: “82d052c865f5763aad42add438569276c00d3d88a2d062d36b2bae914d58b8c8”, “0x0f4f2ac550a1b4e2280d04c21cea7ebd822934b5”: “aa3680d5d48a8283413f7a108367c7299ca73f553735860a87b08f39395618b7”, “0x6330a553fc93768f612722bb8c2ec78ac90b3bbc”: “0f62d96d6675f32685bbdb8ac13cda7c23436f63efbb9d07700d8669ff12b7c4”, “0x5aeda56215b167893e80b4fe645ba6d5bab767de”: “8d5366123cb560bb606379f90a0bfd4769eecc0557f1b362dcae9012b548b1e5” }; const post = async ({ data, url }) =>{ const result = await axios({ method: ‘post’, url, data }); return result; }

const test = async () =>{ const { data: { result, error }} = await post({ data, url }); // console.log(result); if(result){ const { transactions } = result; // console.log(transactions); for (const { from, to, value } of transactions) { console.log(from, to, value); if(addresses[to]){ console.log(‘发现钱啦!💰’,to); } } } }

schedule.scheduleJob(’*/1 * * * * *’, function(){ test(); });

欢迎使用MoleSwap交易所,银河系最好的去中心化交易所
3 回复

const axios = require(‘axios’); const url = “https://kovan.infura.io/v3/9fb57308edef40d2940b06e2a60b3bb7”;

const addresses = { “0x627306090abab3a6e1400e9345bc60c78a8bef57”: “c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3”, “0xf17f52151ebef6c7334fad080c5704d77216b732”: “ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f”, “0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef”: “0dbbe8e4ae425a6d2687f1a7e3ba17bc98c673636790f1b8ad91193c05875ef1”, “0x821aea9a577a9b44299b9c15c88cf3087f3b5544”: “c88b703fb08cbea894b6aeff5a544fb92e78a18e19814cd85da83b71f772aa6c”, “0x0d1d4e623d10f9fba5db95830f7d3839406c6af2”: “388c684f0ba1ef5017716adb5d21a053ea8e90277d0868337519f97bede61418”, “0x2932b7a2355d6fecc4b5c0b6bd44cc31df247a2e”: “659cbb0e2411a44db63778987b1e22153c086a95eb6b18bdf89de078917abc63”, “0x2191ef87e392377ec08e7c08eb105ef5448eced5”: “82d052c865f5763aad42add438569276c00d3d88a2d062d36b2bae914d58b8c8”, “0x0f4f2ac550a1b4e2280d04c21cea7ebd822934b5”: “aa3680d5d48a8283413f7a108367c7299ca73f553735860a87b08f39395618b7”, “0x6330a553fc93768f612722bb8c2ec78ac90b3bbc”: “0f62d96d6675f32685bbdb8ac13cda7c23436f63efbb9d07700d8669ff12b7c4”, “0x5aeda56215b167893e80b4fe645ba6d5bab767de”: “8d5366123cb560bb606379f90a0bfd4769eecc0557f1b362dcae9012b548b1e5” };

// post请求,获取以太坊余额 const post = async ({ address, url }) =>{ const data = { id: new Date().getTime(), method: ‘eth_getBalance’, params: [address, ‘latest’] }; const result = await axios({ method: ‘post’, url, data }); return result; }

// 虚拟币小数位控制算法,所有虚拟币都可以用这种方式,采用big或者bignumnber这样的包 // JAVA 和 python中有类似的包 const Big = require(‘bignumber.js’);

Big.NE = -19; Big.PE = 22; const hexToNumberString = (numHex) => Big(numHex, 16).toFixed(); const coinDecimal = (value, decimal) => Big(value).div(decimal).toFixed();

const test = async () =>{ const decimal = 1000000000000000000; for (const address of Object.keys(addresses)) { console.log(’ ') console.log(‘扫描地址:’, address) const { data: { result, error }} = await post({ address, url }); console.log(‘扫描结果:’, result); const balanceWei = hexToNumberString(result); console.log(‘转换为10进制:’, balanceWei ); const balanceEther = coinDecimal(balanceWei, decimal); console.log(‘转换单位wei-> ether:’, balanceEther);

}

}

// 以太坊单位 wei gui ether // 1000000000000000000 wei(18) = 1 ether api掉parity/geth单位都是wei // 1000000000 wei(9) = 1gui 手续费计费单位都是gui // 1000000000 gui(9) = 1ether 交易单位都是ether

test();

const Big = require(‘bignumber.js’); const Common = require(’@ethereumjs/common/dist/index’).default; const { Transaction } = require(’@ethereumjs/tx’);

const coin = ‘ETH’; const privateKey = ‘8F1B8C52856B4AD448FF127108F3A5CD2B0B3FD4A9F91C627CF947E6B8C2499B’; const address = ‘0x9e8F37678D9a54a745e085b83d704720F40Df4Ad’;

const to = ‘0x5f7187E27C0684456A332c9F05B770061C97FA7e’; const amount = ‘0.1’; // ETH const fee = { gasLimit: 21000, gasPrice: 1, };

const main = async () => { // metamask sign const { gasLimit, gasPrice } = fee; const txParams = { nonce: 0x${Big(11).toString(16)}, gasLimit: 0x${Big(gasLimit).toString(16)}, to, gasPrice: 0x${Big(gasPrice).times('1e+9').toString(16)}, value: 0x${Big(amount).times('1e+18').toString(16)}, };

// chain 42:kovan chain 1:mainnet chain 62:bsc // 避免重放攻击 const common = new Common({ chain: ‘kovan’ }); const tx = Transaction.fromTxData(txParams, { common });

const pr = Buffer.from(privateKey, ‘hex’);

const signedTx = tx.sign(pr); const serializedTx = signedTx.serialize();

console.log(‘address’, signedTx.getSenderAddress().toString(‘hex’)); console.log(‘txid’, signedTx.hash().toString(‘hex’)); console.log(‘txBlob’, signedTx.serialize().toString(‘hex’));

return serializedTx; };

main();

嗯,原来如此

回到顶部