Skip to content

Commit 363b728

Browse files
bgravenorstalexandratranshahbaz17
authored
Separate concepts and add context (#2808)
* Seperate concepts and add context. Signed-off-by: bgravenorst <byron.gravenorst@consensys.net> * Update metamask-connect/multichain/concepts/sessions.md * fix typo * add note about session IDs --------- Signed-off-by: bgravenorst <byron.gravenorst@consensys.net> Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com> Co-authored-by: Alexandra Carrillo <alexandra.carrillo@consensys.net> Co-authored-by: Mohammad Shahbaz Alam <shahbaz17@users.noreply.github.com>
1 parent 864422d commit 363b728

9 files changed

Lines changed: 120 additions & 65 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
sidebar_label: Account IDs
3+
description: Learn how CAIP-10 account IDs work in MetaMask Connect Multichain to uniquely identify accounts across chains.
4+
keywords: [multichain, caip, caip-10, account ID, chain address, eip155, solana account, cross-chain identity]
5+
---
6+
7+
# Account IDs (CAIP-10)
8+
9+
A plain address like `0xab16...` does not identify which chain it belongs to. The same address can
10+
exist on Ethereum, Polygon, and other EVM chains. In a multichain context, you need to know which
11+
account on which chain the user authorized.
12+
13+
Account IDs solve this by combining a [scope](./scopes.md) with an address. After a user connects, the
14+
[session](./sessions.md) returns account IDs, so you know which chain each address belongs to.
15+
16+
## Format and examples
17+
18+
An account ID uses `namespace:reference:address` format, as defined by
19+
[CAIP-10](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md).
20+
21+
| Ecosystem | Example |
22+
| --------- | ------------------------------------------------- |
23+
| EVM | `eip155:1:0xab16a96D359eC26a11e2C2b3d8f8B8942d5Bfcdb` |
24+
| Solana | `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv` |
25+
26+
Account IDs appear in the [`sessionScopes`](./sessions.md) returned by
27+
[`getSession`](../reference/methods.md#getsession). To extract the address from a CAIP-10
28+
account ID:
29+
30+
```javascript
31+
const accountId = 'eip155:1:0xab16a96D359eC26a11e2C2b3d8f8B8942d5Bfcdb'
32+
const address = accountId.split(':')[2]
33+
```
34+
35+
## Next steps
36+
37+
- [Scopes](./scopes.md): Understand CAIP-2 chain identifiers used in account IDs.
38+
- [Sessions](./sessions.md): Learn how accounts are grouped into authorized sessions.
Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,59 @@
11
---
2-
title: "Multichain Scopes and Sessions - MetaMask Connect"
2+
title: "Multichain Scopes - MetaMask Connect"
33
sidebar_label: Scopes
4-
description: Learn how CAIP-2 scopes, CAIP-10 account IDs, and CAIP-25 sessions work in MetaMask Connect Multichain to identify chains and accounts.
5-
keywords: [multichain, caip, scope, caip-2, caip-10, caip-25, session, chain id, chain namespace, account ID format, blockchain identifier, eip155, solana scope]
4+
description: Learn how CAIP-2 scopes work in MetaMask Connect Multichain to identify chains across ecosystems.
5+
keywords: [multichain, caip, scope, caip-2, chain id, chain namespace, blockchain identifier, eip155, solana scope]
66
---
77

8-
# Scopes, accounts, and sessions
8+
# Scopes (CAIP-2)
99

10-
MetaMask Connect Multichain uses three CAIP standards:
10+
MetaMask Connect Multichain uses CAIP standards to identify chains, [accounts](./accounts.md),
11+
and [sessions](./sessions.md).
1112

12-
- **CAIP-2 scopes** (for example, `eip155:1` for Ethereum Mainnet or `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` for Solana Mainnet) to identify chains.
13-
- **CAIP-10 account IDs** to identify accounts across chains.
14-
- **CAIP-25 sessions** to group authorized scopes and accounts into a single connection.
13+
Traditional single-chain dapps identify networks with a numeric chain ID (for example, `1` for
14+
Ethereum Mainnet). That works within EVM ecosystems, but it does not generalize across ecosystems.
15+
Solana does not use numeric chain IDs, and a raw value like `1` is ambiguous without an ecosystem
16+
context.
1517

16-
Understanding these concepts helps you work with the multichain client.
18+
Scopes solve this by providing a **universal chain identifier** for a chain or set of chains.
19+
When you [`connect`](../reference/methods.md#connect) to MetaMask, you pass an array of scopes to
20+
declare exactly which chains your dapp needs. When you call
21+
[`invokeMethod`](../reference/methods.md#invokemethod), you pass a scope to target the correct chain
22+
without switching netwoks.
1723

18-
## Scopes (CAIP-2)
24+
## Format and examples
1925

2026
A scope is a chain identifier in `namespace:reference` format, as defined by
21-
[CAIP-2](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md). It uniquely identifies
22-
a blockchain across any ecosystem.
27+
[CAIP-2](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md). It identifies
28+
a specific blockchain across any ecosystem.
2329

2430
- The **namespace** identifies the ecosystem or standard (for example, `eip155` for EVM, `solana`
2531
for Solana).
2632
- The **reference** identifies a specific chain within that namespace.
2733

28-
You use scopes when connecting and when calling
29-
[`invokeMethod`](../reference/methods.md#invokemethod) to target a specific chain.
34+
```javascript
35+
// Connect to Ethereum, Polygon, and Solana in a single call
36+
await client.connect([
37+
'eip155:1', // Ethereum Mainnet
38+
'eip155:137', // Polygon Mainnet
39+
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' // Solana Mainnet
40+
], [])
41+
42+
// Send an RPC request to a specific chain using its scope
43+
const balance = await client.invokeMethod({
44+
scope: 'eip155:1',
45+
request: { method: 'eth_getBalance', params: ['0xab1...', 'latest'] }
46+
})
47+
```
3048

31-
### Supported scopes
49+
## Supported scopes
3250

3351
| Ecosystem | Format | Examples |
3452
| --------- | ---------------------- | ---------------------------------------------------------------------------- |
3553
| EVM | `eip155:<chainId>` | `eip155:1` (Ethereum), `eip155:59144` (Linea), `eip155:137` (Polygon) |
3654
| Solana | `solana:<genesisHash>` | `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` (Mainnet), `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1` (Devnet) |
3755

38-
### Common EVM scopes
56+
## Common EVM scopes
3957

4058
| Network | Scope |
4159
| ---------------- | ---------------- |
@@ -47,46 +65,7 @@ You use scopes when connecting and when calling
4765
| Optimism | `eip155:10` |
4866
| Sepolia testnet | `eip155:11155111`|
4967

50-
## Account IDs (CAIP-10)
51-
52-
An account ID extends a scope with an address, in `namespace:reference:address` format, as defined
53-
by [CAIP-10](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md). It uniquely
54-
identifies an account on a specific chain.
55-
56-
| Ecosystem | Example |
57-
| --------- | ------------------------------------------------- |
58-
| EVM | `eip155:1:0xab16a96D359eC26a11e2C2b3d8f8B8942d5Bfcdb` |
59-
| Solana | `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv` |
60-
61-
To extract the address from a CAIP-10 account ID:
62-
63-
```javascript
64-
const accountId = 'eip155:1:0xab16a96D359eC26a11e2C2b3d8f8B8942d5Bfcdb'
65-
const address = accountId.split(':')[2]
66-
```
67-
68-
## Sessions (CAIP-25)
69-
70-
A session is an authorized connection between your dapp and MetaMask that spans multiple scopes, as
71-
defined by [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md). When a user
72-
approves a connection, MetaMask creates a session containing the approved scopes and accounts.
73-
74-
A session includes:
75-
76-
- **`sessionScopes`**: The chains the user approved, each with its associated accounts.
77-
- **Persistence**: Sessions survive page reloads and new tabs.
78-
- **Lifecycle methods**: Use [`getSession`](../reference/methods.md#getsession) to retrieve session
79-
data and [`disconnect`](../reference/methods.md#disconnect) to end or modify the session.
80-
81-
```javascript
82-
const session = await client.provider.getSession()
83-
84-
const ethAccounts = session.sessionScopes['eip155:1']?.accounts || []
85-
const solAccounts = session.sessionScopes['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp']?.accounts || []
86-
```
87-
8868
## Next steps
8969

90-
- [Quickstart](../quickstart/javascript.md): Set up MetaMask Connect Multichain.
91-
- [Send transactions](../guides/send-transactions.md): Send transactions on EVM and Solana.
92-
- [API reference](../reference/api.md): Full Multichain API reference.
70+
- [Accounts](./accounts.md): Learn how CAIP-10 account IDs extend scopes with addresses.
71+
- [Sessions](./sessions.md): Learn how scopes and accounts are grouped into authorized connections.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
sidebar_label: Sessions
3+
description: Learn how CAIP-25 sessions work in MetaMask Connect Multichain to group authorized scopes and accounts into a single connection.
4+
keywords: [multichain, caip, caip-25, session, sessionScopes, connection, persistence, disconnect, getSession]
5+
---
6+
7+
# Sessions (CAIP-25)
8+
9+
A session is an authorized connection between your dapp and MetaMask that can span multiple blockchain ecosystems and chains, as defined in
10+
[CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md).
11+
When a user approves a connection, MetaMask creates a session including the approved [scopes](./scopes.md) and [accounts](./accounts.md).
12+
13+
MetaMask Connect Multichain provides the method [`getSession`](../reference/methods.md#getsession) to get information about the current session,
14+
and the method [`disconnect`](../reference/methods.md#disconnect) to end or update the session.
15+
For more information about the session lifecycle, see [CAIP-316](https://standards.chainagnostic.org/CAIPs/caip-316).
16+
17+
A session is persistent, meaning it survives across page reloads and new tabs.
18+
19+
A session includes `sessionScopes`, which contains the chains the user approved, each with its associated accounts.
20+
The following example extracts the approved Ethereum Mainnet and Solana Mainnet accounts from `sessionScopes`:
21+
22+
```javascript
23+
const session = await client.provider.getSession()
24+
25+
const ethAccounts = session.sessionScopes['eip155:1']?.accounts || []
26+
const solAccounts = session.sessionScopes['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp']?.accounts || []
27+
```
28+
29+
:::note
30+
MetaMask doesn't support session IDs.
31+
:::
32+
33+
## Next steps
34+
35+
- [Scopes](./scopes.md): Understand CAIP-2 chain identifiers used in sessions.
36+
- [Accounts](./accounts.md): Learn how CAIP-10 account IDs identify accounts across chains.

metamask-connect/multichain/quickstart/javascript.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Use [`invokeMethod()`](../reference/methods.md#invokemethod) to call RPC methods
164164
| Method | Description |
165165
| -------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
166166
| [`connect(scopes, caipAccountIds)`](../reference/methods.md#connect) | Connects to MetaMask with multichain [scopes](../concepts/scopes.md) |
167-
| [`getSession()`](../reference/methods.md#getsession) | Returns the current [session](../concepts/scopes.md#sessions-caip-25) with approved accounts |
167+
| [`getSession()`](../reference/methods.md#getsession) | Returns the current [session](../concepts/sessions.md) with approved accounts |
168168
| [`invokeMethod({ scope, request })`](../reference/methods.md#invokemethod) | Calls an RPC method on a specific chain using a [scope](../concepts/scopes.md) |
169169
| [`disconnect()`](../reference/methods.md#disconnect) | Disconnects all [scopes](../concepts/scopes.md) and ends the session |
170170
| [`disconnect(scopes)`](../reference/methods.md#disconnect) | Disconnects specific [scopes](../concepts/scopes.md) without ending the session |
@@ -174,7 +174,7 @@ Use [`invokeMethod()`](../reference/methods.md#invokemethod) to call RPC methods
174174
175175
## Next steps
176176
177-
- See [Scopes, accounts, and sessions](../concepts/scopes.md) to understand CAIP-2 chain identifiers and CAIP-25 sessions.
177+
- Understand [scopes](../concepts/scopes.md), [accounts](../concepts/accounts.md), and [sessions](../concepts/sessions.md) for CAIP-2 chain identifiers, CAIP-10 account IDs, and CAIP-25 sessions.
178178
- [Send transactions on EVM and Solana](../guides/send-transactions.md) from a single multichain session.
179179
- [Sign messages on EVM and Solana](../guides/sign-transactions.md) using `invokeMethod`.
180180
- See [Create a multichain dapp](../tutorials/create-multichain-dapp.md) for a full step-by-step tutorial with React.

metamask-connect/multichain/quickstart/nodejs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ client.on('wallet_sessionChanged', session => {
179179
| Method | Description |
180180
| -------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
181181
| [`connect(scopes, caipAccountIds)`](../reference/methods.md#connect) | Connects to MetaMask with multichain [scopes](../concepts/scopes.md). |
182-
| [`getSession()`](../reference/methods.md#getsession) | Returns the current [session](../concepts/scopes.md#sessions-caip-25) with approved accounts. |
182+
| [`getSession()`](../reference/methods.md#getsession) | Returns the current [session](../concepts/sessions.md) with approved accounts. |
183183
| [`invokeMethod({ scope, request })`](../reference/methods.md#invokemethod) | Calls an RPC method on a specific chain using a [scope](../concepts/scopes.md). |
184184
| [`disconnect()`](../reference/methods.md#disconnect) | Disconnects all [scopes](../concepts/scopes.md) and ends the session. |
185185
| [`disconnect(scopes)`](../reference/methods.md#disconnect) | Disconnects specific [scopes](../concepts/scopes.md) without ending the session. |
@@ -268,7 +268,7 @@ node index.mjs
268268
269269
## Next steps
270270
271-
- [Understand multichain scopes](../concepts/scopes.md) for CAIP-2 chain identifiers and CAIP-25 sessions.
271+
- Understand [scopes](../concepts/scopes.md), [accounts](../concepts/accounts.md), and [sessions](../concepts/sessions.md) for CAIP-2 chain identifiers, CAIP-10 account IDs, and CAIP-25 sessions.
272272
- [Sign multichain transactions](../guides/sign-transactions.md) using `invokeMethod`.
273273
- [Send multichain transactions](../guides/send-transactions.md) from a single session.
274274
- See [Create a multichain dapp](../tutorials/create-multichain-dapp.md) for a full step-by-step tutorial with React.

metamask-connect/multichain/quickstart/react-native.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ npx expo run:ios
460460

461461
## Next steps
462462

463-
- [Understand multichain scopes.](../concepts/scopes.md)
463+
- Understand [scopes](../concepts/scopes.md), [accounts](../concepts/accounts.md), and [sessions](../concepts/sessions.md).
464464
- [Sign multichain transactions.](../guides/sign-transactions.md)
465465
- [Send multichain transactions.](../guides/send-transactions.md)
466466
- Follow the [Create a multichain dapp tutorial](../tutorials/create-multichain-dapp.md).

metamask-connect/multichain/reference/api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,6 @@ according to [CAIP-217](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/c
423423
## Next steps
424424

425425
- Follow the [JavaScript quickstart](../quickstart/javascript.md) to set up MetaMask Connect Multichain in a dapp.
426-
- See the [MetaMask Connect Multichain methods](methods.md) for the high-level methods that wrap this API.
427-
- See [Scopes, accounts, and sessions](../concepts/scopes.md) to understand CAIP-2, CAIP-10, and CAIP-25 identifiers.
426+
- See the [MetaMask Connect Multichain methods](methods.md) for the client-level methods that wrap this API.
427+
- Understand [scopes](../concepts/scopes.md), [accounts](../concepts/accounts.md), and [sessions](../concepts/sessions.md) for CAIP-2, CAIP-10, and CAIP-25 identifiers.
428428
- See [Send transactions on EVM and Solana](../guides/send-transactions.md) for practical usage examples.

metamask-connect/multichain/tutorials/create-multichain-dapp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Your dapp will handle wallet login and logout, read balances across all four cha
1717

1818
## Key concepts
1919

20-
This tutorial uses [scopes, account IDs, and sessions](../concepts/scopes.md) to identify chains and
20+
This tutorial uses [scopes](../concepts/scopes.md), [account IDs](../concepts/accounts.md), and [sessions](../concepts/sessions.md) to identify chains and
2121
accounts across ecosystems. If you're unfamiliar with these concepts, review them before continuing.
2222

2323
This tutorial uses the following scopes:

mm-connect-sidebar.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ const metamaskConnectSidebar = {
7575
collapsed: false,
7676
items: [
7777
'multichain/concepts/scopes',
78+
'multichain/concepts/accounts',
79+
'multichain/concepts/sessions',
7880
],
7981
},
8082
{

0 commit comments

Comments
 (0)