Member-only story
Solidity Tutorial: all about Libraries

Table of Contents
- What are Libraries in Solidity?
- How to create a library contract?
- How to deploy libraries?
- How to use a Library in a smart contract?
- How to interact with libraries?
- Understanding functions in libraries.
- Events and Libraries
- Mappings in Library = more functionalities !
- Using structs inside Libraries
- Linking libraries with other libraries
- Using modifier inside libraries
- What you can’t do with Libraries in Solidity?
- Some popular existing libraries
References
1. What are Libraries in Solidity?
Libraries can be seen as implicit base contracts of the contracts that use them (Solidity doc)
A library
in Solidity is a different type of smart contract that contains reusable code. Once deployed on the blockchain (only once), it is assigned a specific address and its properties / methods can be reused many times by other contracts in the Ethereum network.
They enable to develop in a more modular way. Sometimes, it is helpful to think of a library as a singleton in the EVM, a piece of code that can be called from any contract without the need to deploy it again.
Benefits
However, libraries in Solidity are not only limited to reusability. Here are some of their advantages :
- Usability : Functions in a library can be used by many contracts. If you have many contracts that have some common code, then you can deploy that common code as a library.
- Economical : Deploying common code as library will save gas as gas depends on the size of the contract too. Using a base contract instead of a library to split the common code won’t save gas because in Solidity, inheritance works by copying code.
- Good add-ons : Solidity libraries can be used to add member functions to data types. For instance, think of libraries…