to be
a problem slover

solidity default value for interface instance

pragma solidity 0.6.6;

interface IERC20{
    function name() external view returns (string memory);
}

contract DefaultValue{
    IERC20 public a_erc20; // default value 0x0000000000000000000000000000000000000000
    mapping(address => IERC20) public erc20s; // default value for a non-exist key address(nonexistKey) = address(0)

    function addErc20(address addr) public{
        erc20s[addr] = IERC20(addr);
    }

    function isExist(address addr) public view returns (bool){
        if (address(erc20s[addr]) == address(0)){
            return false;
        }
        return true;
    }
}
赞(4) 打赏
欢迎转载,注明出处:刘世明的博客 » solidity default value for interface instance

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下作者

支付宝扫一扫打赏

微信扫一扫打赏