1

I am stuck trying to compile a contract using Remix. I am initializing an array as follows:

address[] public wmaticToUsdcPath =[0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270, 0x2791bca1f2de4661ed88a30c99a7a9449aa84174];

But Remix won't compile and is complaining that 0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270 is not an error. The exact error is, this looks like an array but has an invalid checksum. It is suggesting I prepend '00' to it and directing me to https://docs.soliditylang.org/en/develop/types.html#address-literals but I can't seem to understand what to do. Prepending '00' will change the address. I am working on the MATIC/Polygon network.

The funny thing is if I declare an address variable and assign the WMATIC address to it, it is accepted by the compiler.

Does anyone know why the MATIC address is not accepted in an array.

2

Ethereum addresses have checksum and solidity enforces that to avoid "spelling" errors.

If they were assigning to an uint prepending 0 will make it skip the checksum

uint a = 0x002791bca1f2de4661ed88a30c99a7a9449aa84174;

It'll not work when assigning to an address because the checksum is required. In that case the solution is to add it

address b = 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174;

An alternative is to define as bytes20

bytes20 c = hex"2791bca1f2de4661ed88a30c99a7a9449aa84174";

Or use solidity 0.4, the latest version where missing checksum wasn't an error.

1
  • Thanks for that. I was just worried that prepending '00' will change the address and make the code not work correctly but your answer re-assure me and once deployed the '00' was removed automatically in the deployed code.
    – falopsy
    Jul 9 at 18:58

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.