You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JavaScript bindings for the [Solidity compiler](https://github.com/ethereum/solidity).
7
8
8
9
Uses the Emscripten compiled Solidity found in the [solc-bin repository](https://github.com/ethereum/solc-bin).
@@ -35,8 +36,9 @@ mentioned on the command line.
35
36
### Usage in Projects
36
37
37
38
There are two ways to use `solc`:
38
-
1) Through a high-level API giving a uniform interface to all compiler versions
39
-
2) Through a low-level API giving access to all the compiler interfaces, which depend on the version of the compiler
39
+
40
+
1. Through a high-level API giving a uniform interface to all compiler versions
41
+
2. Through a low-level API giving access to all the compiler interfaces, which depend on the version of the compiler
40
42
41
43
#### High-level API
42
44
@@ -48,81 +50,95 @@ of them are resolved.
48
50
49
51
Starting 0.5.12 it also accepts an object in place of the callback to supply different kind of callbacks, however only file imports are supported.
50
52
51
-
*Note*: as an intermittent backwards compatibility feature, between versions 0.5.0 and 0.5.2, `compileStandard` and `compileStandardWrapper` also exists and behave like `compile` does.
53
+
_Note_: as an intermittent backwards compatibility feature, between versions 0.5.0 and 0.5.2, `compileStandard` and `compileStandardWrapper` also exists and behave like `compile` does.
52
54
53
55
#### Example usage without the import callback
54
56
55
57
Example:
58
+
56
59
```javascript
57
-
var solc =require('solc')
60
+
var solc =require('solc');
58
61
59
62
var input = {
60
-
language:'Solidity',
61
-
sources: {
62
-
'test.sol': {
63
-
content:'contract C { function f() public { } }'
64
-
}
65
-
},
66
-
settings: {
67
-
outputSelection: {
68
-
'*': {
69
-
'*': ['*']
70
-
}
71
-
}
72
-
}
73
-
}
74
-
75
-
var output =JSON.parse(solc.compile(JSON.stringify(input)))
63
+
language:'Solidity',
64
+
sources: {
65
+
'test.sol': {
66
+
content:'contract C { function f() public { } }'
67
+
}
68
+
},
69
+
settings: {
70
+
outputSelection: {
71
+
'*': {
72
+
'*': ['*']
73
+
}
74
+
}
75
+
}
76
+
};
77
+
78
+
var output =JSON.parse(solc.compile(JSON.stringify(input)));
76
79
77
80
// `output` here contains the JSON output as specified in the documentation
78
81
for (var contractName inoutput.contracts['test.sol']) {
-`solc.lowlevel.compileSingle`: the original entry point, supports only a single file
127
143
-`solc.lowlevel.compileMulti`: this supports multiple files, introduced in 0.1.6
128
144
-`solc.lowlevel.compileCallback`: this supports callbacks, introduced in 0.2.1
@@ -139,15 +155,15 @@ To turn off `nodeIntegration`, use the following:
139
155
140
156
```javascript
141
157
newBrowserWindow({
142
-
webPreferences: {
143
-
nodeIntegration:false
144
-
}
145
-
})
158
+
webPreferences: {
159
+
nodeIntegration:false
160
+
}
161
+
});
146
162
```
147
163
148
164
### Using a Legacy Version
149
165
150
-
In order to compile contracts using a specific version of Solidity, the `solc.loadRemoteVersion(version, callback)` method is available. This returns a new `solc` object that uses a version of the compiler specified.
166
+
In order to compile contracts using a specific version of Solidity, the `solc.loadRemoteVersion(version, callback)` method is available. This returns a new `solc` object that uses a version of the compiler specified.
151
167
152
168
You can also load the "binary" manually and use `setupMethods` to create the familiar wrapper functions described above:
@@ -157,16 +173,16 @@ You can also load the "binary" manually and use `setupMethods` to create the fam
157
173
By default, the npm version is only created for releases. This prevents people from deploying contracts with non-release versions because they are less stable and harder to verify. If you would like to use the latest development snapshot (at your own risk!), you may use the following example code.
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. It also doesn't have the limitation on library file and contract name lengths.
202
+
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. It also doesn't have the limitation on library file and contract name lengths.
187
203
188
204
There is a method available in the `linker` module called `findLinkReferences` which can find such link references in bytecode produced by an older compiler:
189
205
190
206
```javascript
191
-
var linker =require('solc/linker')
207
+
var linker =require('solc/linker');
192
208
193
-
var linkReferences =linker.findLinkReferences(bytecode)
209
+
var linkReferences =linker.findLinkReferences(bytecode);
194
210
```
195
211
196
212
### Updating the ABI
197
213
198
-
The ABI generated by Solidity versions can differ slightly, due to new features introduced. There is a tool included which aims to translate the ABI generated by an older Solidity version to conform to the latest standard.
214
+
The ABI generated by Solidity versions can differ slightly, due to new features introduced. There is a tool included which aims to translate the ABI generated by an older Solidity version to conform to the latest standard.
199
215
200
216
It can be used as:
201
-
```javascript
202
-
var abi =require('solc/abi')
203
217
204
-
var inputABI = [{"constant":false,"inputs":[],"name":"hello","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"}]
This will result in two global variables, `window.soljsonReleases` listing all releases and `window.soljsonSources` listing all nightly builds and releases.
0 commit comments