5

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?

1

1 Answer 1

6

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.

2
  • 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? Aug 10, 2016 at 15:38
  • 1
    Yup, like you said the "Hashes can't be worked backwards". Aug 10, 2016 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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