5

I'm fetching transaction data using Etherscan API. This is the example result I'm getting:

{
  blockNumber: '7409930',
  timeStamp: '1639151980',
  hash: '...',
  nonce: '4124',
  ...
  input: '0x9d90e4c8000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002000000000000000000000000093238bb66b5d15b4152c5db574e3397ff1b1a450',
  contractAddress: '',
  cumulativeGasUsed: '403775',
  gasUsed: '1162315',
  confirmations: '191308'
}

I now need to figure out the event type (contract method, e.g. TransferOwnership, stakeTokens,...) for this transaction. This data is stored in input property of this object.

I managed to accomplish this using abi-decoder library, but I want to accomplish the same thing using ethers's utility method (whichever).

My current implementation:

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);

I was reading through ether's documentation (https://docs.ethers.io/v5/api/utils/abi/coder/), but I can't figure it out.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Jan Potočnik
  • 51
  • 1
  • 2

1 Answers1

0

you can try what is recommended in this: https://github.com/ethers-io/ethers.js/issues/423 . but if you are interacting with BSC, this is not possible due to the error input data too big causing Error in Big Number Number can only safely store up to 53 bits

Phạm Huy Phát
  • 783
  • 9
  • 17