1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| cnpm install etherscan-api --save const api = require('etherscan-api').init('YourApiKey','rinkeby', '3000') Parameters: apiKey (string) (optional) Your Etherscan APIkey chain (string) (optional) Testnet chain keys [ropsten, rinkeby, kovan] timeout (number) (optional) Timeout in milliseconds for requests, default 10000 let blockNumber = ethapi.proxy.eth_getBlockByNumber('0x10d4f') getLogs(address: any, fromBlock: string, toBlock: string, topic0: string, topic0_1_opr: string, topic1: string, topic1_2_opr: string, topic2: string, topic2_3_opr: string, topic3: string, topic0_2_opr: string)
eg: const ethapi = require('etherscan-api').init('DYX3xxxxx','ropsten', '3000') let logs = await _this.ethapi.log.getLogs('0x98C59036C71Ef10684b3A4a3ffA85b280fe7b402', 0, 'latest') {status: "1", message: "OK", result: Array(3)}
https:
主网的Host是 api.etherscan.io
api-ropsten.etherscan.io api-kovan.etherscan.io api-rinkeby.etherscan.io
getLogs(){ let _this = this async function main() { let res = await _this.axios.request({ method: 'get', url: 'https://api-ropsten.etherscan.io/api?module=logs\&' + 'action=getLogs&fromBlock=0\&' + 'toBlock=latest\&' + 'address=0xF1484DB8e5adf717E83c105cc0aD1D9668Cc076c\&' + 'apikey=DYX36xxxxxxxx', }) console.log(999, res) console.log(99911, res.data.result) } main() }
|