Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading