Created
October 19, 2020 14:12
-
-
Save DanielVF/186db6809cd9a1a9bfcf1dfbdbf192d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.6.0; | |
// Calling SafeERC20.safeTransfer and SafeERC20.safeTransferFrom can fail | |
// with a "SafeERC20: ERC20 operation did not succeed" message when the | |
// underlying cause is running out of gas inside the transfer | |
// This is because the low level call to the ERC20 is indeed reverted by | |
// running out of gas, but that revert is caught, and a different revert | |
// is raised by the safeTransfer method. | |
// Sample code for remix below. | |
pragma solidity ^0.6.0; | |
contract Caller{ | |
function doSafeTransfer(address other) public returns (bytes memory rd) { | |
bytes memory data = abi.encodeWithSignature("transfer()"); | |
(bool success, bytes memory returndata) = address(other).call(data); | |
require(success, "SafeERC20: ERC20 operation did not succeed"); | |
return returndata; | |
} | |
} | |
contract Happy{ | |
function transfer() public { | |
} | |
} | |
contract Sad { | |
uint256 foo; | |
function transfer() public { | |
for(uint256 i = 0; i < 400; i++){ | |
foo = i; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment