0

I see suggestions here and there to import an interface instead of the whole contract to reduce contract's bytecode and deployment costs.

Consider the following structures:

contract Storage {
   uint data;

   function setData(uint _data) public {
      data = _data;
   }
}

contract IStorage {
   function setData(uint _data) public; 
}

contract Logic1 {
   Storage st;

   constructor (address _storage) public {
      st = Storage(_storage);
   }
}

contract Logic2 {
   IStorage st;

   constructor (address _storage) public {
      st = IStorage(_storage);
   }
}

Deploying contract Logic1 has the same exact deployment costs of Logic2.

Why whould I want to use an interface in this case?

  • In your example, you'd want to use the interface instead of the contract, in order to allow yourself to import the interface instead of the contract, which would yield fewer dependencies in your code. – goodvibration Jul 2 '19 at 9:46

Your Answer

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

Browse other questions tagged or ask your own question.