I am trying to copy stored values using the following internal value.

pragma solidity ^0.4.21;

contract test{

    event LogTest(
        bytes32[5] a
    ); 

    bytes32[5]  attr;

    function attributes() internal {
        attr[0] = "0x0"; attr[1] = "0x1"; attr[2] = "0x2"; attr[3] = "0x3"; attr[4] = "0x4";
    }

    function getA() public{
        attributes();
        LogTest(attr);
    }

}

However, the log does not return the correct values. Instead, it returns the following:

"a": [
                "0x3078300000000000000000000000000000000000000000000000000000000000",
                "0x3078310000000000000000000000000000000000000000000000000000000000",
                "0x3078320000000000000000000000000000000000000000000000000000000000",
                "0x3078330000000000000000000000000000000000000000000000000000000000",
                "0x3078340000000000000000000000000000000000000000000000000000000000"
            ]

Why are the values incorrect?

That looks right to me. You're storing strings in the array, so they're stored in their ASCII representation. You can double check that the right string was stored by converting the output back to strings, here using web3.js in my browser:

> web3.toAscii('0x3078300000000000000000000000000000000000000000000000000000000000')
"0x0"
> web3.toAscii('0x3078310000000000000000000000000000000000000000000000000000000000')
"0x1"

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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