current position:Home>Smart contract extraction usdt

Smart contract extraction usdt

2022-02-03 23:41:47 Q & A of Denglian community

function withdrawERC20(IERC20 token) external payable onlyOwner {token.transfer(msg.sender, token.balanceOf(address(this)));} Can't extract USDT, Other tokens are OK




Take the answer 1:

because USDT The implementation of is not standard ERC20, You need to use the following methods :

    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');    }



copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032341456925.html

Random recommended