JSON RPC – How to Decode Response Results

json-rpc

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?

Best Answer

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.

Related Topic