pragma solidity 0.5.10;

contract ERC20 {
    function totalSupply() public view returns (uint supply);
    function balanceOf(address _owner) public view returns (uint balance);
    function transfer(address _to, uint _value) public returns (bool success);
    function transferFrom(address _from, address _to, uint _value) public returns (bool success);
    function approve(address _spender, uint _value) public returns (bool success);
    function allowance(address _owner, address _spender) public view returns (uint remaining);
    function decimals() public view returns(uint digits);
    event Approval(address indexed _owner, address indexed _spender, uint _value);

contract TestContract{

    address payable public owner;


    constructor() public {
        owner = msg.sender;

    function depositToken(address _addr) external
        ERC20 tokenContract = ERC20(0x722dd3F80BAC40c951b51BdD28Dd19d435762180);
        uint tokenAmount = tokenContract.allowance(msg.sender, this);
        require(tokenContract.transferFrom(msg.sender, this, tokenAmount));

When i Compile this contract return

TypeError: Invalid type for argument in function call. Invalid implicit conversion from contract TestContract to address requested. require(tokenContract.allowance(msg.sender,this)>0); ^--^

1 Answer 1



function allowance(address _owner, address _spender)

You should change this:

tokenContract.allowance(msg.sender, this)

To this:

tokenContract.allowance(msg.sender, address(this))

The type of the function's 2nd input parameter is address.

Yet, you are passing a value of type TestContract.

In terms of offchain interface (e.g. web3.js), these two types are identical.

But in terms of onchain interface (the Solidity compiler), they are different.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.