[Ethereum] Whether usdt can be sent to a contract

erc-20usdt

Whether erc20 usdt can be sent to a smart contract so the owner will be a contract address, I mean balanceOf[] will use contract address or the contract owner address? If I send the erc20 again from the contract, I can just call the usdt contract function transfer within my contract? Thanks

Best Answer

Any address can be an owner of ERC20 tokens, so a contract is also fine.

The possible problem with contracts owning tokens is that the contract has to have functionality to transfer the tokens onwards (call the token contract). If the contract doesn't have such functionality the tokens are essentially lost/burned as they can never be transferred anywhere.

What you need in your contract is basically:

  1. Write an interface which says what functionality the other contract has

  2. Create a reference to the token contract with the interface and the token contract's address

  3. Call the token contract's functionality within your contract

Something like this:

pragma solidity ^0.7.0;

interface TokenContract {
    function a() external;
    function b() external;
}

contract RefContract
{
    function doStuff(address contrAddr) public {
        TokenContract contr = TokenContract(contrAddr);
        contr.a();
    }
}
Related Topic