1

I am trying to create a contract to store ether and two ERC-20 tokens. People will transfer ether and the other two ERC-20 tokens to this contract and when the time comes, the owner of this contract will transfer these ether and ERC-20 tokens back to them. I don't know how to make this contract.

Currently, I can make an ERC-20 token contract and it can only store the ether and this ERC-20 token itself like below.

Suppose this contract can store 3 kinds of tokens. When people transfer these tokens to the contract, how the contract itself knows which token was sent?

contract WalkDogToken is ERC20, ERC20Burnable, Ownable {
    constructor() ERC20("WalkDogToken", "WDT") {}

    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }

    function decimals() public view virtual override returns (uint8) {
        return 8;
    }

    receive() external payable {}
}

1 Answer 1

1

Suppose this contract can store 3 kinds of tokens. When people transfer these tokens to the contract, how the contract itself knows which token was sent?

Tokens are transferred using IERC20(address).transferFrom(). Your contract differs between different ERC-20 tokens by their smart contract address.

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.