[Ethereum] how to deal with bytes32 to string in javascript

solidity

I am going to set a email address from users and going to save it to ethereum network.

I kept email as bytes32 in smart contract and when I am sending the value to javascript i am getting always a same bytes . when i use to convert to ascii I am getting '@' everytime. what can be the reason?

Best Answer

If you're on web3 v0.x, then:

  • Use web3.fromAscii before you send the string to the smart contract
  • Use web3.toAscii after you read the string from the smart contract

If you're on web3 v1.x, then:

Related Topic