# How do I get an address with a correct checksum, from an address with an incorrect checksum, using Solidity?

Example of an address with the wrong checksum:

0xa54D3c09E34aC96807c1CC397404bF2B98DC4eFb

Example of an address with the right checksum:

0xa54d3c09E34aC96807c1CC397404bF2B98DC4eFb

-Difference is the first letter "D".

Which function call should I make in Solidity to convert the wrong checksum address to a right checksum address ?

• I think I don't understand your use case, Solidity doesn't have a function with that functionality, perhaps you want to use web3.utils.toChecksumAddress from web3.js. – Ismael Sep 8 at 15:08
• I want to do it with Solidity and not Javascript. The only way I know is to convert to a string and then correct the checksum of a string and then back to address... which costs a lot of eth to process. – Damir Olejar Sep 8 at 15:20
• As stated by Lauri Peltonen EVM/Solidity deal with addresses as raw bytes and they do not include the checksum. It is responsibility of framework/libraries to calculate the checksum at user presentation. – Ismael Sep 8 at 18:32

The simple answer is that in solidity:

address(0xa54D3c09E34aC96807c1CC397404bF2B98DC4eFb);


It is true that the compiler warns you of incorrect checksum when it sees one, but that warning is probably there just to tell you that you might have gotten the wrong address altogether (because typically, constant addresses are copy-pasted from one place to another, and copy-pasting would not "accidentally" change some upper-case letter to lower-case or vice versa).

The Solidity compiler tells you exactly how you can fix it (manually):

The solution then becomes:

Hexadecimal literals that pass the address checksum test, for example 0xdCad3a6d3569DF655070DEd06cb7A1b2Ccd1D3AF are of address payable type. Hexadecimal literals that are between 39 and 41 digits long and do not pass the checksum test produce an error. You can prepend (for integer types) or append (for bytesNN types) zeros to remove the error.

But again, these two constants are identical, and they will yield the exact same runtime-behavior.

• I will accept this as an answer because it is pointing to the right link which contains the solution I have written here. I just didn't want to accept my own answer. For anyone interested, follow the link (or see my answer). You can continue using the address and convert it to a String with a correct checksum if necessary. – Damir Olejar Oct 1 at 11:41

As mentioned in comments Solidity doesn't have such functionality. Solidity (and also EVM) doesn't understand anything about address checksums, it's only a construct added on top of the toolkits.

If you really really want to you can calculate it yourself in Solidity. Here's the original EIP: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md with some example code. But I fail to see why you'd want to do that.

• In that case it has to be coded, and I am sure there is a simple solution for it. Sorry, but can't accept the answer... – Damir Olejar Sep 8 at 17:58

Other colleagues did underline very well the point: in Solidity does not exist something called “address with correct checksum”. There exist addresses. Full stop.

The request for a proper checksum comes from the user interface of the IDE, like remix or similar, just to ask you to double check your address. But just for this.

You can obtain your correct checksum address treating it as a string, then applying the EIP 55 rules, then converting it back to address.

But this do not make sense in a smart contract: never. And it does not make sense to record that on blockchain. It is something like using EVM and paying ethers at running time to indent properly the source code. It, if required, is to be done offline, by means of some JavaScript or C.

In other word: the CRC is a “cosmetic” element useful for the interface to the IDE, like comments in green and between /* and */.

You are asking something like “I want to format comments in solidity”.

This does not make sense. At run time do not exist anymore both indenting and comments and CRC for addresses.

I hope this can help.

• If incorrect checksum didn't exist, there shouldn't be a compiler error stating that the address contains the incorrect checksum. It should exist as a warning instead. On the other hand, the older versions of solidity do accept the incorrect checksum, so perhaps your answer is valid, however, outdated. – Damir Olejar Oct 1 at 10:52
• It is a safe check made in order to give you the habit to copy and paste addresses in the code, not to write them from the scratch. Nothing more. Try this way: may be (may be!) that in a future the CRC of addresses be possibly used for something not clear at the moment. At the moment it is not. In no way. Sorry for it, this is the cruel truth. – Rick Park Oct 1 at 11:23