Search code examples
ethereumsolidity

Difference between IERC20 and just address


There are two ways of declaration ERC20 in other contracts:

  1. IERC20 public token, and then connecting to it like token.transfer;
  2. address public token, and then connecting to it like IERC20(token).transfer.

Is there any difference between these two ways of declaration? If so, what is more preferred for usage?


Solution

  • The only difference is during compilation, when the compiler would give you an error if you tried to use one type where the other is required.

    In terms of runtime, they are both (160-bit) ethereum addresses.

    In your example, it makes more sense to use the type IERC20, because that is the intended type of the variable token.