# Substrate Connect Q4 2024 Update

**URL:** https://forum.polkadot.network/t/substrate-connect-q4-2024-update/10527
**Category:** Tech Talk
**Created:** [October 21, 2024, 5:07am UTC](https://forum.polkadot.network/t/substrate-connect-q4-2024-update/10527 "2024-10-21T05:07:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ryan](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@ryan](https://forum.polkadot.network/u/ryan)
#### Post date: [October 21, 2024, 5:07am UTC](https://forum.polkadot.network/t/substrate-connect-q4-2024-update/10527/1 "2024-10-21T05:07:24Z")

</div>

This post introduces the latest additions and updates to [Substrate Connect](https://github.com/paritytech/substrate-connect). For those who are not familiar, Substrate Connect is a web extension that uses [smoldot](https://github.com/smol-dot/smoldot), a light-client provider that synchronizes Substrate-based chains in the background for the user. This ensures that when you visit a dApp, the time to connect to the chain is almost instantaneous.

During the first half of 2024, we’ve added **wallet capabilities** to Substrate Connect. This means you can securely create accounts and sign transactions with them, but instead of using centralized RPCs to submit the transaction, you are using a light client. Substrate Connect is the first of its kind to do so.

In addition, we created a new protocol called `@substrate/discovery` that serves as a common interface for dApps to communicate with light client extensions.

### What You Need To Know:

1. **The Wallet Template** : There is now a new wallet template under the [projects directory in the Substrate Connect repository](https://github.com/paritytech/substrate-connect/tree/main/projects/wallet-template). You can use this template to get a light client wallet up and running quickly. We have extensive documentation here on how you can get it running.

2. **The Discovery Protocol** : The new `@substrate/discovery protocol`; a common interface for dApps to communicate with light client extensions, has been created [here](https://github.com/paritytech/substrate-connect/tree/main/packages/discovery). There are currently two implementations of this protocol: [@substrate/smoldot-discovery](https://github.com/paritytech/substrate-connect/tree/main/packages/smoldot-discovery) and [@substrate/connect-discovery](https://github.com/paritytech/substrate-connect/tree/main/packages/connect-discovery). The former is useful for wallets that just want to expose the smoldot API to dApps, while the latter is internal to Substrate Connect.

3. **Getting Started** : The wallet template contains a [Step By Step Guide](https://github.com/paritytech/substrate-connect/blob/d183f3dfb96fcace81eda15531c2af18f28b9cba/projects/wallet-template/STEP-BY-STEP-GUIDE.md) on how you can add light client functionality to your extension.

### Why do we need a Discovery Protocol?

Prior to the introduction of the discovery protocol, we had the [Connect Extension Protocol](https://github.com/paritytech/substrate-connect/blob/d183f3dfb96fcace81eda15531c2af18f28b9cba/packages/connect-extension-protocol/src/index.ts), which dictates how dApps can connect to Substrate Connect and use it to interface with a smoldot light client.

However, when it comes to real-world usage, you’re going to want to connect your dApp to a wallet provider and not just Substrate Connect. That wallet provider will also be running its own light client instance, so it is paramount that your dApp shares the same light client state as the wallet you are connected to.

Since it’s not possible for multiple browser extensions to implement the Connect Extension Protocol, we decided to come up with the Discovery Protocol. This protocol dictates the interface Wallet Providers need to provide in their _content script_, such that they can be discovered by dApps. It takes inspiration from [EIP-6963: Multi Injected Provider Discovery](https://eips.ethereum.org/EIPS/eip-6963), which is the protocol Ethereum uses for wallet provider discovery.

#### How it works

When a dApp is loaded, the extension’s first priority is to inject an `inpage` script from the content script that is attached to the DOM of the dApp. Inside this inpage script, it adds a window event listener under the namespace `"substrateDiscovery:requestProvider"`. When the listener is invoked, it receives a callback: `onProvider` that accepts a provider instance. The inpage script will execute this callback with all the providers it supports and this will be passed to the caller of the event that triggered the listener.

In this case, the caller is the dApp. All the dApp needs to do upon initialization is invoke the `getProviders` method from the `@substrate/discovery` package. This initiates a [window.dispatchEvent](https://developer.mozilla.org/en-US/docs/Web/Events/Creating_and_triggering_events) with a CustomEvent that has the same namespace: `"substrateDiscovery:requestProvider"`.

By using this protocol, dApps are able to get a list of wallet providers in a synchronous manner. To filter for specific providers, dApps can install provider-specific implementations of the discovery protocol such as [@substrate/smoldot-discovery](https://github.com/paritytech/substrate-connect/tree/main/packages/smoldot-discovery) and [@substrate/connect-discovery](https://github.com/paritytech/substrate-connect/tree/main/packages/connect-discovery). These packages invoke `getProviders` under the hood, but filter the provider-specific variant for you.

### Workflow Comparison: Old vs. New

To better understand the improvements, lets compare the old and new workflows.

#### Old Workflow

Previously, dapps had to rely on `@polkadot/extension-dapp` to inject a global named [`window.injectedWeb3`](https://github.com/polkadot-js/extension/tree/59b3c435dd12dc3827616554986b0f73335b1de0?tab=readme-ov-file#injection-information) to connect to a wallet. This had its limitations because it mandated a single interface wallets could expose that was dictated by Polkadot JS.

#### New Workflow

```auto
+-----------+ +---------------+ +---------------+
| Dapp |<------------- | Inpage Script |<-------------| Extension |
| | add listeners | | add script | Content Script|
| | | | | |
| |-------------->| | | |
| | getProviders | | | |
| | | | | |
| |<--------------| | | |
| | onProvider | | | |
| | | | | |
+-----------+ +---------------+ +---------------+

```

In the new workflow, we allow dapps to request providers that confirm to an agreed upon interface (that is arbitrary based on an agreed upon specificiation). The steps are as follows:

1. **Extension content script** : injects inpage script, it adds a window event listener for provider requests.
2. **Dapp** : invokes the `getProviders` method to _synchronously_ get a list of all available providers.
3. **Inpage Script** : responds to the `getProviders` event and passes the providers back to the dApp in the `onProvider` callback.

For in-depth code examples, [read the docs](https://github.com/paritytech/substrate-connect/tree/main/packages/discovery).

### What’s Next

Substrate Connect is now considered stable and ready for general use. We encoursage wallet providers to try the template so we can solicit feedback on how we can make the template better for integration.

We also plan to present the Substrate Connect Wallet Template at the [Sub0 Reset](https://sub0.gg/) in Bangkok and; I will personally be running a 90 minute workshop where I will light client wallet live using the libraries we’ve have built.

---

<div class="post-metadata">

### Author: ![IkerParity](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.polkadot.network/ikerparity/32/88_2.png) [@IkerParity](https://forum.polkadot.network/u/IkerParity)
#### Post date: [November 1, 2024, 4:11pm UTC](https://forum.polkadot.network/t/substrate-connect-q4-2024-update/10527/2 "2024-11-01T16:11:07Z")

</div>

Giving a gentle bump to this thread and updating it with the time for the Sub0 workshop.

**The “Building Light Client dApps with Substrate Connect” workshop will happen on Sunday 10th Nov at 11.10am local time.**

More info here:

> **[Workshop: Building Light Client dApps with Substrate Connect sub0 reset](https://agenda.sub0.gg/sub0-reset-2024/talk/UQNMA9/)**
>
> In this session, we will demonstrate how to build light client Chrome extension wallets using the Substrate Connect wallet template. You can access the template here: Substrate Connect Wallet Template.
> 
> This approach is crucial for the greater Web3...
