Skip to content

TX Hash - Decode "Input Data" field #1637

Answered by ricmoo
elthom21 asked this question in Q&A
Discussion options

You must be logged in to vote

You can use use the Interface object to simplify your life.

const iface = new ethers.utils.Interface([ "function foo(uint bar)" ])
const info = iface.parseTransaction({ data: "0x2fbebd3800000000000000000000000000000000000000000000000000000000000004d2" })
/*
TransactionDescription {
  args: [
    BigNumber { _hex: '0x04d2', _isBigNumber: true },
    bar: BigNumber { _hex: '0x04d2', _isBigNumber: true }
  ],
  functionFragment: FunctionFragment { ... },
  name: 'foo',
  signature: 'foo(uint256)',
  sighash: '0x2fbebd38',
  value: BigNumber { _hex: '0x00', _isBigNumber: true }
}
*/

// Available positionally or via its name (if named)
console.log(info.args[0]);
console.log(info.bar);

Let me …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ricmoo
Comment options

@elthom21
Comment options

Answer selected by ricmoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1636 on June 02, 2021 01:54.