2

I was wondering why most tokens inherit from an ERC20 interface, instead of just implementing all the functions directly. Are there are any problems that arise if the interface functions are just implemented directly?

5

When the developer makes a contract that inherits the interface, he/she is committing to implementing the functions defined in the interface. Failing to do so will result in undefined functions in the contract. Since that will not do, the contract will be rejected by the EVM.

From a quality assurance perspective, a refusal to deploy contract with an obvious oversight is exactly what you want.

Hope it helps.

3
  • This is very true! However I find this to be a double edged sword, since by default importing the interface requires you to implement all functions, even though one may only want to implement a few of them. Thus one is required to either manually define the function signatures, or remove them from the interface code if you do not wish to implement all interfaces. – hextet Apr 6 '18 at 16:04
  • But this way you are forced to make actions not to implement the standard optional methods. This is a conscious decision not to implement methods and there's no risk of forgetting – Daniel Luca CleanUnicorn Apr 6 '18 at 16:07
  • 1
    Right. In the context of "Standard Token" it's important to implement all functions the standard says the contract must implement. One can decide a certain function isn't necessary and not implement it, but one cannot simultaneously say it is still a standard ERC20 token. Missing functions break compatibility. It may be "valid" but it is not "standard". – Rob Hitchens Jul 8 '19 at 20:14

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.