Skip to content

Commit 66d9ac6

Browse files
authored
Merge pull request #123 from ethereum/cleanup-readme
Cleanup code style in readme
2 parents 3e7027d + a56de7c commit 66d9ac6

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

README.md

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ used in combination with an Ethereum client via the `eth.compile.solidity()` RPC
3434
It can also be included and used in other projects:
3535

3636
```javascript
37-
var solc = require('solc');
38-
var input = 'contract x { function g() {} }';
39-
var output = solc.compile(input, 1); // 1 activates the optimiser
37+
var solc = require('solc')
38+
var input = 'contract x { function g() {} }'
39+
// Setting 1 as second paramateractivates the optimiser
40+
var output = solc.compile(input, 1)
4041
for (var contractName in output.contracts) {
4142
// code and ABI that are needed by web3
42-
console.log(contractName + ': ' + output.contracts[contractName].bytecode);
43-
console.log(contractName + '; ' + JSON.parse(output.contracts[contractName].interface));
43+
console.log(contractName + ': ' + output.contracts[contractName].bytecode)
44+
console.log(contractName + '; ' + JSON.parse(output.contracts[contractName].interface))
4445
}
4546
```
4647

@@ -49,14 +50,14 @@ for (var contractName in output.contracts) {
4950
Starting from version 0.1.6, multiple files are supported with automatic import resolution by the compiler as follows:
5051

5152
```javascript
52-
var solc = require('solc');
53+
var solc = require('solc')
5354
var input = {
5455
'lib.sol': 'library L { function f() returns (uint) { return 7; } }',
5556
'cont.sol': 'import "lib.sol"; contract x { function g() { L.f(); } }'
56-
};
57-
var output = solc.compile({sources: input}, 1);
57+
}
58+
var output = solc.compile({ sources: input }, 1)
5859
for (var contractName in output.contracts)
59-
console.log(contractName + ': ' + output.contracts[contractName].bytecode);
60+
console.log(contractName + ': ' + output.contracts[contractName].bytecode)
6061
```
6162

6263
Note that all input files that are imported have to be supplied, the compiler will not load any additional files on its own.
@@ -66,19 +67,19 @@ Note that all input files that are imported have to be supplied, the compiler wi
6667
Starting from version 0.2.1, a callback is supported to resolve missing imports as follows:
6768

6869
```javascript
69-
var solc = require('solc');
70+
var solc = require('solc')
7071
var input = {
7172
'cont.sol': 'import "lib.sol"; contract x { function g() { L.f(); } }'
72-
};
73-
function findImports(path) {
73+
}
74+
function findImports (path) {
7475
if (path === 'lib.sol')
7576
return { contents: 'library L { function f() returns (uint) { return 7; } }' }
7677
else
7778
return { error: 'File not found' }
7879
}
79-
var output = solc.compile({sources: input}, 1, findImports);
80+
var output = solc.compile({ sources: input }, 1, findImports)
8081
for (var contractName in output.contracts)
81-
console.log(contractName + ': ' + output.contracts[contractName].bytecode);
82+
console.log(contractName + ': ' + output.contracts[contractName].bytecode)
8283
```
8384

8485
The `compile()` method always returns an object, which can contain `errors`, `sources` and `contracts` fields. `errors` is a list of error mesages.
@@ -87,6 +88,8 @@ The `compile()` method always returns an object, which can contain `errors`, `so
8788

8889
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.
8990

91+
### Using with Electron
92+
9093
**Note:**
9194
If you are using Electron, `nodeIntegration` is on for `BrowserWindow` by default. If it is on, Electron will provide a `require` method which will not behave as expected and this may cause calls, such as `require('solc')`, to fail.
9295

@@ -97,21 +100,21 @@ new BrowserWindow({
97100
webPreferences: {
98101
nodeIntegration: false
99102
}
100-
});
103+
})
101104
```
102105

103106
### Using a Legacy Version
104107

105108
In order to compile contracts using a specific version of Solidity, the `solc.useVersion` method is available. This returns a new `solc` object that uses a version of the compiler specified. **Note**: version strings must match the version substring of the files available in `/bin/soljson-*.js`. See below for an example.
106109

107110
```javascript
108-
var solc = require('solc');
111+
var solc = require('solc')
109112
// by default the latest version is used
110113
// ie: solc.useVersion('latest')
111114

112115
// getting a legacy version
113-
var solcV011 = solc.useVersion('v0.1.1-2015-08-04-6ff4cd6');
114-
var output = solcV011.compile('contract t { function g() {} }', 1);
116+
var solcV011 = solc.useVersion('v0.1.1-2015-08-04-6ff4cd6')
117+
var output = solcV011.compile('contract t { function g() {} }', 1)
115118
```
116119

117120
If the version is not available locally, you can use `solc.loadRemoteVersion(version, callback)` to load it directly from GitHub.
@@ -124,15 +127,15 @@ You can also load the "binary" manually and use `setupMethods` to create the fam
124127
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.
125128

126129
```javascript
127-
var solc = require('solc');
130+
var solc = require('solc')
128131

129132
// getting the development snapshot
130-
solc.loadRemoteVersion('latest', function(err, solcSnapshot) {
133+
solc.loadRemoteVersion('latest', function (err, solcSnapshot) {
131134
if (err) {
132135
// An error was encountered, display and quit
133136
}
134-
var output = solcSnapshot.compile("contract t { function g() {} }", 1);
135-
});
137+
var output = solcSnapshot.compile("contract t { function g() {} }", 1)
138+
})
136139
```
137140

138141
### Linking Bytecode
@@ -142,7 +145,7 @@ When using libraries, the resulting bytecode will contain placeholders for the r
142145
The `linkBytecode` method provides a simple helper for linking:
143146

144147
```javascript
145-
bytecode = solc.linkBytecode(bytecode, { 'MyLibrary': '0x123456...' });
148+
bytecode = solc.linkBytecode(bytecode, { 'MyLibrary': '0x123456...' })
146149
```
147150

148151
Note: in future versions of Solidity a more sophisticated linker architecture will be introduced. Once that changes, this method will still be usable for output created by old versions of Solidity.
@@ -153,9 +156,9 @@ The ABI generated by Solidity versions can differ slightly, due to new features
153156

154157
It can be used as:
155158
```javascript
156-
var abi = require('solc/abi');
159+
var abi = require('solc/abi')
157160

158-
var inputABI = [{"constant":false,"inputs":[],"name":"hello","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"}];
161+
var inputABI = [{"constant":false,"inputs":[],"name":"hello","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"}]
159162
var outputABI = abi.update('0.3.6', inputABI)
160163
// Output contains: [{"constant":false,"inputs":[],"name":"hello","outputs":[{"name":"","type":"string"}],"payable":true,"type":"function"},{"type":"fallback","payable":true}]
161164

0 commit comments

Comments
 (0)