11

How do I convert the result returned from a JSON-RPC eth_call from my geth client?

This is the call: curl -X POST --data '{"jsonrpc":"2.0","method":"eth_call","params":[{"to":"0x86312d97c0dd3fd9202fdbdec434f36ee1b30720", "data":"0x18160ddd"}, "latest"],"id":1}' 127.0.0.1:8545

This is the return: {"jsonrpc":"2.0","id":1,"result":"0x00000000000000000000000000000000000000000000000000000000000f4240"}

How to convert: 0x00000000000000000000000000000000000000000000000000000000000f4240 back to human readable characters?

Jupiter
  • 113
  • 1
  • 5

1 Answers1

4

Its Hex encoded string you can convert it in to Decimal.

For web3: web3.toDecimal('0x00000000000000000000000000000000000000000000000000000000000f4240')

For javascript: parseInt('0x00000000000000000000000000000000000000000000000000000000000f4240', 16);

For PHP: hexdec('0x00000000000000000000000000000000000000000000000000000000000f4240');

// result: 1000000

For other programming languages you can search for hextodecimal function for that particular programming language.

  • Sometimes one needs to use bignumber.js - I've received the following result 2e+21 which wouldn't work with the functions above, would only work with BigNumber(2e+21).toString(10) – Asaf Apr 19 '18 at 12:44