EatTheBlocks Forum

Development mastery : When to use ERC20 and IERC20?

Hi!

I have 2 questions regarding the ERC20 token video in the Defi development mastery:

  1. In order to create an ERC20 token, an ERC20.sol in openzeppelin is being imported and is being used. In order to transfer token between contracts, an IERC20.sol in openzeppelin is being used. My question is when to use ERC20 and when to use IERC20?

  2. In the token.transferFrom function, is msg.sender is the owner of the contractA? Address(this) means the address of contractA?

Does anyone know? Thanks!

Hi Cheryl,

Below the answers:

1- ERC20 is commonly used in case you want to create a token, so you can manage its name, decimals, supply (mint, burn), etc, whereas IERC20 is to use an existing token (so that you can create an instance pointing to that token by just sending its address by parameter).

2- this refers always to the instance of a contract, therefore, address(this) is the contract address regardless of the caller (msg.sender).

2 Likes