-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Initial Multichain API docs #1621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
79b421d
3eff634
5d85f55
f1d72dc
3ef9258
d06c36f
45a7748
f984b7d
e72193e
6eee68f
4be0757
66b29ae
f83c96f
ace1a08
e752569
9f3c5ba
290b796
1fec541
118b981
19df454
4574202
0d39c1b
6397c3d
401b459
43424e0
7a6a8e0
35874e5
8b8828e
a4f386a
93a8cc6
cae4eac
0c6712c
8ace53c
10b6666
3b0ff4a
2ec7900
4e8d23d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
--- | ||
description: Learn about the Multichain API. | ||
sidebar_custom_props: | ||
flask_only: true | ||
--- | ||
|
||
# About the Multichain API | ||
Check warning on line 7 in wallet/concepts/multichain-api.md
|
||
|
||
:::flaskOnly | ||
::: | ||
|
||
The Multichain API is a scalable, generalized web3 wallet API that supports simultaneous | ||
interactions across multiple blockchain networks and ecosystems. | ||
When integrated with [MetaMask Snaps](/snaps), it enables developers to interact with both popular | ||
and emerging networks. | ||
Key benefits include: | ||
|
||
- **Elimination of chain switching** - The Multichain API allows dapps to interact with multiple EVM networks without having to request chain switches. | ||
This feature significantly reduces development overhead involved with error handling. | ||
|
||
- **Extensibility** - The Multichain API can be integrated with | ||
[interoperability Snaps](https://snaps.metamask.io/explore/), providing a standards-based interface | ||
to non-EVM networks that can be broadly adopted across ecosystems. | ||
Check warning on line 23 in wallet/concepts/multichain-api.md
|
||
|
||
- **Seamless multichain UX** - The Multichain API offers improvements over EIP-1193 and [wallet-standard](https://github.com/wallet-standard/wallet-standard) interfaces. | ||
It allows dapps to create unified multichain wallet connection flows, trigger transactions across disparate networks, and clearly interpret chain-specific addresses. | ||
|
||
[**Get started using the Multichain API.**](../how-to/manage-networks/use-multichain.md) | ||
|
||
## Technical overview | ||
|
||
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. | ||
See [MIP-5](https://github.com/MetaMask/metamask-improvement-proposals/blob/main/MIPs/mip-5.md) and | ||
[MIP-6](https://github.com/MetaMask/metamask-improvement-proposals/blob/main/MIPs/mip-6.md) for | ||
detailed information about MetaMask's Multichain API implementation. | ||
|
||
The API includes a method [`wallet_createSession`](../reference/multichain-api.md#wallet_createsession) | ||
that dapps can call to create a multichain connection with a wallet, with specified properties and | ||
authorization scopes. | ||
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 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 connection lifecycle. | ||
|
||
```mermaid | ||
%%{ | ||
init: { | ||
'sequence': { | ||
'actorMargin': 100, | ||
'width': 275 | ||
} | ||
} | ||
}%% | ||
|
||
sequenceDiagram | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to show the case where sessionChange is successful? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This diagram was taken from CAIP 316. Would a successful sessionChange case look the same as the failed case, minus the "connection interrupted" / "connection re-established" arrows? |
||
participant Dapp | ||
participant Wallet | ||
participant WalletDataStore as Wallet data store | ||
|
||
opt Create connection | ||
Dapp->>Wallet: wallet_createSession | ||
Wallet->>WalletDataStore: Persist connection data | ||
Wallet-->>Dapp: {"sessionScopes": {...}} | ||
end | ||
|
||
opt Update connection | ||
Dapp->>Wallet: wallet_createSession (update auth) | ||
Wallet->>WalletDataStore: Update connection data | ||
Wallet-->>Dapp: {"sessionScopes": {updatedScopes...}} | ||
end | ||
|
||
opt Connection interrupted with wallet-side modification | ||
Dapp-->>Wallet: Connection interrupted | ||
Wallet->>WalletDataStore: User initiated connection change | ||
Wallet-->>Dapp: wallet_sessionChanged (attempt fails) | ||
Dapp-->>Wallet: Connection re-established | ||
end | ||
|
||
opt Get connection | ||
Dapp->>Wallet: wallet_getSession | ||
Wallet-->>Dapp: {"sessionScopes": {...}} | ||
end | ||
|
||
opt Revoke connection | ||
Dapp->>Wallet: wallet_revokeSession | ||
Wallet->>WalletDataStore: Update connection data | ||
Wallet-->>Dapp: {"result": "true"} | ||
end | ||
``` | ||
|
||
## Backwards compatibility | ||
|
||
When using the Multichain API, your dapp can still interact with the existing | ||
[Ethereum Provider API](wallet-api.md#ethereum-provider-api). | ||
However, the Ethereum Provider API is not optimized for multichain usage, and we recommend | ||
[starting directly with the Multichain API](../how-to/manage-networks/use-multichain.md) if possible. | ||
The Multichain API is backwards compatible mainly to support dapps that use third-party libraries | ||
with dependencies on the legacy provider. | ||
|
||
## Get started | ||
|
||
Get started with the Multichain API: | ||
|
||
- Learn how to [use the Multichain API](../how-to/manage-networks/use-multichain.md). | ||
- See the [Multichain API reference](../reference/multichain-api.md) for more details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's flask and beta soon i believe. @vandan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, should we remove the flask label and replace it with a note that the feature is experimental / a beta release?