Library
Programming languages provide facilities to write reusable code and use it across multiple projects. Solidity has a similar concept through which code written once in a library can be reused across multiple smart contracts. A library in Solidity is created using the library
keyword followed by the library
code within a {}
block:
library { }
The concept of a library might sound very similar to that of a contract; however, there are differences. The similarity of a library with a contract is that they both consist of functions and they both can be deployed on the Ethereum network. They both generate unique addresses on the Ethereum network. However, a library can declare its own state variables. A library does not manage or maintain any state. It has a set of functions that are available for use as reusable code. So, ideally, they are best suited for implementing logic that is common across contracts without the involvement of state variables.
The code for a simple...