| title | Multichain API Reference | |||||||
|---|---|---|---|---|---|---|---|---|
| sidebar_label | Multichain API | |||||||
| description | Complete reference for the MetaMask Multichain API (CAIP-25), including wallet_createSession, wallet_invokeMethod, and wallet_revokeSession methods. | |||||||
| keywords |
|
import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem";
The Multichain API is a standard wallet API that supports simultaneous interactions across multiple blockchain networks and ecosystems, as defined in CAIP-25.
:::info SDK methods vs. Multichain API MetaMask Connect Multichain exposes high-level SDK methods that wrap the standard Multichain API. Use those methods if you're building with the multichain client.
The standard Multichain API is client-agnostic, and is not entirely exposed by MetaMask Connect Multichain. Use the standard methods referenced on this page if you're building your own client or need lower-level control. :::
:::note
MetaMask implements an older version of the CAIP-25 Multichain API specification.
:::
Creates a multichain session with a wallet, authorizing that wallet with the specified set of scopes and properties. This method is defined in CAIP-25.
-
optionalScopes:object- (Optional) CAIP-217 authorization scopes the wallet can support for use with this dapp. If scopes are specified, only the following properties are supported:-
references:array- (Optional) A list of references to specific blockchains for the namespace of this scope. This property can only be used if the scope namespace does not already specify the blockchain. For example, use this property for an"eip155"scope, but not an"eip155:10"scope.References are mainly used when there would otherwise be duplicate scopes.
-
methods:array- A list of JSON-RPC methods the wallet must support to be compatible with the dapp. -
notifications:array- A list of JSON-RPC notifications the wallet must support to be compatible with the dapp. -
accounts:array- (Optional) A list of CAIP-10 account IDs valid within this scope. Dapps should include this only if they know which accounts they want the user to permit. When supplied, these accounts are preselected by default in the account selection process. Dapps typically omit this property for the user to select their own accounts.
-
-
sessionProperties:object- (Optional) Properties that the wallet can use to determine if the session is valid. -
requiredScopes:object- (Optional) CAIP-217 authorization scopes the wallet must support to be compatible with the dapp. We don't recommend usingrequiredScopeswith MetaMask. MetaMask treats allrequiredScopesasoptionalScopes.
The scopes and properties of the created session.
{
"id": 1,
"jsonrpc": "2.0",
"method": "wallet_createSession",
"params": {
"optionalScopes": {
"eip155": {
"methods": [
"eth_sendTransaction",
"eth_signTransaction",
"eth_sign",
"eth_subscribe",
"get_balance",
"personal_sign"
],
"notifications": ["eth_subscription"]
},
"eip155:10": {
"methods": ["get_balance"],
"notifications": []
},
"eip155:42161": {
"methods": ["eth_sendTransaction", "eth_signTransaction", "get_balance", "personal_sign"],
"notifications": []
}
}
}
}{
"id": 1,
"jsonrpc": "2.0",
"result": {
"sessionScopes": {
"eip155": {
"references": ["1", "137"],
"methods": [
"eth_sendTransaction",
"eth_signTransaction",
"eth_subscribe",
"get_balance",
"eth_sign",
"personal_sign"
],
"notifications": ["eth_subscription"],
"accounts": [
"eip155:1:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb",
"eip155:137:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb"
]
},
"eip155:10": {
"methods": ["get_balance"],
"notifications": [],
"accounts": []
},
"eip155:42161": {
"methods": ["personal_sign"],
"notifications": [],
"accounts": ["eip155:42161:0x0910e12C68d02B561a34569E1367c9AAb42bd810"]
}
},
"sessionProperties": {
"expiry": "2022-11-30T17:07:31+00:00",
"globalConfig": {
"foo": "bar"
}
}
}
}Gets the scopes and properties within the active session. This method is defined in CAIP-312.
:::note MetaMask doesn't support session IDs. :::
None.
The scopes and properties of the session.
{
"id": 1,
"jsonrpc": "2.0",
"method": "wallet_getSession",
"params": {}
}{
"id": 1,
"jsonrpc": "2.0",
"result": {
"sessionScopes": {
"eip155:1": {
"methods": ["eth_signTransaction"],
"notifications": [],
"accounts": ["eip155:1:0xabc123"]
},
"eip155:137": {
"methods": ["eth_sendTransaction"],
"notifications": [],
"accounts": ["eip155:137:0xdef456"]
},
"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1": {
"methods": ["getBalance", "getAccountInfo", "sendTransaction", "getBlock"],
"notifications": [],
"accounts": [
"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1:4Nd1mS8AUwK3kU3gdiAM6QCvqhA7Do8rKtMXsGyqrJxy"
]
}
}
}
}Invokes the specified JSON-RPC API method on the specified network previously authorized to the dapp within a session. This method is defined in CAIP-27.
:::note MetaMask doesn't support session IDs. :::
scope:string- A CAIP-2 chain ID previously authorized to the dapp within a session.request:object- A request object containing:method:string- The JSON-RPC API method to invoke, previously authorized to the dapp within a session.params:object- The RPC method parameters (can be empty).
The response from the JSON-RPC method call.
{
"id": 1,
"jsonrpc": "2.0",
"method": "wallet_invokeMethod",
"params": {
"scope": "eip155:1",
"request": {
"method": "eth_sendTransaction",
"params": [
{
"to": "0x4B0897b0513FdBeEc7C469D9aF4fA6C0752aBea7",
"from": "0xDeaDbeefdEAdbeefdEadbEEFdeadbeefDEADbEEF",
"gas": "0x76c0",
"value": "0x8ac7230489e80000",
"data": "0x",
"gasPrice": "0x4a817c800"
}
]
}
}
}{
"id": 1,
"jsonrpc": "2.0",
"result": {
"scope": "eip155:1",
"result": {
"method": "eth_sendTransaction",
"result": "0x4e306b5a5a37532e1734503f7d2427a86f2c992fbe471f5be403b9f734e667c8"
}
}
}Revokes the active session. This method is defined in CAIP-285.
:::note MetaMask doesn't support session IDs. :::
None.
true if the revocation was successful.
{
"id": 1,
"jsonrpc": "2.0",
"method": "wallet_revokeSession",
"params": {}
}{
"id": 1,
"jsonrpc": "2.0",
"result": true
}The Multichain API provides the following events that wallets can send to dapps to notify them of changes to a session.
Notifies the dapp of events or state changes related to a specific, previously authorized network. CAIP-319 defines this event.
:::note MetaMask doesn't support session IDs. :::
scope:string- A CAIP-2 chain ID previously authorized to the dapp within a session.notification:object- A notification object containing:method:string- A JSON-RPC API notification method name previously authorized to the dapp within a session.params:object- The RPC notification method parameters.
{
"jsonrpc": "2.0",
"method": "wallet_notify",
"params": {
"scope": "eip155:1",
"notification": {
"method": "eth_subscription",
"params": {
"subscription": "0x12345678",
"result": {
"blockNumber": "0x1234",
"transactionHash": "0x5678",
"logIndex": "0x9abc"
}
}
}
}
}Notifies the dapp of updates to the active session's authorization scopes. CAIP-311 defines this method.
:::note MetaMask doesn't support session IDs. :::
sessionScopes: object - An object containing the full updated authorization scopes, each formatted
according to CAIP-217.
{
"jsonrpc": "2.0",
"method": "wallet_sessionChanged",
"params": {
"sessionScopes": {
"eip155:1": {
"methods": ["eth_signTransaction", "eth_sendTransaction"],
"notifications": [],
"accounts": ["eip155:1:0xabc123"]
},
"eip155:137": {
"methods": ["eth_sendTransaction"],
"notifications": [],
"accounts": ["eip155:137:0xdef456"]
}
}
}
}- Follow the JavaScript quickstart to set up MetaMask Connect Multichain in a dapp.
- See the MetaMask Connect Multichain methods for the client-level methods that wrap this API.
- Understand scopes, accounts, and sessions for CAIP-2, CAIP-10, and CAIP-25 identifiers.
- See Send transactions on EVM and Solana for practical usage examples.