Skip to content

Commit bf49720

Browse files
authored
Merge pull request #658 from ethereum/doc-update
Update documentation
2 parents fc232fe + 3549bf4 commit bf49720

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

README.md

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ The low-level API is as follows:
204204

205205
For examples how to use them, please refer to the README of the above mentioned solc-js releases.
206206

207+
**Note**: These low-level functions remain available for compatibility reasons.
208+
However, they were superseded by the `compile()` function and are no longer required.
209+
Starting from version `0.5.0+commit.1d4f565a`, the functions `compileSingle`, `compileMulti`, and `compileCallback` are always `null` when using newer solc binary versions.
210+
It is recommended to use the latest release of solc-js, but it should also handle all the older solc binaries down to `0.1.x`.
211+
207212
### Using with Electron
208213

209214
**Note:**
@@ -239,10 +244,20 @@ solc.loadRemoteVersion('latest', function(err, solcSnapshot) {
239244
// An error was encountered, display and quit
240245
} else {
241246
// NOTE: Use `solcSnapshot` here with the same interface `solc` has
247+
// For example:
248+
const output = solcSnapshot.compile(/* ... */)
242249
}
243250
});
244251
```
245252

253+
The version **must** be in the long format.
254+
Thus, if you would like to use version `v0.8.17` you need to include the commit hash of the release.
255+
You can extract the long version string for each version from the [publicly available release list](https://binaries.soliditylang.org/bin/list.json).
256+
257+
```javascript
258+
solc.loadRemoteVersion('v0.8.17+commit.8df45f5f', function(err, solcSnapshot) { /* ... */ });
259+
```
260+
246261
### Linking Bytecode
247262

248263
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.
@@ -308,13 +323,39 @@ Add the version of `solc` you want to use into `index.html`:
308323
```html
309324
<script
310325
type="text/javascript"
311-
src="https://binaries.soliditylang.org/bin/{{ SOLC VERSION }}.js"
326+
src="https://binaries.soliditylang.org/bin/{{ SOLC_VERSION }}.js"
327+
integrity="sha256-{{ BASE64_ENCODED_HASH_OF_SOLC_VERSION }}"
328+
crossorigin="anonymous"
312329
></script>
313330
```
314331

315-
(Alternatively use `https://binaries.soliditylang.org/bin/soljson-latest.js` to get the latests version.)
332+
This will load `solc` into the global variable `window.Module`.
333+
Alternatively, use `soljson-latest.js` as `{{ SOLC_VERSION }}.js` in the code snippet above to load the latest version.
334+
335+
It is recommended that you check the integrity of the resource being fetched before using it in your application.
336+
For that, you can use the [Subresource Integrity (SRI)](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) feature.
337+
Adding SRI configuration to your HTML script tag ensures that the resource will only be loaded by the browser if the cryptographic hashes match.
338+
339+
You can generate the SRI hash yourself based on the base64-encoded version of the sha256 hash of the release.
340+
For example, after downloading version `v0.8.16+commit.07a7930e`, run:
341+
```bash
342+
node -e "console.log(crypto.createHash('sha256').update(fs.readFileSync('./soljson-v0.8.16+commit.07a7930e.js', 'utf8')).digest('base64'))"
343+
```
344+
```
345+
J7KCDvk4BaZcdreUWklDJYLTBv0XoomFcJpR5kA2d8I=
346+
```
347+
348+
And update your `index.html` to:
349+
```html
350+
<script
351+
type="text/javascript"
352+
src="https://binaries.soliditylang.org/bin/soljson-v0.8.16+commit.07a7930e.js"
353+
integrity="sha256-J7KCDvk4BaZcdreUWklDJYLTBv0XoomFcJpR5kA2d8I="
354+
crossorigin="anonymous"
355+
></script>
356+
```
316357

317-
This will load `solc` into the global variable `window.Module`. Then use this inside Javascript as:
358+
Then use this inside JavaScript as:
318359

319360
```javascript
320361
var wrapper = require('solc/wrapper');
@@ -324,7 +365,7 @@ var solc = wrapper(window.Module);
324365
Or in ES6 syntax:
325366

326367
```javascript
327-
import * as wrapper from 'solc/wrapper';
368+
import wrapper from 'solc/wrapper';
328369
const solc = wrapper(window.Module);
329370
```
330371

0 commit comments

Comments
 (0)