Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the function name and parameter from input data

Tags:

web3js

Transaction hash give input data like this "0xa9059cbb00000000000000000000000024c38db6c4a85b3e6b58631de2334105f6209da300000000000000000000000000000000000000000000000000000dca4f1516a8". if i call this function let encodedFunctionSignature = web3.eth.abi.encodeFunctionSignature('transfer(address,uint256)');

it give me this "0xa9059cbb".etherscan call this methodId

My question is how i get the transfer(address,uint256) back from this "0xa9059cbb"

enter image description here

like image 344
Fahad Avatar asked Sep 12 '25 03:09

Fahad


1 Answers

The function selector is the first four bytes of the keccak256 hash of the canonicalized function signature. In this case, web3.sha3('transfer(address,uint256)').substring(0, 10) === "0xa9059cbb".

Reversing this process is not generally possible unless the contract's code or ABI is provided. That said, as long as someone else has used a given function selector before and provided its original name, you can use that information instead.

One list of commonly used function selectors is here: https://github.com/ethereum-lists/4bytes, and in fact transfer(addresss,uint256) is the first example given.

like image 84
user94559 Avatar answered Sep 15 '25 20:09

user94559