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
Copy file name to clipboardExpand all lines: README.md
+59-72Lines changed: 59 additions & 72 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,108 +31,95 @@ used in combination with an Ethereum client via the `eth.compile.solidity()` RPC
31
31
32
32
### Usage in Projects
33
33
34
-
#### From version 0.5.0
34
+
There are two ways to use `solc`:
35
+
1) Through a high-level API giving a uniform interface to all compiler versions
36
+
2) Through a low-level API giving access to all the compiler interfaces, which depend on the version of the compiler
35
37
36
-
Starting from version 0.5.0, `compile`, `compileStandard` and `compileStandardWrapper` all do the same thing - what `compileStandardWrapper` used to do.
38
+
#### High-level API
37
39
38
-
*Note*: with 0.5.2, `compileStandard` and `compileStandardWrapper` will be removed.
40
+
The high-level API consists of a single method, `compile`, which expects the [Compiler Standard Input and Output JSON](https://solidity.readthedocs.io/en/v0.5.0/using-the-compiler.html#compiler-input-and-output-json-description).
39
41
40
-
Starting from version 0.5.0 the low-level functions are also exposed:
41
-
-`solc.lowlevel.compileSingle`: the original entry point, supports only a single file
42
-
-`solc.lowlevel.compileMulti`: this supports multiple files, introduced in 0.1.6
43
-
-`solc.lowlevel.compileCallback`: this supports callbacks, introduced in 0.2.1
44
-
-`solc.lowlevel.compileStandard`: this supports the Standard JSON input and output interface, introduced in 0.4.11
42
+
It also accepts an optional callback function to resolve unmet dependencies. This callback receives a path and must synchronously return either an error or the content of the dependency as a string.
43
+
It cannot be used together with callback-based, asynchronous, filesystem access. A workaround is to collect the names of dependencies, return an error, and keep re-running the compiler until all
44
+
of them are resolved.
45
+
46
+
*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.
47
+
48
+
#### Example usage without the import callback
45
49
46
50
Example:
47
51
```javascript
48
52
var solc =require('solc')
53
+
49
54
var input = {
50
-
'lib.sol':'library L { function f() returns (uint) { return 7; } }',
51
-
'cont.sol':'import "lib.sol"; contract x { function g() { L.f(); } }'
55
+
language:'Solidity',
56
+
sources: {
57
+
'test.sol': {
58
+
content:'contract C { function f() public { } }'
59
+
}
60
+
},
61
+
settings: {
62
+
outputSelection: {
63
+
'*': {
64
+
'*': [ '*' ]
65
+
}
66
+
}
67
+
}
52
68
}
53
-
var output =JSON.parse(solc.lowlevel.compileMulti(JSON.stringify({ sources: input }), 1))
Starting from version 0.4.20 a Semver compatible version number can be retrieved on every compiler release, including old ones, using the `semver()` method.
61
69
62
-
#### From version 0.4.11
70
+
var output =JSON.parse(solc.compile(JSON.stringify(input)))
63
71
64
-
Starting from version 0.4.11 there is a new entry point named `compileStandardWrapper()` which supports Solidity's [standard JSON input and output](https://solidity.readthedocs.io/en/develop/using-the-compiler.html#compiler-input-and-output-json-description). It also maps old compiler output to it.
65
-
66
-
```javascript
67
-
var solc =require('solc')
68
-
69
-
// 'input' is a JSON string corresponding to the "standard JSON input" as described in the link above
70
-
// 'findImports' works as described above
71
-
var output =solc.compileStandardWrapper(input, findImports)
72
-
// Ouput is a JSON string corresponding to the "standard JSON output"
72
+
// `output` here contains the JSON output as specified in the documentation
73
+
for (var contractName inoutput.contracts['test.sol']) {
There is also a direct method, `compileStandard`, which is only present on recent compilers and works the same way. `compileStandardWrapper` is preferred however because it provides the same interface for old compilers.
76
-
77
-
#### From version 0.2.1
78
-
79
-
**Not available since 0.5.0**
80
-
81
-
Starting from version 0.2.1, a callback is supported to resolve missing imports as follows:
78
+
#### Example usage with import callback
82
79
83
80
```javascript
84
81
var solc =require('solc')
82
+
85
83
var input = {
86
-
'cont.sol':'import "lib.sol"; contract x { function g() { L.f(); } }'
84
+
language:'Solidity',
85
+
sources: {
86
+
'test.sol': {
87
+
content:'import "lib.sol"; contract C { function f() public { L.f(); } }'
88
+
}
89
+
},
90
+
settings: {
91
+
outputSelection: {
92
+
'*': {
93
+
'*': [ '*' ]
94
+
}
95
+
}
96
+
}
87
97
}
98
+
88
99
functionfindImports (path) {
89
100
if (path ==='lib.sol')
90
-
return { contents:'library L { function f() returns (uint) { return 7; } }' }
101
+
return { contents:'library L { function f() internal returns (uint) { return 7; } }' }
91
102
else
92
103
return { error:'File not found' }
93
104
}
94
-
var output =solc.compile({ sources: input }, 1, findImports)
0 commit comments