I have several pieces of documentation about libraries, but I am not yet able to infer what steps are needed to compile and deploy a library and then a contract that uses it. The behavior of the library within solidity is quite clear, but compiling and linking is not obvious to me.
Resources I have consulted:
- http://solidity.readthedocs.io/en/latest/contracts.html#libraries
- http://solidity.readthedocs.io/en/latest/miscellaneous.html#commandline-compiler
- https://github.com/ethereum/wiki/wiki/Solidity-Features#libraries-without-inheritance
- https://github.com/ethereum/solc-js
- https://ethereum.stackexchange.com/questions/2916/finding-and-using-solidity-libraries-ie-math-functions/2933
Here is an example contract and library that I would like to get working:
MetaCoin.sol:
import "TestLib.sol";
contract MetaCoin {
TestLib.Data data;
address public owner;
function MetaCoin() {
owner = msg.sender;
TestLib.Set(data, 2);
}
function GetData() constant returns(uint) {
return TestLib.Get(data);
}
}
TestLib.sol:
library TestLib {
struct Data {
uint n;
}
function Set(Data storage self, uint a) {
self.n = a;
}
function Get(Data storage self) returns(uint) {
return self.n;
}
}
Thanks for your help!