2

I am using arab letters in bytes32 data stored in a smart contract, when reading the data and converting to utf-8 with web3.toUtf8() i get errors like unknown utf character or Invalid continuation byte and Invalid byte index

If this is the case, how do I fix it?

EDIT

This is the code i am using right now ( i fixed it ) :

contractInstance.insertPerson(
        web3.fromUtf8(web3.fromDecimal(i+2*i)),
        jsonObj["email"]?jsonObj["email"]:"",
        web3.fromUtf8(jsonObj["FIRST_NAME"]),
        web3.fromUtf8(jsonObj["LAST_NAME"]), 
...

this is the code i was using (the one that does not show correct letters):

contractInstance.insertPerson(
        web3.fromUtf8(web3.fromDecimal(i+2*i)),
        jsonObj["email"]?jsonObj["email"]:"",
        jsonObj["FIRST_NAME"],
        jsonObj["LAST_NAME"], 
...
  • How did you encode the data when it was turned into bytes32? – Edmund Edgar Feb 22 '18 at 8:57
  • 1
    encode ? didn't do anything manually, i had an arabic letter string and i pushed it like any other latin letter string to my mapping. when i read it and convert to utf-8 using web3 i get those errors. am i missing something ? – Kaki Master Of Time Feb 22 '18 at 9:41
  • 1
    Try posting the code for whatever you mean by "pushed it like any other latin letter string to my mapping". – Edmund Edgar Feb 22 '18 at 13:05

Your Answer

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

Browse other questions tagged or ask your own question.