erc20 token standard functions are only important for creating new tokens, or for all, suppose a smart contract is only intended to transfer token, should it contain those standard erc20 functions or that is useless there ?


ERC-20 standard defines API to be implemented in token smart contracts. Such smart contracts keep track of token balances for particular addresses and update balances when tokens are transferred. Usually, there is single token smart contract for every sort of tokens. For example, WETH tokens balances are tracked by this smart contract.

If your smart contract does not manage its own sort of tokens, but just uses (i.e. receives, holds, sends, checks balances etc) tokens managed by other smart contracts, then you don't need to implement any of ERC-20 functions in it. Just import IERC20.sol, cast address of token smart contract to IERC20, and then call its methods.

| improve this answer | |
  • Answer is nice, but please elaborate little more for if I am writing smart contract to deposit token of user or visitor before deal, and if deal finalize will transfer to some other user, or if deal fails will return the token back to the last owner, in this case should I include standard erc20 functions or not ? – FLAME'S KING Jun 25 '19 at 3:26
  • Seems that your contract just needs to receive tokens from one party, hold them for some time, and then send the tokens to the same of some other party. In other words, your smart contracts just receives, holds, and sends tokens. In such case, as I said in my answer, your contract does not need to implement any of ERC20 methods. – Mikhail Vladimirov Jun 25 '19 at 20:39

A smart contract that uses an ERC20 token doesn't need to implement ERC20 functions, it only needs to call the functions. You can use an interface IERC20.sol to call a tokens functions.

OpenZeppelin utility contract SafeERC20 — provides safeTransfer, safeTransferFrom, and safeApprove that are helpful wrappers around the normal ERC20 functions. Using SafeERC20 forces transfers and approvals to succeed, or the entire transaction is reverted. https://docs.openzeppelin.org/v2.3.0/tokens#erc20

OpenZeppelin TokenTimelock and Crowdsale contracts are examples of interacting with an ERC20 token, including doing a safeTransfer

If you have questions on using OpenZeppelin then you can ask in the community forum https://forum.zeppelin.solutions

| improve this answer | |
  • 1
    Thanks , answer is quite clear now. – FLAME'S KING Jun 25 '19 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.