On a Smart Contract called "mem" there is a function called "get()" that returns a bytes32 that is supposed to be a string. How can I decode the string? The result is an hex value. I have tried toString() on geth console, but I am probably doing something wrong...

mem.get(); "0x4d61726b65745061792e696f206973206465706c6f79696e6720536d61727420" mem.get().toString(); "0x4d61726b65745061792e696f206973206465706c6f79696e6720536d61727420" mem.get().toString('hex'); "0x4d61726b65745061792e696f206973206465706c6f79696e6720536d61727420"


1 Answer 1


You can use web3.toAscii(hexString) as documented in Web3 JavaScript Ðapp API:

> web3.toAscii("0x4d61726b65745061792e696f206973206465706c6f79696e6720536d61727420")
"MarketPay.io is deploying Smart "

You can also use web3.toUtf8(hexString):

> web3.toUtf8("0x4d61726b65745061792e696f206973206465706c6f79696e6720536d61727420")
"MarketPay.io is deploying Smart "
  • Thx. It works like a charm! Commented Sep 27, 2016 at 12:19
  • For version 1.x, it's under web3.utils. So you need to do web3.utils.toAscii(hexString)
    – MeetM
    Commented May 10, 2020 at 16:03

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