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;}
Ismael
  • 30,570
  • 21
  • 53
  • 96
Eric Falkenstein
  • 701
  • 1
  • 5
  • 18

1 Answers1

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.

Samparsky
  • 59
  • 4
  • Cool. Thanks. So the new 'CustList' contract implicitly has 'address payable, and thus address(CustList) casts it back into just 'address'? – Eric Falkenstein Aug 04 '19 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 https://ethereum.stackexchange.com/questions/64108/whats-the-difference-between-address-and-address-payable – Samparsky Aug 05 '19 at 06:30