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
-[Write Secure and Effective dApps with the Polkadot Network](#write-secure-and-effective-dapps-with-the-polkadot-network)
16
+
-[Additional Resources](#additional-resources)
17
+
-[Why Embed a Light Client in Browser Extensions?](#why-embed-a-light-client-in-browser-extensions)
17
18
-[Comprehensive API Documentation](#comprehensive-api-documentation)
18
19
-[Repository Structure](#repository-structure)
19
20
-[Packages](#packages)
@@ -27,16 +28,33 @@
27
28
28
29
## Introduction
29
30
30
-
Substrate Connect offers an innovative way to interact with [Substrate](https://substrate.dev/)-based blockchains directly in your browser, eliminating the need for an RPC server. By leveraging the [smoldot](https://github.com/smol-dot/smoldot) WASM light client, it ensures a secure and efficient connection to the blockchain network without dependency on specific third parties.
31
+
Substrate Connect provides a groundbreaking method to engage with [Substrate](https://substrate.dev/)-based blockchains directly in your browser, eliminating the need for an RPC server. By utilizing the [smoldot](https://github.com/smol-dot/smoldot) WASM light client, it ensures a secure and efficient connection to the blockchain network without reliance on specific third parties.
31
32
32
-
### Overcoming Browser Limitations
33
+
### Write Secure and Effective dApps with the Polkadot Network
33
34
34
-
Browser limitations on websockets from HTTPS pages make establishing a robust number of peers challenging, as many nodes must be available with TLS.
35
-
Substrate Connect addresses this issue through a powerful browser extension, allowing chains to stay synced in the background, thereby significantly enhancing the performance of your applications.
35
+
The aim of this repository is to offer NPM packages that can be used to:
36
36
37
-
### Seamless Integration
37
+
-**Provide a secure and efficient connection to the Polkadot network** via [`@substrate/connect`](./packages/connect/), leveraging the excellent [Smoldot](https://github.com/smol-dot/smoldot) WASM light client.
38
+
-**Discover browser extensions** that implement [the discovery protocol](./packages/discovery/), including those which expose a light client via [`@substrate/smoldot-discovery`](./packages/smoldot-discovery/). Substrate Connect will automatically leverage these where possible.
39
+
-**Easily enhance a browser extension with a light client** via [`@substrate/light-client-extension-helpers`](./packages/light-client-extension-helpers).
38
40
39
-
When building an application with Substrate Connect, it automatically detects whether the user has the extension installed and utilizes it. If not, it seamlessly creates the WASM light client in-page for them. Built on [Polkadot JS](https://polkadot.js.org/docs/api), Substrate Connect ensures that your development experience is as smooth as using a traditional RPC server node.
41
+
We also provide example projects using the above packages, including:
42
+
43
+
-**[Basic light client demo](./projects/demo)**: a demo using `@substrate/connect` to obtain information about chains on the Polkadot network.
44
+
-**[Light client extension demo](./projects/extension/)**: an example of a browser extension that provides a light client.
45
+
-**[Wallet extension demo](./projects/wallet-template/)**: an example of a browser extension that provides a full Polkadot wallet leveraging a light client.
46
+
47
+
### Additional Resources
48
+
49
+
- A [step-by-step guide](./projects/wallet-template/STEP-BY-STEP-GUIDE.md) on how to integrate a light client into a browser extension.
50
+
- Details on [the discovery protocol](./packages/discovery/), including how to implement it on the browser or extension side.
51
+
52
+
### Why Embed a Light Client in Browser Extensions?
53
+
54
+
Embedding a light client in browser extensions offers several advantages:
55
+
56
+
-**Shared Light Client Across Multiple dApps:** By sharing a single light client among various decentralized applications (dApps), the time spent on startup and syncing is reduced. This avoids slowing down individual dApps and enhances overall efficiency.
57
+
-**Overcoming Browser Limitations:** Browser limitations on WebSockets from HTTPS pages make it challenging to establish a robust number of peers, as many nodes must be available with TLS. Substrate Connect addresses this issue through a powerful browser extension, enabling chains to stay synced in the background and significantly improving the performance of your applications. This ensures a more robust connection to the Polkadot ecosystem.
40
58
41
59
## Comprehensive API Documentation
42
60
@@ -45,7 +63,7 @@ For detailed API usage, refer to the [Substrate Connect API documentation](https
45
63
## Repository Structure
46
64
47
65
### [Packages](./packages/README.md)
48
-
The core implementations of `@subtrate/connect` and `@substrate/discovery`, and some auxiliary packages.
66
+
The core implementations of `@subtrate/connect` and `@substrate/discovery`, and some auxiliary packages.
⚠️ WARNING: This interface is currently unstable and is likely to change ⚠️
19
+
</div>
20
+
21
+
<br /><br />
22
+
17
23
A TypeScript package extended from the [`@substrate/discovery`](../discovery/README.md) npm module, that allows to discover and filter Substrate Connect Extension providers from a list of providers.
Copy file name to clipboardexpand all lines: packages/connect/README.md
+10-7
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,11 @@ The main implementation of the light-client provider for a given substrate-based
19
19
20
20
## Using `@substrate/connect` for library authors
21
21
22
-
Provide a well-known chain name ('polkadot', 'ksmcc3', 'westend2', 'rococo_v2_2'):
22
+
The `connect` package will look for a light client provider via the discovery protocol. If it can't find one, it will spawn a smoldot instance in the user's browser tab.
23
+
24
+
### Example Usage
25
+
26
+
To use a well-known chain ('polkadot', 'ksmcc3', 'westend2', 'rococo_v2_2'):
In order to connect to a parachain, you must first instantiate the relay chain
62
-
this parachain is connected to, then instantiate the parachain on the same
63
-
relay chain. The following example connects to a parachain of the Westend test
64
-
network:
65
+
### Connecting to a Parachain
66
+
67
+
To connect to a parachain, you must first instantiate the relay chain this parachain is connected to, and then instantiate the parachain on the same relay chain. The following example connects to a parachain of the Westend test network:
Copy file name to clipboardexpand all lines: packages/discovery/README.md
+9-4
Original file line number
Diff line number
Diff line change
@@ -22,12 +22,15 @@ The main export is a function called `getProviders`. This function dispatches an
22
22
23
23
## How It Works
24
24
25
-
The extension injects an inpage script that:
25
+
The discovery protocol is quite simple and can be implemented in these steps:
26
26
27
-
- Registers a listener for the `substrateDiscovery:requestProvider` event and announces the provider by invoking synchronously the `onProvider` callback from the event payload.
28
-
- Optionally, dispatches the `substrateDiscovery:announceProvider` event with the provider details when the script is loaded.
27
+
1. The extension injects an inpage script that registers a listener for the `substrateDiscovery:requestProvider` event.
28
+
2. The listener announces the provider by invoking the `onProvider` callback from the event payload synchronously.
29
+
3. Optionally, the script can dispatch the `substrateDiscovery:announceProvider` event with the provider details when the script is loaded.
29
30
30
-
## Basic Example
31
+
Refer to `src/index.ts` in this package for an implementation of this protocol.
This example demonstrates how to filter providers based on a specific rDNS value. This approach is useful when you need to target specific extensions rather than all extensions matching a certain interface.
Copy file name to clipboardexpand all lines: packages/smoldot-discovery/README.md
+3-1
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,9 @@
14
14
15
15
<br /><br />
16
16
17
-
A TypeScript package extended from the [`@substrate/discovery`](../discovery/README.md) NPM package, that allows to discover and filter Smoldot extension providers from a list of providers.
17
+
A TypeScript package extended from the [`@substrate/discovery`](../discovery/README.md) NPM package, which enables the discovery and filtering of Smoldot extension providers from a list of providers.
18
+
19
+
To be utilized by dApps, extensions should implement the `SmoldotExtensionProviderDetail` interface. This can be achieved by following the extension side of the discovery protocol as detailed [here](../discovery/README.md), and then returning the implemented interface.
0 commit comments