0

So I've updated solidity to version 0.5.0 and I'm trying to re-write my code. One thing that worked before was comparing contract (represented by its address) to addresses. So now I'm getting the following error:

TypeError: Operator == not compatible with types contract User and address payable

Then I've tried to just add the address field, but the compiler won't allow it. For instance, the following won't compile because it expects ; instead of . :

address a = User.address;

So how do I solve this problem of getting the address field from a contract so the compiler lets me compare those two? Here is the part of the code that won't compile because of that require statement:

mapping(address=>User) public users;

function register(string memory _nome) public {
    require(users[msg.sender]==0x0000000000000000000000000000000000000000);
    users[msg.sender] = new User(_nome,msg.sender);
}
1

I assume by "that if statement" you mean the require?

Just use an explicit cast to address:

require(address(users[msg.sender]) == 0x0000000000000000000000000000000000000000);
  • yes, I'll correct it – Tadeu Moreira Jan 9 at 7:42
  • that works, thanks. I've assumed casting was not yet implemented in solidity so I didn't bother trying. – Tadeu Moreira Jan 9 at 8:00

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.