I am trying to utilize the SafeERC20 library from zeppelin-solidity. However the instructions for using the library are not sufficient for a novice like me . Please help me in understanding . /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure. + * To use this library you can add a using SafeERC20 for ERC20; statement to your contract, + * which allows you to call the safe operations as token.safeTransfer(...), etc.*/ when I utilize it in my Contract token program , How shall I use it ? code is available here https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/ERC20/SafeERC20.sol enter image description here

below is the code . https://gist.github.com/bhattnaval/2eea6398fab22e64140bef930243bacd

  • Hey Naval, what are you trying to do? Do you have a token you're trying to transfer or are you looking to create a token?
    – thefett
    Oct 27, 2017 at 2:56
  • I am trying to transfer the token from one owner to another . However I am not able to use the safeERC20's safetransfer . Sorry in the above code I had the statement wrong . it should be token.safeTransfer(Mytoken,msg.sender,_to,_value); but even that is giving an error . DeclarationError: Undeclared identifier. token.safeTransfer(Mytoken,msg.sender,_to,_value); ^---^
    – Naval
    Oct 27, 2017 at 3:05
  • in case you would like to check the complete code . gist.github.com/bhattnaval/2eea6398fab22e64140bef930243bacd
    – Naval
    Oct 27, 2017 at 3:31
  • yea I think you have quite a few issues going on here. But for the safeTransfer, you can try safeERC20.safeTransfer(); Are you trying to create your own token or have a utility that handles multiple tokens?
    – thefett
    Oct 27, 2017 at 12:00
  • Yes , I am trying to create my own token. I checked the helper zeppelin-solidity/test/helpers/SafeERC20Helper.sol. However, I am not able to grasp the idea . specifically , function SafeERC20Helper() { failing = new ERC20FailingMock(); succeeding = new ERC20SucceedingMock(); }
    – Naval
    Oct 27, 2017 at 17:19

1 Answer 1


The library SafeERC20 is to safely interact with a third party token. It is not to be used inside your own token contract.

OpenZeppelin contracts already have require to check for preconditions so they will return true or fail early.

Also I'd suggest to remove the protection for short address attack onlyPayloadSize. They were removed from the OpenZeppelin contracts several months ago #261 Remove short address attack checks from tokens.

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.