0

I'm learning smart contract, and I have a problem compiling one it gives me this error message:

Error: Type literal_string "0x5c15741c7abb1b0e8fb0bd41b5ed8c17219926a1" is not implicitly convertible to expected type address. address multisig = "0x5c15741c7abb1b0e8fb0bd41b5ed8c17219926a1";

I have tried to me it looks like that, we shouldn't hard code the contract address?

here is the code of the line causing trouble :

address multisig = "0x5c15741c7abb1b0e8fb0bd41b5ed8c17219926a1";

thank you for your help!

3 Answers 3

1

Explicit declaration as an address

You'll want to explicitly define the address instead of trying to force cast a string as an address.

To do this simply use the address() operator to make an address type value from the hexadecimal representation of the address.

Example:

address multisig = address(0x5c15741c7abb1b0e8fb0bd41b5ed8c17219926a1);
2
  • If this answered your question, please mark it as the correct answer. If not let me know so I can further assist.
    – supakaity
    Commented Apr 2, 2018 at 3:04
  • this still gives an error, "This looks like an address but has an invalid checksum"
    – Jim
    Commented Oct 19, 2021 at 15:26
0

The proper way to initialize an address is to not use quotes

address a = 0x5c15741c7abb1b0e8fb0bd41b5ed8c17219926a1;

But this generates a warning, solidity want addresses with the mixed case checksum

address b = 0x5c15741C7ABb1b0E8FB0BD41b5ed8c17219926A1;
0

It is because you are not using mixed case checksum.

Go to this link below and use toChecksumAddress function with your lowercased address here. And use the result.

https://web3-tools.netlify.app/

Example) enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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