Skip to content

Find a matching ABI function by selector. #1406

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

You must be logged in to vote

Either of those will work, but you can also just pass a sighash (or any allowed fragment specifier) into the interface.getFunction method, and it will find it for you. :)

It will throw though, if it isn't available in the Interface, so you will still need the try...catch.

e.g.

homestead> iface = new ethers.utils.Interface([ "function foo()" ])
homestead> iface.getFunction("foo")
FunctionFragment {
  type: 'function',
  name: 'foo',
  constant: false,
  inputs: [],
  outputs: [],
  payable: false,
  stateMutability: 'nonpayable',
  gas: null,
  _isFragment: true
}
homestead> id("foo()")
'0xc2985578b8f3b75f7dc66a767be2a4ef7d7c2224896a1c86e92ccf30bae678b7'
homestead> iface.getFunction("0xc29…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ricmoo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1404 on March 27, 2021 01:33.