I want to understand how function call should be converted to the hex.

I have to sign transaction on the client side. Web3 provides this function:

web3.eth.accounts.signTransaction(tx, privateKey)

Tx is transaction which has data field. Data field represents function call with arguments in hex format.

The question is how to convert function call into this hex representation? What kind of format I should follow?

At this moment I'm looking at this https://github.com/ethereumjs/ethereumjs-abi

1 Answer 1


https://solidity.readthedocs.io/en/develop/abi-spec.html gives the gory details.


  • The beginning of the data is the "function selector," the first four bytes of the keccak256 hash of the function signature, e.g., keccak256("transfer(address,amount)".
  • The rest is the ABI-encoded arguments. For simple types, it's pretty much just the raw value, and for things like arrays, it gets a bit more complicated. (Essentially a pointer to the data, then a size telling you how much data to read, and then the data itself.)
  • Thank you, Smarx! We already had a chat on this and I even worked on parser for this, but few examples in the web move my thoughts I missed something. Research on high level libraries brought me to this way to implement it github.com/trufflesuite/ganache-cli/issues/344
    – Gleichmut
    Commented Feb 1, 2018 at 2:05

Your Answer

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

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