0

what is a general rule of thumb for creating interfaces? Why would I want an interface i.e. IAugur.sol instead of the entire Augur.sol file? Can someone shed light on interface best practices and pros/cons.

2

There are two main reasons.

  1. To minimize contract size
  2. To ensure compliance

If you make the smallest possible contract and use Augor.sol, then your contract will be at least as big as Augor.sol.

contract Mine {
  Augor a;
}

You have defined a as an instance of Augor and that means all of the Augor bytecode is rolled up into yours. It's not evaluated for usefulness, so the fact it isn't used doesn't reduce the size of your contract.

If you, instead say:

IAugor a;

Your contract will include the code for the interface which should be much smaller. The interface is all that is required. It's a black box and its internal workings are not relevant. Only the function signatures and expected responses.

Interfaces are also useful for ensuring and demonstrating compliance. For example, one might say "My contract is an ERC20 token." Is it? Does it implement all the required functions?

You can say:

contract MyIncompleteToken is ERC20 {} // where ERC20 is the standard interface

It will compile but it will not deploy. It won't deploy because the interface laid out some functions and they have no implementation. This can help catch developer oversight. The inherited interface is a commitment to implement all the promised functions. It is not a catch-all for every compatibility concern, but it is helpful.

Hope it helps.

1

Because often when you're writing contracts which interact with other contracts, the internal workings of those contracts are not relevant, just the externally exposed functions. By providing an Interface, other developers can write code that interacts perfectly with yours, without needing to see/include your entire codebase.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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