I am trying to compare the token contract address with the address(0). This was working fine in older version of truffle and solidity compiler (0.4.24). When I upgraded truffle and started using the latest truffle and compiler version (0.5.0) I am unable to compare the token contract address and address(0).

Could you please assist me to resolve this ?

enter image description here


As of Solidity 0.5.X, contract types do not include the address members. Per the documentation:

Contract types do not include address members anymore in order to separate the namespaces. Therefore, it is now necessary to explicitly convert values of contract type to addresses before using an address member. Example: if c is a contract, change c.transfer(...) to address(c).transfer(...), and c.balance to address(c).balance.

So you will need to update that particular line of code to be require(address(token) != address(0));, as shown in this mvce:

pragma solidity ^0.5.2;

contract ERC20Interface {
    function totalSupply() public view returns (uint);
    function balanceOf(address tokenOwner) public view returns (uint balance);
    function allowance(address tokenOwner, address spender) public view returns (uint remaining);
    function transfer(address to, uint tokens) public returns (bool success);
    function approve(address spender, uint tokens) public returns (bool success);    
    function transferFrom(address from, address to, uint tokens) public returns (bool success);    

    event Transfer(address indexed from, address indexed to, uint tokens);    
    event Approval(address indexed tokenOwner, address indexed spender, uint tokens);    

contract init {        
    ERC20Interface token;

    function test() public view {    
        require(address(token) != address(0));

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.