0

I have the following (array of bytes32 types):

bytes32[] public allTokenSymbols = ["0x4554480000000000000000000000000000000000000000000000000000000000", "0x4c54430000000000000000000000000000000000000000000000000000000000", "0x5852500000000000000000000000000000000000000000000000000000000000"];

This gives the following error:

string memory[3] memory is not implicitly convertible to expected type bytes32[] storage ref

How should this be done? I want the array to contain the bytes32 of "ETH", "LTC" and "XRP".

1

The error makes sense... on the right-hand side of the assignment, you have an array of strings, each of which is too large to fit into a bytes32 anyway. (Each string is 66 characters long.)

Given your intention, which is store the representation of "ETH", "LTC", and "XRP," I believe this code does what you want:

bytes32[] public allTokenSymbols = [
        bytes32(0x4554480000000000000000000000000000000000000000000000000000000000),
        bytes32(0x4c54430000000000000000000000000000000000000000000000000000000000),
        bytes32(0x5852500000000000000000000000000000000000000000000000000000000000)];

Note that I'm using hexadecimal numbers instead of strings, and I'm explicitly converting each to a bytes32.

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.