5 智能合约提取USDT

function withdrawERC20(IERC20 token) external payable onlyOwner { token.transfer(msg.sender, token.balanceOf(address(this))); } 提取不了USDT,其他代币都可以

请先 登录 后评论

最佳答案 2021-01-22 14:42

由于 USDT 的实现不是标准的 ERC20, 你需要使用以下方法:

    function safeTransfer(address token, address to, uint value) internal {
        // bytes4(keccak256(bytes('transfer(address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
    }

    function safeTransferFrom(address token, address from, address to, uint value) internal {
        // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
    }
请先 登录 后评论

其它 0 个回答

  • 1 关注
  • 2 收藏,233 浏览
  • v 提出于 2021-01-21 22:29

相似问题