Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
79b421d
Initial Multichain API docs
alexandratran Oct 9, 2024
3eff634
Merge branch 'main' into 1566-multichain
alexandratran Oct 9, 2024
5d85f55
Merge branch 'main' into 1566-multichain
alexandratran Oct 11, 2024
f1d72dc
edit content
alexandratran Oct 11, 2024
3ef9258
Merge branch 'main' into 1566-multichain
alexandratran Oct 11, 2024
d06c36f
fix typo
alexandratran Oct 15, 2024
45a7748
Merge branch 'main' into 1566-multichain
alexandratran Oct 22, 2024
f984b7d
edits
alexandratran Oct 22, 2024
e72193e
Merge branch 'main' into 1566-multichain
alexandratran Oct 22, 2024
6eee68f
Merge branch 'main' into 1566-multichain
joaniekube Oct 28, 2024
4be0757
Merge branch 'main' into 1566-multichain
alexandratran Oct 31, 2024
66b29ae
Merge branch '1566-multichain' of github.com:MetaMask/metamask-docs i…
alexandratran Oct 31, 2024
f83c96f
fixes
alexandratran Oct 31, 2024
ace1a08
Merge branch 'main' into 1566-multichain
alexandratran Nov 8, 2024
e752569
add how-to guide and edits
alexandratran Nov 8, 2024
9f3c5ba
minor fix
alexandratran Nov 12, 2024
290b796
Merge branch 'main' into 1566-multichain
alexandratran Nov 13, 2024
1fec541
Mention multichain tag
alexandratran Nov 13, 2024
118b981
update what's new
alexandratran Nov 13, 2024
19df454
Apply suggestions from code review
alexandratran Nov 25, 2024
4574202
Merge branch 'main' into 1566-multichain
alexandratran Nov 25, 2024
0d39c1b
address reviewer feedback
alexandratran Nov 25, 2024
6397c3d
Apply suggestions from code review
alexandratran Feb 6, 2025
401b459
Merge branch 'main' into 1566-multichain
alexandratran Feb 6, 2025
7a6aec0
feat: add multichain client docs
chakra-guy Feb 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address reviewer feedback
  • Loading branch information
alexandratran committed Nov 25, 2024
commit 0d39c1b495ab49a4a760a32ce7084d265e712342
35 changes: 18 additions & 17 deletions wallet/concepts/multichain-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
flask_only: true
---

# About the Multichain API

Check warning on line 7 in wallet/concepts/multichain-api.md

View workflow job for this annotation

GitHub Actions / Lint / Spelling (.mdx)

[vale] reported by reviewdog 🐶 [Consensys.Headings] 'About the Multichain API' should use sentence-style capitalization. Raw Output: {"message": "[Consensys.Headings] 'About the Multichain API' should use sentence-style capitalization.", "location": {"path": "wallet/concepts/multichain-api.md", "range": {"start": {"line": 7, "column": 3}}}, "severity": "WARNING"}

:::flaskOnly
:::
Expand All @@ -24,7 +24,7 @@
to encourage broader adoption of non-EVM networks.

- **Simplified integrations** - The Multichain API reduces the complexity associated with navigating
different wallet APIs and SDKs, making it easier for dapps to integrate with wallets, discover

Check failure on line 27 in wallet/concepts/multichain-api.md

View workflow job for this annotation

GitHub Actions / Lint / Spelling (.mdx)

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'SDKs'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'SDKs'?", "location": {"path": "wallet/concepts/multichain-api.md", "range": {"start": {"line": 27, "column": 29}}}, "severity": "ERROR"}
capabilities, and negotiate interfaces.

[**Get started using the Multichain API.**](../how-to/manage-networks/use-multichain.md)
Expand All @@ -34,25 +34,26 @@
The Multichain API follows the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md)
standard for dapps to interface with multichain wallets.
The API includes a method [`wallet_createSession`](../reference/multichain-api.md#wallet_createsession)
that dapps can call to create a multichain session with a wallet, with specified properties and
that dapps can call to create a multichain connection with a wallet, with specified properties and
authorization scopes.
Dapps can update the session using the same method `wallet_createSession`.
Dapps can update the connection using the same method `wallet_createSession`.

Dapps can use [`wallet_invokeMethod`](../reference/multichain-api.md#wallet_invokemethod) to
call a subset of the [Wallet JSON-RPC API methods](../reference/json-rpc-methods/index.md) on
a specified chain.
Dapps can use [`wallet_getSession`](../reference/multichain-api.md#wallet_getsession) to get
the scopes and properties of the active session, and use
[`wallet_revokeSession`](../reference/multichain-api.md#wallet_revokesession) to revoke the session.
The API also supports the [`wallet_notify`](../reference/multichain-api.md#wallet_notify) and
[`wallet_sessionChanged`](../reference/multichain-api.md#wallet_sessionchanged) events,
allowing wallets to notify dapps of changes to the session.
the scopes and properties of the active connection, and use
[`wallet_revokeSession`](../reference/multichain-api.md#wallet_revokesession) to revoke the connection.
The API also supports the following events:

- [`wallet_notify`](../reference/multichain-api.md#wallet_notify) notifies dapps of onchain events or state changes they previously subscribed to.
- [`wallet_sessionChanged`](../reference/multichain-api.md#wallet_sessionchanged) notifies dapps of changes to the multichain connection.

See the [Multichain API reference](../reference/multichain-api.md) for full details.

### Lifecycle diagram

The following sequence diagram illustrates the multichain session lifecycle.
The following sequence diagram illustrates the multichain connection lifecycle.

```mermaid
%%{
Expand All @@ -69,33 +70,33 @@
participant Wallet
participant WalletDataStore as Wallet data store

opt Create session
opt Create connection
Dapp->>Wallet: wallet_createSession
Wallet->>WalletDataStore: Persist session data
Wallet->>WalletDataStore: Persist connection data
Wallet-->>Dapp: {"sessionScopes": {...}}
end

opt Update session
opt Update connection
Dapp->>Wallet: wallet_createSession (update auth)
Wallet->>WalletDataStore: Update session data
Wallet->>WalletDataStore: Update connection data
Wallet-->>Dapp: {"sessionScopes": {updatedScopes...}}
end

opt Connection interrupted with wallet-side session modification
opt Connection interrupted with wallet-side modification
Dapp-->>Wallet: Connection interrupted
Wallet->>WalletDataStore: User initiated session change
Wallet->>WalletDataStore: User initiated connection change
Wallet-->>Dapp: wallet_sessionChanged (attempt fails)
Dapp-->>Wallet: Connection re-established
end

opt Get session
opt Get connection
Dapp->>Wallet: wallet_getSession
Wallet-->>Dapp: {"sessionScopes": {...}}
end

opt Revoke session
opt Revoke connection
Dapp->>Wallet: wallet_revokeSession
Wallet->>WalletDataStore: Update session data
Wallet->>WalletDataStore: Update connection data
Wallet-->>Dapp: {"result": "true"}
end
```
Expand Down
25 changes: 12 additions & 13 deletions wallet/how-to/manage-networks/use-multichain.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ extensionPort.onMessage.addListener((msg) => {
})
```


### 2. Manage sessions
### 2. Manage multichain connections

To interact with multiple networks simultaneously, you'll create and manage
[CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) multichain sessions
[CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) multichain connections
with MetaMask.

#### 2.1. Check existing sessions
#### 2.1. Check existing connections

Before creating a new session, check if one already exists using the
Before creating a new connection, check if one already exists using the
[`wallet_getSession`](../../reference/multichain-api.md#wallet_getsession) method.
For example:

Expand All @@ -75,12 +74,12 @@ extensionPort.postMessage({
});
```

If the result returns an empty `sessionScopes` parameter, then a multichain session is not active
and you must create a new session.
If the result returns an empty `sessionScopes` parameter, then a multichain connection is not active
and you must create a new connection.

#### 2.2. Create a new session
#### 2.2. Create a new connection

Create a new session using the [`wallet_createSession`](../../reference/multichain-api.md#wallet_createsession) method.
Create a new connection using the [`wallet_createSession`](../../reference/multichain-api.md#wallet_createsession) method.
Specify which chains and methods your dapp needs access to, using the `optionalScopes` parameter.
For example:

Expand Down Expand Up @@ -137,12 +136,12 @@ In `optionalScopes`:
- For each network, request access to [Wallet API methods](../../reference/json-rpc-methods/index.md)
that your dapp expects to call at any time.
The methods listed in the `sessionScope` of each Multichain API response indicate which wallet
capabilities your dapp can use during the session.
capabilities your dapp can use during the connection.

#### 2.3. Check for session changes
#### 2.3. Check for connection changes

To ensure your dapp responds appropriately to changes in the wallet session, such as network or
account updates, check for session changes using the
To ensure your dapp responds appropriately to changes in the multichain connection, such as network or
account updates, check for connection changes using the
[`wallet_sessionChanged`](../../reference/multichain-api.md#wallet_sessionchanged) event.
Based on the event data, you can determine whether your dapp needs to request additional permissions
using [`wallet_createSession`](../../reference/multichain-api.md#wallet_createsession).
Expand Down
31 changes: 15 additions & 16 deletions wallet/reference/multichain-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import TabItem from "@theme/TabItem";
:::

Dapps can call Multichain API [methods](#methods) to create and manage
[CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) sessions with MetaMask.
The API also provides [events](#events) that wallets can send to dapps to notify them of changes to
a session.
[CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) connections with MetaMask.
The API also provides [events](#events) that wallets can send to dapps to notify them of onchain or connection changes.

:::note See also
- [About the Multichain API](../concepts/multichain-api.md)
Expand All @@ -26,21 +25,21 @@ a session.

### `wallet_createSession`

Creates a multichain session with a wallet, authorizing that wallet with the specified set of scopes
Creates a multichain connection with a wallet, authorizing that wallet with the specified set of scopes
and properties.
This method is defined in [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md).

#### Parameters

- `optionalScopes`: `object` - Scopes that the wallet can support in order to be used with this dapp.
- `sessionProperties`: `object` - Properties that the wallet can use to determine if the session is valid.
- `sessionProperties`: `object` - Properties that the wallet can use to determine if the connection is valid.
- `requiredScopes`: `object` - (Optional) Scopes that the wallet must support in order to be used
with this dapp.
We don't recommend using `requiredScopes` with MetaMask.

#### Returns

The scopes and properties of the created session.
The scopes and properties of the created connection.

#### Example

Expand Down Expand Up @@ -126,7 +125,7 @@ The scopes and properties of the created session.

### `wallet_getSession`

Gets the scopes and properties within the active session.
Gets the scopes and properties within the active connection.
This method is defined in [CAIP-312](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-312.md).

:::note
Expand All @@ -139,7 +138,7 @@ None.

#### Returns

The scopes and properties of the session.
The scopes and properties of the connection.

#### Example

Expand Down Expand Up @@ -190,7 +189,7 @@ The scopes and properties of the session.
### `wallet_invokeMethod`

Invokes the specified [JSON-RPC API](json-rpc-methods/index.md) method on the specified network
previously authorized to the dapp within a session.
previously authorized to the dapp within a connection.
This method is defined in [CAIP-27](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-27.md).

:::note
Expand All @@ -200,10 +199,10 @@ MetaMask doesn't support session IDs.
#### Parameters

- `scope`: `string` - A [CAIP-2](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md)
chain ID previously authorized to the dapp within a session.
chain ID previously authorized to the dapp within a connection.
- `request`: `object` - A request object containing:
- `method`: `string` - The [JSON-RPC API](json-rpc-methods/index.md) method to invoke,
previously authorized to the dapp within a session.
previously authorized to the dapp within a connection.
- `params`: `object` - The RPC method parameters (can be empty).

#### Returns
Expand Down Expand Up @@ -261,7 +260,7 @@ The response from the JSON-RPC method call.

### `wallet_revokeSession`

Revokes the active session.
Revokes the active connection.
This method is defined in [CAIP-285](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-285.md).

:::note
Expand Down Expand Up @@ -321,10 +320,10 @@ MetaMask doesn't support session IDs.
#### Parameters

- `scope`: `string` - A [CAIP-2](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md)
chain ID previously authorized to the dapp within a session.
chain ID previously authorized to the dapp within a connection.
- `notification`: `object` - A notification object containing:
- `method`: `string` - A [JSON-RPC API](json-rpc-methods/index.md) notification method name
previously authorized to the dapp within a session.
previously authorized to the dapp within a connection.
- `params`: `object` - The RPC notification method parameters.

#### Example
Expand Down Expand Up @@ -352,7 +351,7 @@ MetaMask doesn't support session IDs.

### `wallet_sessionChanged`

Notifies the dapp of updates to the active session's authorization scopes.
Notifies the dapp of updates to the active connection's authorization scopes.
This method is defined in [CAIP-311](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-311.md).

:::note
Expand All @@ -361,7 +360,7 @@ MetaMask doesn't support session IDs.

#### Parameters

`sessionScopes`: `object` - An object containing the full updated session scopes, each formatted
`sessionScopes`: `object` - An object containing the full updated authorization scopes, each formatted
according to [CAIP-217](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-217.md).

#### Example
Expand Down
Loading