9

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?

  • use toasci funtion – Etherkimist Jul 14 '17 at 13:53
  • I've tried web3.toAscii("0x00000000000000000000000000000000000000000000000000000000000f4240") and this is what I get: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0fB@" – Jupiter Jul 14 '17 at 13:56
  • 1
    it depends on the return of your function toasci will work only if it return a string – Etherkimist Jul 14 '17 at 13:57
  • Yes! that is the answer. Trivial actually. – Jupiter Jul 14 '17 at 14:00
2

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.

| improve this answer | |
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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