从 ERC20 智能合约中移除不受信任的代币

Remove unstrusted token from ERC20 Smart Contract

我有一个问题,我尝试 google 没有多少存在。

我们以这个token为例: 1inch Token

因此您可以看到它具有人们发送到该地址的不同令牌。

如果我是所有者,我如何实现将所有这些代币提取到我的钱包的功能?

你的合约可以定义ERC20接口函数transfer(),然后在外部代币合约上执行这个函数

pragma solidity ^0.8;

interface IERC20 {
    function transfer(address _to, uint256 _amount) external returns (bool);
}

contract MyContract {
    modifier onlyOwner {
        require(msg.sender == address(0x123), 'Not authorized');
        _;
    }

    function withdrawERC20Token(address _tokenContractAddress, uint256 _amount) external onlyOwner {
        IERC20 token = IERC20(_tokenContractAddress);
        
        // transfer the `_amount` of tokens (mind the decimals) from this contract address
        // to the `msg.sender` - the caller of the `withdrawERC20Token()` function
        bool success = token.transfer(msg.sender, _amount);
        require(success, 'Could not withdraw');
    }
}