In solidity, most smart contracts cast external contract calls to interfaces (IERC20 vs. ERC20). Is there any difference casting between the two?
For example, if I write
IERC20 Token = IERC20(tokenContractAddress);
Is there any functional difference to
ERC20 Token = ERC20(tokenContractAddress);
?
Just curious if there are factors to consider in terms of gas costs, compatibility issues, etc. Thanks!
If you just want to access the functions, you can use either. But in interfaces you cannot have state variables so if you need some state variables you cast to contract.
Also interfaces cannot inherit other contracts or interfaces. Maybe the contract is inheriting from contractB and in your contract you want to access to contractB.