When sending eth_call to get erc20 token WETH name and symbol I get hex response padded with bunch of zeros and a mysterious digit '2'.

for symbol I get response:


for name I get response:


When I convert responses to utf8 string I get:

�������������������������������Wrapped Ether

The routine to decode hex strings from ethereum.js unpads only up to first '2' that it finds. Although padding with zeros continues until actual chars begin.

Why such a 'weird' encoding of response and how to properly decode it?

1 Answer 1


They are encoded using solidity abi

  • The first 32 bytes is the offset where string is present within the response: 0000000000000000000000000000000000000000000000000000000000000020. So the string starts at position 20h = 32.

  • At specified offset the first 32 bytes indicates the length of the string: 0000000000000000000000000000000000000000000000000000000000000004. So string has length 4h = 4.

  • Following the length the next 4 bytes are the string itself: 57455448. From a utf-8 you have "WETH".

  • Thanks @Ismael. ethereum rpc spec on encoding is very loose: github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding only two options: quantities and unformatted data. How do I know what encoding was used for data? I know that response is supposed to be string from method ABI definition. But how am I supposed to figure out what encoding was used for that string?
    – Sharas
    Commented May 23, 2020 at 13:01
  • @Sharas The exceptions to that rule are when you interact with a contract, for example data field in eth_sendTransaction, eth_call; the returned data from eth_call; etc.
    – Ismael
    Commented May 23, 2020 at 15:40

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.