Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Warning: This looks like an address but has an invalid checksum #2092

Closed
ruchevits opened this issue Mar 27, 2017 · 9 comments
Closed

Comments

@ruchevits
Copy link
Member

contract Users {
  struct User {
    address addr;
    string name;
  }
  mapping (bytes32 => User) users;
  function create(bytes32 id, string name) {
    users[id] = User(msg.sender, name);
  }
}

I'm getting the following error trying to compile it:

Warning: This looks like an address but has an invalid checksum. If this is not used as an address, please prepend '00'.

It looks like an address because it is an address. And it is used as an address.

@federicobond
Copy link
Contributor

I cannot reproduce this with latest master or browser-solidity. Which version of solidity are you using?

@ruchevits
Copy link
Member Author

solc 0.4.10

@chriseth
Copy link
Contributor

@ruchevits if you use literal addresses, you have to use the uppercase / lowercase encoding. This error might also come from the --libraries option to solc and not necessarily from the source code itself.

@ruchevits
Copy link
Member Author

@chriseth @federicobond Sorry, my mistake, the error actually happens with:

contract Users {
  struct User {
    address addr;
    string name;
  }
  mapping (bytes32 => User) users;
  function create(bytes32 id, string name) {
    address myAddr = 0x0E5CB767CCE09A7F3CA594DF118AA519BE5E2B5A;
    users[id] = User(myAddr, name);
  }
}

(when the address is hardcoded)

If I wrap the address in double quotes, the error is: Error: Type literal_string "0x0E5CB767CCE09A7F3CA594DF118AA519BE5E2B5A" is not implicitly convertible to expected type address.

address myAddr = "0x0E5CB767CCE09A7F3CA594DF118AA519BE5E2B5A";

If I try to explicitly cast literal string to address, the error is: Error: Explicit type conversion not allowed.

address myAddr = address("0x0E5CB767CCE09A7F3CA594DF118AA519BE5E2B5A");

@chriseth
Copy link
Contributor

The warning asks you to add a checksum to your address: ethereum/EIPs#55

@ruchevits
Copy link
Member Author

@chriseth Thank you!

@ronnie173
Copy link

So how exactly did you fix this? Can you please post an example? Because I tried everything

@axic
Copy link
Member

axic commented May 24, 2018

Just follow what the compiler suggests - it also suggests you the correctly encoded address. Note: the distinction between lower and uppercase letters matters.

@CHAOWEICHIU
Copy link

I had the same issue, but you can make it work by using ethereumjs-util
const { toChecksumAddress } = require('ethereumjs-util')
The address I had was
0x8a9a728f64e58db7e790f099bddb3416ccc2eb77
by using toChecksumAddress() I get
0x8a9a728f64E58Db7e790F099BdDB3416ccC2Eb77

For how they did it, please refer to
https://github.com/ethereumjs/ethereumjs-util/blob/master/index.js#L476

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants