Why is IERC20 needed?

Why is the interface IERC20 needed?
Can I just copy ERC20’s code into myToken without inheriting the interface?
what’s the difference in doing it this way?
is it still an ERC20 compatible token?

2 Likes

Hi @Marc_Rod,

Welcome to the community forum :wave:

IERC20 defines functions and events as per the standard defined in the EIP, so implementing the interface is good practice so that your token's functions and events match the EIP.

:warning: To keep your system secure, you should always use the installed code as-is, and neither copy-paste it from online sources, nor modify it yourself.

OpenZeppelin Contracts has a MIT License

I am curious to why you don't want to inherit from the OpenZeppelin implementation?

Creating an ERC20 token inheriting from the OpenZeppelin implementation is fairly straight forward. There is an example in the documentation: Constructing an ERC20 Token Contract:

pragma solidity ^0.5.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";

contract GLDToken is ERC20, ERC20Detailed {
    constructor(uint256 initialSupply) ERC20Detailed("Gold", "GLD", 18) public {
        _mint(msg.sender, initialSupply);
    }
}

:warning: Any solution should be appropriately tested and audited.

It is good practice to implement an interface that conforms to the specification.

If your token doesn't inherit from IERC20 then you need to ensure that your functions and events match the specification in the EIP.

If your functions and events match the specification in the EIP and the functionality complies with the EIP then your token would be ERC20 compatible.

You may also want to look at: Online ERC20 contract verifier

2 Likes

Hi @Marc_Rod,

Let me know if you need any more information.