Interfaces and Librariese
Interfaces
An interface is a contract sugar type with restrictions. This type cannot be instantiated; it can only define the functions prototypes for a contract. This is useful as a generic interface.
No contract storage variables can exist (however constants are allowed)
No function can have a body or implementation
Libraries
Libraries are a special type of contract which can be reused in multiple contracts. Functions declared in a library can be called with the library.function()
syntax. When the library has been imported or declared, any contract can use its functions simply by using its name.
When using the Ethereum Foundation Solidity compiler, libraries are a special contract type and are called using delegatecall.Ola statically links the library calls into your contract code. This generates larger contract code, however it reduces the call overhead and make it possible to do compiler optimizations across library and contract code.
Last updated