Solidity Type Conversion – Handling Explicit Type Conversion in IERC20 Contracts

contract-developmentsolidity

How can I use IERC20("0xf7a35Eef60dC35fa2D3188Dfb22e635E4308fc8b"); it is throwing the error for me. I am try to use the another contract inside my contract.

contract LPTokenWrapper {
    using SafeMath for uint256;
    using SafeERC20 for IERC20;

    IERC20 public y = IERC20("0xf7a35Eef60dC35fa2D3188Dfb22e635E4308fc8b");

    uint256 private _totalSupply;
    mapping(address => uint256) private _balances;

    function totalSupply() public view returns (uint256) {
        return _totalSupply;
    }

    function balanceOf(address account) public view returns (uint256) {
        return _balances[account];
    }
}

Best Answer

The type of "0xf7a35Eef60dC35fa2D3188Dfb22e635E4308fc8b" is string, not address.

Use address(0xf7a35Eef60dC35fa2D3188Dfb22e635E4308fc8b) instead.

In Javascript, BTW, you do need to use strings in order to denote addresses, because the integer value of an address (up to 2 ^ 160 - 1) might be larger than Number.MAX_SAFE_INTEGER (2 ^ 53 - 1).

Related Topic