Skip to content

Commit 01125f1

Browse files
r0qschristianparpartmatheusaaguiarcameel
committed
General readme updates:
- Document the necessity of using long version string in loadRemoteVersion - Add note about low-level functions - Fix SRI documentation - Improve text Co-authored-by: Christian Parpart <[email protected]> Co-authored-by: matheusaaguiar <[email protected]> Co-authored-by: Kamil Śliwak <[email protected]>
1 parent 0de43fc commit 01125f1

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

README.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ 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 in newer versions. The functions `compileSingle`, `compileMulti` and `compileCallback` are always `null` in the newer versions.
209+
207210
### Using with Electron
208211

209212
**Note:**
@@ -239,10 +242,20 @@ solc.loadRemoteVersion('latest', function(err, solcSnapshot) {
239242
// An error was encountered, display and quit
240243
} else {
241244
// NOTE: Use `solcSnapshot` here with the same interface `solc` has
245+
// For example:
246+
const output = solcSnapshot.compile(/* ... */)
242247
}
243248
});
244249
```
245250

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

248261
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,25 +321,39 @@ Add the version of `solc` you want to use into `index.html`:
308321
```html
309322
<script
310323
type="text/javascript"
311-
src="https://binaries.soliditylang.org/bin/{{ SOLC VERSION }}.js"
312-
integrity="sha256-{{ BASE64-ENCODED HASH OF SOLC VERSION }}"
324+
src="https://binaries.soliditylang.org/bin/{{ SOLC_VERSION }}.js"
325+
integrity="sha256-{{ BASE64_ENCODED_HASH_OF_SOLC_VERSION }}"
313326
crossorigin="anonymous"
314327
></script>
315328
```
316329

317-
(Alternatively, use `https://binaries.soliditylang.org/bin/soljson-latest.js` to get the latest version.)
330+
This will load `solc` into the global variable `window.Module`.
331+
Alternatively, use `soljson-latest.js` as `{{ SOLC_VERSION }}.js` in the code snippet above to load the latest version.
318332

319333
It is recommended that you check the integrity of the resource being fetched before using it in your application.
320334
For that, you can use the [Subresource Integrity (SRI)](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) feature.
321-
Adding SRI configuration to your HTML script tag ensures that the resource will only be loaded in the browser if the cryptographic hashes matches.
335+
Adding SRI configuration to your HTML script tag ensures that the resource will only be loaded by the browser if the cryptographic hashes match.
322336

323-
You can run the script [get-sri.sh](./get-sri.sh) informing the desired solc-js version or compute it yourself based on the base64-encoded version of the sha256 hash of the release.
337+
You can generate the SRI hash yourself based on the base64-encoded version of the sha256 hash of the release.
338+
For example, after downloading version `v0.8.16+commit.07a7930e`, run:
339+
```bash
340+
sha256sum --binary soljson-v0.8.16+commit.07a7930e.js | awk '{ print $1 }' | xxd -revert -plain | base64
341+
```
324342
```
325-
./get-sri.sh 0.8.16
326-
sha256-J7KCDvk4BaZcdreUWklDJYLTBv0XoomFcJpR5kA2d8I= soljson-v0.8.16+commit.07a7930e.js
343+
J7KCDvk4BaZcdreUWklDJYLTBv0XoomFcJpR5kA2d8I=
344+
```
345+
346+
And update your `index.html` to:
347+
```html
348+
<script
349+
type="text/javascript"
350+
src="https://binaries.soliditylang.org/bin/soljson-v0.8.16+commit.07a7930e.js"
351+
integrity="sha256-J7KCDvk4BaZcdreUWklDJYLTBv0XoomFcJpR5kA2d8I="
352+
crossorigin="anonymous"
353+
></script>
327354
```
328355

329-
This will load `solc` into the global variable `window.Module`. Then use this inside Javascript as:
356+
Then use this inside JavaScript as:
330357

331358
```javascript
332359
var wrapper = require('solc/wrapper');

0 commit comments

Comments
 (0)