Using the web3 JS library, there's hooks to grab a transaction by its hash (web3.eth.getTransaction()), which includes an input property that is the data payload of the transaction. The first four bytes of which are the function selector which is a fragment of a hash.

The question is, how to determine what function was called? Hashes can't be worked backwards, so we need to derive the list of function signatures for that contract (a.k.a. the contract ABI).

Web3 has the web3.eth.getCode(txnHash) method that can get the hex code for a contract, but can that be parsed into an ABI of the contract?

Or is it impossible to derive the ABI without having the source code of the contract?

up vote 4 down vote accepted

Here's a database of mappings from the functions to the function signatures - https://www.4byte.directory/. Note that the server has been returning 'Server Error (500)' intermittently.

Some further information about this service: Ethereum Function Signature Database - database of 4-Btye function signatures to their human readable counterparts.

  • 1
    So, the only way to derive the function if the source code is not known is to just maintain a rainbow table of possible signatures? – MidnightLightning Aug 10 '16 at 15:38
  • 1
    Yup, like you said the "Hashes can't be worked backwards". – The Officious BokkyPooBah Aug 10 '16 at 15:47

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.