diff --git a/docs/whats-new.md b/docs/whats-new.md index efc0d328607..166516cfa58 100644 --- a/docs/whats-new.md +++ b/docs/whats-new.md @@ -9,8 +9,11 @@ The latest major MetaMask documentation updates are listed by the month they wer For a comprehensive list of recent product changes, visit the "Release Notes" section at the bottom of the [MetaMask developer page](https://metamask.io/developer/). -## February +## February 2025 +- Documented Multichain API [guide](/wallet/how-to/manage-networks/use-multichain), + [concept](/wallet/concepts/multichain-api), and [reference](/wallet/reference/multichain-api). + ([#1621](https://github.com/MetaMask/metamask-docs/pull/1621)) - Documented [Unichain Mainnet](/services/reference/unichain) support.([#1878](https://github.com/MetaMask/metamask-docs/pull/1878)) ## January 2025 diff --git a/docusaurus.config.js b/docusaurus.config.js index 9a12d585aef..930ac8a4177 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -137,6 +137,20 @@ const config = { editUrl: "https://github.com/MetaMask/metamask-docs/edit/main/", sidebarPath: require.resolve("./wallet-sidebar.js"), breadcrumbs: false, + admonitions: { + keywords: [ + "info", + "success", + "danger", + "note", + "tip", + "warning", + "important", + "caution", + "security", + "flaskOnly", + ], + }, sidebarItemsGenerator: async function ({ defaultSidebarItemsGenerator, ...args }) { const sidebarItems = await defaultSidebarItemsGenerator(args); const dynamicItems = await fetchAndGenerateDynamicSidebarItems( diff --git a/snaps/get-started/install-flask.md b/snaps/get-started/install-flask.md index 5493aa5639b..7bde83c05ab 100644 --- a/snaps/get-started/install-flask.md +++ b/snaps/get-started/install-flask.md @@ -5,10 +5,9 @@ sidebar_position: 1 # Install MetaMask Flask -To get started building your own Snaps, install the MetaMask Flask browser extension on -[Google Chrome](https://chromewebstore.google.com/detail/metamask-flask-developmen/ljfoeinjpaedjfecbmggjgodbgkmjkjk) -or -[Mozilla Firefox](https://addons.mozilla.org/en-US/firefox/addon/metamask-flask/). +To build your own Snaps or test upcoming MetaMask features, install the MetaMask Flask browser +extension on [Google Chrome](https://chromewebstore.google.com/detail/metamask-flask-developmen/ljfoeinjpaedjfecbmggjgodbgkmjkjk) +or [Mozilla Firefox](https://addons.mozilla.org/en-US/firefox/addon/metamask-flask/). Install Flask in a new browser profile, or disable any existing installed versions of MetaMask before installing Flask. @@ -27,8 +26,10 @@ If you import accounts with funds into Flask, you do so at your own risk. ## About MetaMask Flask MetaMask Flask is an experimental playground that provides developers access to upcoming MetaMask features. -While a small set of audited Snaps are allowlisted in the stable version of the MetaMask browser extension, MetaMask Flask is intended for developers building and testing Snaps locally or from npm. -Also, new Snaps API features are enabled in Flask for testing and developer feedback before they're enabled in MetaMask stable. +While a small set of audited Snaps are allowlisted in the stable version of the MetaMask browser +extension, MetaMask Flask is intended for developers building and testing Snaps locally or from npm. +Also, new MetaMask features are enabled in Flask for testing and developer feedback before they're +enabled in MetaMask stable. These features appear in the documentation with the **Flask** or **FLASK ONLY** tag. You can also view Flask-specific features by looking for the **\[FLASK\]** label in the [MetaMask Extension changelog](https://github.com/MetaMask/metamask-extension/blob/develop/CHANGELOG.md). diff --git a/wallet-sidebar.js b/wallet-sidebar.js index 8ba6e7763e3..2fec476498b 100644 --- a/wallet-sidebar.js +++ b/wallet-sidebar.js @@ -41,6 +41,11 @@ const sidebar = { type: "doc", label: "Add a network", id: "how-to/manage-networks/add-network" + }, + { + type: "doc", + label: "Interact with multiple networks", + id: "how-to/manage-networks/use-multichain" } ] }, @@ -177,6 +182,11 @@ const sidebar = { label: "About the Wallet API", id: "concepts/wallet-api" }, + { + type: "doc", + label: "About the Multichain API", + id: "concepts/multichain-api" + }, { type: "doc", label: "Convenience libraries", @@ -253,6 +263,11 @@ const sidebar = { label: "Ethereum provider API", id: "reference/provider-api", }, + { + type: "doc", + label: "Multichain API", + id: "reference/multichain-api", + }, { type: "category", label: "JSON-RPC API", diff --git a/wallet/concepts/multichain-api.md b/wallet/concepts/multichain-api.md new file mode 100644 index 00000000000..ebd631c7c03 --- /dev/null +++ b/wallet/concepts/multichain-api.md @@ -0,0 +1,116 @@ +--- +description: Learn about the Multichain API. +sidebar_custom_props: + flask_only: true +--- + +# About the Multichain API + +:::flaskOnly +::: + +The Multichain API is a scalable, generalized web3 wallet API that supports simultaneous +interactions across multiple blockchain networks. +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. + +- **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. +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 + 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. diff --git a/wallet/how-to/manage-networks/use-multichain.md b/wallet/how-to/manage-networks/use-multichain.md new file mode 100644 index 00000000000..48ac9d277b1 --- /dev/null +++ b/wallet/how-to/manage-networks/use-multichain.md @@ -0,0 +1,245 @@ +--- +description: Use the Multichain API. +toc_max_heading_level: 4 +sidebar_custom_props: + flask_only: true +--- + +# Interact with multiple networks + +:::flaskOnly +::: + +You can use the Multichain API to interact with multiple blockchain networks in MetaMask simultaneously. +The API allows you to target specific chains as part of each method call, eliminating the need to +detect and switch networks before executing signatures and transactions. + +:::note See also +- [About the Multichain API](../../concepts/multichain-api.md) +- [Multichain API reference](../../reference/multichain-api.md) +::: + +## Prerequisites + +[Install MetaMask Flask.](/snaps/get-started/install-flask) + +## Steps + +### 1. Set up your project + +Establish a connection to MetaMask Flask and set up basic message handling using the +[`wallet_notify`](../../reference/multichain-api.md#wallet_notify) event: + +```javascript +// Initialize the connection to Flask. +const EXTENSION_ID = "ljfoeinjpaedjfecbmggjgodbgkmjkjk"; // Flask extension ID +const extensionPort = chrome.runtime.connect(EXTENSION_ID) + +// Set up message listener for events. +extensionPort.onMessage.addListener((msg) => { + // Format wallet_notify events to be able to read them later. + if (msg.data.method === "wallet_notify") { + console.log("wallet_notify:", { + scope: msg.data.params.scope, + method: msg.data.params.notification.method, + subscription: msg.data.params.notification.params.subscription, + number: msg.data.params.notification.params.result.number + }) + return; + } + console.log(msg.data) +}) +``` + +### 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 connections +with MetaMask. + +#### 2.1. Check existing connections + +Before creating a new connection, check if one already exists using the +[`wallet_getSession`](../../reference/multichain-api.md#wallet_getsession) method. +For example: + +```javascript +extensionPort.postMessage({ + type: "caip-x", + data: { + jsonrpc: "2.0", + method: "wallet_getSession", + params: {} + } +}); +``` + +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 connection + +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: + +```javascript +extensionPort.postMessage({ + type: "caip-x", + data: { + jsonrpc: "2.0", + method: "wallet_createSession", + params: { + optionalScopes: { + "wallet:eip155": { // General Ethereum wallet functions + methods: ["wallet_addEthereumChain"], + notifications: [], + accounts: [] + }, + "eip155:1": { // Ethereum Mainnet + methods: [ + "personal_sign", + "eth_blockNumber", + "eth_gasPrice", + "eth_getBalance", + "eth_getTransactionCount", + "eth_sendTransaction", + "eth_subscribe" + ], + notifications: ["eth_subscription"], + accounts: [] + }, + "eip155:59141": { // Linea Sepolia + methods: [ + "personal_sign", + "eth_blockNumber", + "eth_gasPrice", + "eth_getBalance", + "eth_getTransactionCount", + "eth_sendTransaction", + "eth_subscribe" + ], + notifications: ["eth_subscription"], + accounts: [] + } + } + } + } +}); +``` + +In `optionalScopes`: + +- Request access to networks that your dapp intends to interact with. + If a requested network is not configured by the MetaMask user, you might need to + [add the network](add-network.md). +- 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 connection. + +#### 2.3. Check for connection changes + +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). + +```javascript +extensionPort.onMessage.addListener((msg) => { + // Check for wallet_sessionChanged events. + if (msg.data.method === "wallet_sessionChanged") { + // Update permissions if required. + } +}); +``` + +### 3. Invoke Wallet API methods + +You can invoke a subset of the [Wallet JSON-RPC API methods](../../reference/json-rpc-methods/index.md) +on a specified chain using the [`wallet_invokeMethod`](../../reference/multichain-api.md#wallet_invokemethod) +Multichain API method. +The following are example Wallet API functionalities that are compatible with the Multichain API. + +#### 3.1. Sign in with Ethereum + +You can implement Sign-In with Ethereum (SIWE) by invoking +[`personal_sign`](/wallet/reference/json-rpc-methods/personal_sign). +For example: + +```javascript +// Specify an account that the signature will be requested for. +const address = "0xAddress"; +const message = `Sign-in request for ${address} at ${new Date().toLocaleString()}`; + +// Invoke the personal_sign Wallet API method. +const sign = await extensionPort.postMessage({ + type: "caip-x", + data: { + "jsonrpc": "2.0", + method: "wallet_invokeMethod", + params: { + scope: "eip155:1", + request: { + method: "personal_sign", + params: [message, address], + } + } + } +}) +``` + +#### 3.2. Check balances + +You can read gas token balances by invoking +[`eth_getBalance`](/wallet/reference/json-rpc-methods/personal_sign). +For example: + +```javascript +extensionPort.postMessage({ + type: "caip-x", + data: { + jsonrpc: "2.0", + method: "wallet_invokeMethod", + params: { + scope: "eip155:1", + request: { + method: "eth_getBalance", + params: ["0xAddress", "latest"], + } + } + } +}); +``` + +#### 3.3. Send transactions + +You can send transactions on a specific network, by invoking +[`eth_sendTransaction`](/wallet/reference/json-rpc-methods/eth_sendtransaction). +For example: + +```javascript +return extensionPort.postMessage({ + type: "caip-x", + data: { + jsonrpc: "2.0", + method: "wallet_invokeMethod", + params: { + // Specify a chain ID where the user has sufficient gas. + scope: "eip155:1", + request: { + method: "eth_sendTransaction", + params: [{ + from: "0xFromAccount", + to: "0xToAccount", + value: "0x0", + gasLimit: "0x5028", + maxPriorityFeePerGas: "0x3b9aca00", + maxFeePerGas: "0x2540be400", + }] + } + } + } +}); +``` diff --git a/wallet/reference/json-rpc-methods/index.md b/wallet/reference/json-rpc-methods/index.md index 076a64bd3f8..70b4bb0c088 100644 --- a/wallet/reference/json-rpc-methods/index.md +++ b/wallet/reference/json-rpc-methods/index.md @@ -13,6 +13,7 @@ Each method may have one or more of the following labels: - **MetaMask** - The functionalities of these methods are specific to MetaMask, and may or may not be supported by other wallets. - **Restricted** - These methods are restricted and require requesting permission using [`wallet_requestPermissions`](/wallet/reference/json-rpc-methods/wallet_requestpermissions). - **Mobile** - These methods are only available on MetaMask Mobile. +- **Ethereum API** - These are standard Ethereum JSON-RPC API methods. See the [Ethereum wiki](https://ethereum.org/en/#json-rpc-methods) for more information about these methods. +- **Multichain API** - These methods are compatible with the [Multichain API](../multichain-api.md). - **Experimental** - These methods are experimental and may be changed in the future. -- **Deprecated** - These methods are deprecated and may be removed in the future. -- **Ethereum API** - These are standard Ethereum JSON-RPC API methods. See the [Ethereum wiki](https://ethereum.org/en/#json-rpc-methods) for more information about these methods. \ No newline at end of file +- **Deprecated** - These methods are deprecated and may be removed in the future. \ No newline at end of file diff --git a/wallet/reference/multichain-api.md b/wallet/reference/multichain-api.md new file mode 100644 index 00000000000..bcd2423db31 --- /dev/null +++ b/wallet/reference/multichain-api.md @@ -0,0 +1,387 @@ +--- +description: See the Multichain API reference. +sidebar_custom_props: + flask_only: true +--- + +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + +# Multichain API + +:::flaskOnly +::: + +Dapps can call Multichain API [methods](#methods) to create and manage +[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) +- [Interact with multiple networks](../how-to/manage-networks/use-multichain.md) +::: + +## Methods + +### `wallet_createSession` + +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 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 connection. + +#### Example + + + + +```json +{ + "id": 1, + "jsonrpc": "2.0", + "method": "wallet_createSession", + "params": { + "optionalScopes": { + "eip155": { + "references": ["1", "137"], + "methods": ["eth_sendTransaction", "eth_signTransaction", "eth_sign", "get_balance", "personal_sign"], + "notifications": ["accountsChanged", "chainChanged"] + }, + "eip155:10": { + "methods": ["get_balance"], + "notifications": ["accountsChanged", "chainChanged"] + }, + "eip155:0": { + "methods": ["wallet_getPermissions", "wallet_creds_store", "wallet_creds_verify", "wallet_creds_issue", "wallet_creds_present"], + "notifications": [] + }, + "eip155:42161": { + "methods": ["eth_sendTransaction", "eth_signTransaction", "get_balance", "personal_sign"], + "notifications": ["accountsChanged", "chainChanged"] + } + }, + "sessionProperties": { + "expiry": "2022-12-24T17:07:31+00:00", + "caip154-mandatory": "true" + } + } +} +``` + + + + +```json +{ + "id": 1, + "jsonrpc": "2.0", + "result": { + "sessionScopes": { + "eip155": { + "references": ["1", "137"], + "methods": ["eth_sendTransaction", "eth_signTransaction", "get_balance", "eth_sign", "personal_sign"], + "notifications": ["accountsChanged", "chainChanged"], + "accounts": ["eip155:1:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb", "eip155:137:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb"] + }, + "eip155:10": { + "methods": ["get_balance"], + "notifications": ["accountsChanged", "chainChanged"], + "accounts": [] + }, + "eip155:42161": { + "methods": ["personal_sign"], + "notifications": ["accountsChanged", "chainChanged"], + "accounts": ["eip155:42161:0x0910e12C68d02B561a34569E1367c9AAb42bd810"], + "rpcDocuments": "https://example.com/wallet_extension.json" + }, + "eip155:0": { + "methods": ["wallet_getPermissions", "wallet_creds_store", "wallet_creds_verify", "wallet_creds_issue", "wallet_creds_present"], + "notifications": [] + } + }, + "sessionProperties": { + "expiry": "2022-11-31T17:07:31+00:00", + "globalConfig": { + "foo": "bar" + } + } + } +} +``` + + + + +### `wallet_getSession` + +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 +MetaMask doesn't support session IDs. +::: + +#### Parameters + +None. + +#### Returns + +The scopes and properties of the connection. + +#### Example + + + + +```json +{ + "id": 1, + "jsonrpc": "2.0", + "method": "wallet_getSession", + "params": {} +} +``` + + + + +```json +{ + "id": 1, + "jsonrpc": "2.0", + "result": { + "sessionScopes": { + "eip155:1": { + "methods": ["eth_signTransaction"], + "notifications": ["accountsChanged"], + "accounts": ["eip155:1:0xabc123"] + }, + "eip155:137": { + "methods": ["eth_sendTransaction"], + "notifications": ["chainChanged"], + "accounts": ["eip155:137:0xdef456"] + }, + "solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ": { + "methods": ["getBalance", "getAccountInfo", "sendTransaction", "getBlock"], + "notifications": [], + "accounts": ["solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ:4Nd1mS8AUwK3kU3gdiAM6QCvqhA7Do8rKtMXsGyqrJxy"] + } + } + } +} +``` + + + + +### `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 connection. +This method is defined in [CAIP-27](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-27.md). + +:::note +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 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 connection. + - `params`: `object` - The RPC method parameters (can be empty). + +#### Returns + +The response from the JSON-RPC method call. + +#### Example + + + + +```json +{ + "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" + } + ] + } + } +} +``` + + + + +```json +{ + "id": 1, + "jsonrpc": "2.0", + "result": { + "scope": "eip155:1", + "result": { + "method": "eth_sendTransaction", + "result": "0x4e306b5a5a37532e1734503f7d2427a86f2c992fbe471f5be403b9f734e667c8" + } + } +} +``` + + + + +### `wallet_revokeSession` + +Revokes the active connection. +This method is defined in [CAIP-285](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-285.md). + +:::note +MetaMask doesn't support session IDs. +::: + +#### Parameters + +None. + +#### Returns + +`true` if the revocation was successful. + +#### Example + + + + +```json +{ + "id": 1, + "jsonrpc": "2.0", + "method": "wallet_revokeSession", + "params": {} +} +``` + + + + +```json +{ + "id": 1, + "jsonrpc": "2.0", + "result": true +} +``` + + + + +## Events + +The Multichain API provides the following events that wallets can send to dapps to notify them of +changes to a session. + +### `wallet_notify` + +Notifies the dapp of events or state changes related to a specific, previously authorized network. +This event is defined in [CAIP-319](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-319.md). + +:::note +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 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 connection. + - `params`: `object` - The RPC notification method parameters. + +#### Example + +```json +{ + "jsonrpc": "2.0", + "method": "wallet_notify", + "params": { + "scope": "eip155:1", + "notification": { + "method": "eth_subscription", + "params": { + "subscription": "0x12345678", + "result": { + "blockNumber": "0x1234", + "transactionHash": "0x5678", + "logIndex": "0x9abc" + } + } + } + } +} +``` + +### `wallet_sessionChanged` + +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 +MetaMask doesn't support session IDs. +::: + +#### Parameters + +`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 + +```json +{ + "jsonrpc": "2.0", + "method": "wallet_sessionChanged", + "params": { + "sessionScopes": { + "eip155:1": { + "methods": ["eth_signTransaction", "eth_sendTransaction"], + "notifications": ["message"], + "accounts": ["eip155:1:0xabc123"] + }, + "eip155:137": { + "methods": ["eth_sendTransaction"], + "notifications": [], + "accounts": ["eip155:137:0xdef456"] + } + } + } +} +``` \ No newline at end of file