April 2017
Intermediate to advanced
266 pages
7h 4m
English
If your solidity source code references libraries, then the generated byte code will contain placeholders for the real addresses of the referenced libraries. These have to be updated via a process called linking before deploying the contract.
solcjs provides the linkByteCode method to link library addresses to the generated byte code.
Here is an example to demonstrate this:
var solc = require("solc"); var input = { "lib.sol": "library L { function f() returns (uint) { return 7; } }", "cont.sol": "import 'lib.sol'; contract x { function g() { L.f(); } }" }; var output = solc.compile({sources: input}, 1); var finalByteCode = solc.linkBytecode(output.contracts["x"].bytecode, { 'L': '0x123456...' });