Jan*_*nik 5 javascript ethereum web3js etherscan ethers.js
我正在使用 Etherscan API 获取交易数据。这是我得到的示例结果:
{
blockNumber: '7409930',
timeStamp: '1639151980',
hash: '...',
nonce: '4124',
...
input: '0x9d90e4c8000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002000000000000000000000000093238bb66b5d15b4152c5db574e3397ff1b1a450',
contractAddress: '',
cumulativeGasUsed: '403775',
gasUsed: '1162315',
confirmations: '191308'
}
Run Code Online (Sandbox Code Playgroud)
我现在需要找出该交易的事件类型(合约方法,例如,,...)TransferOwnership。stakeTokens该数据存储在input该对象的属性中。
我设法使用abi-decoder库来完成此任务,但我想使用 ethers 的实用方法(以哪种方式)来完成同样的事情。
我当前的实现:
const abiDecoder = require("abi-decoder");
abiDecoder.addABI(contractAbi);
// "item" is transaction data, input property is encoded stuff from which I want to get the contract method used by this transaction
const decodedInput = abiDecoder.decodeMethod(item.input);
// contract method
console.log(decodedInput.name);
Run Code Online (Sandbox Code Playgroud)
我正在阅读以太坊的文档(https://docs.ethers.io/v5/api/utils/abi/coder/),但我无法弄清楚。
小智 0
您可以尝试以下建议: https: //github.com/ethers-io/ethers.js/issues/423。但如果您与 BSC 交互,这是不可能的,因为错误输入数据太大,导致大数错误Number can only safely store up to 53 bits