Skip to content

Commit 211de4d

Browse files
committed
Update README to explain linkBytecode is part of the linker module
1 parent fc32e8b commit 211de4d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,27 @@ solc.loadRemoteVersion('latest', function (err, solcSnapshot) {
146146

147147
When using libraries, the resulting bytecode 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.
148148

149+
The `linker` module (`require('solc/linker')`) offers helpers to accomplish this.
150+
149151
The `linkBytecode` method provides a simple helper for linking:
150152

151153
```javascript
152-
bytecode = solc.linkBytecode(bytecode, { 'MyLibrary': '0x123456...' })
154+
var linker = require('solc/linker')
155+
156+
bytecode = linker.linkBytecode(bytecode, { 'MyLibrary': '0x123456...' })
153157
```
154158

159+
(Note: `linkBytecode` is also exposed via `solc` as `solc.linkBytecode`, but this usage is deprecated.)
160+
155161
As of Solidity 0.4.11 the compiler supports [standard JSON input and output](https://solidity.readthedocs.io/en/develop/using-the-compiler.html#compiler-input-and-output-json-description) which outputs a *link references* map. This gives a map of library names to offsets in the bytecode to replace the addresses at.
156162

157-
There is a method available in the `linker` module (`require('solc/linker')`) called `findLinkReferences` which can find such link references in bytecode produced by an older compiler.
163+
There is a method available in the `linker` module called `findLinkReferences` which can find such link references in bytecode produced by an older compiler:
164+
165+
```javascript
166+
var linker = require('solc/linker')
167+
168+
var linkReferences = linker.findLinkReferences(bytecode)
169+
```
158170

159171
### Updating the ABI
160172

0 commit comments

Comments
 (0)