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;}
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.

  • Cool. Thanks. So the new 'CustList' contract implicitly has 'address payable, and thus address(CustList) casts it back into just 'address'? – Eric Falkenstein Aug 4 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 at 6:30

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.