I'm trying to understand if there is any difference between passing an object vs passing the address and casting. For example:

function getTotalSupply(IERC20 token) view returns (uint256) {
   return token.totalSupply()


function getTotalSupply(address token) view returns (uint256) {
   return IERC20(token).totalSupply()

I have couple questions:

  • Is one of them cheaper? If so, what is the way to go about empirically determining the difference?
  • In the first case, does it make a difference if I add memory (IERC20 memory token) in the function call?


1 Answer 1


As outline in quite some other post Interfaces are only syntactic sugar around addresses (e.g. How is an interface initialised?).

As an interface is under the hood "just" and address you cannot use memory on it as this will only work on reference types (see When to use memory and when not to use?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.