0

The following compiles in 0.4.26, but not 0.5.0. The error is "Type contract CustList is not implicitly convertible to expected type address." I figure it's something with address payable, but I have tried ever casting permutation and can't get this to work in 0.5.0.

pragma solidity ^0.5.0;

contract CustTest {
    mapping(address  => address) public customers;  
    function createProfile()
        public
    {
    customers[msg.sender] = new CustList();
    }
}

contract CustList { uint x;}

1 Answer 1

0

Solidity pre 0.5 does an implicit conversion from Contract to address but from > 0.5.x focus has been more on explicit conversions

To fix you can follow either of these approaches:

pragma solidity ^0.5.0;

contract CustTest { 
  mapping(address => CustList ) public customers;
  function createProfile() public { 
    customers[msg.sender] = new CustList(); 
  } 
}

contract CustList { 
  uint x;
}

or another approach is to cast new CustList() to an address itself

pragma solidity ^0.5.0;

contract CustTest { 
  mapping(address => address) public customers;
  function createProfile() public { 
    customers[msg.sender] = address(new CustList()); 
  } 
}

contract CustList { 
  uint x;
}

PS: For every invocation of createProfile() you are deploying a new CustList contract on-chain via an internal transaction.

2
  • Cool. Thanks. So the new 'CustList' contract implicitly has 'address payable, and thus address(CustList) casts it back into just 'address'? Aug 4, 2019 at 19:46
  • The address and address payable types both store a 160-bit Ethereum address. The concept of payable and non-payable addresses only exists in the Solidity type system at compile-time. The difference between payable and non-payable addresses is gone in the compiled contract code. You can checkout more here ethereum.stackexchange.com/questions/64108/…
    – Samparsky
    Aug 5, 2019 at 6:30

Your Answer

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

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