Libraries
Learn about Solidity libraries.
Solidity libraries are reusable components that contain functions that can be accessed by other contracts. Libraries, like contracts, are primarily intended for reuse. Solidity libraries are distinguished by certain requirements and features that ensure their proper use inside the Ethereum ecosystem.
Key features of Solidity libraries
Here are the key features of Solidity libraries:
Direct invocation of stateless functions: Library functions that don’t alter the system’s state can be directly invoked. Only
pure
orview
functions from thelibrary
can be called externally.Immutable and stateless nature: Libraries are considered stateless, and once deployed, they can’t be destroyed. Their immutability ensures consistency and reliability in their functionality.
Prohibition of state variables: Libraries aren’t allowed to have state variables. This constraint emphasizes their stateless design and reinforces the idea of using libraries for utility functions.
No inheritance for libraries: Libraries can’t inherit from other contracts, and no contract can inherit from a library. This restriction maintains a clear separation between libraries and contracts.
No inheriting elements: Libraries can’t inherit any elements from other contracts. They stand alone as self-contained utility components.
Get hands-on with 1400+ tech skills courses.