Libraries are deployed only once at a specific address and their code is called via CALLCODE or DELEGATECALL opcode of the EVM. The key idea behind libraries is code reusability. They are similar to contracts and act as base contracts to the calling contracts. A library can be declared as shown in the following example:
library Addition { function Add(uint x,uint y) returns (uint z) { return x + y; } }
This library can then be called in the contract, as shown here. First, it needs to be imported and then it can be used anywhere in the code. A simple example is shown as follows:
import "Addition.sol" function Addtwovalues() returns(uint) { return Addition.Add(100,100); }
There are a few limitations with libraries; for example, ...