diff --git a/docs/whats-new.md b/docs/whats-new.md index 082a9541f60..4e7d066d0d3 100644 --- a/docs/whats-new.md +++ b/docs/whats-new.md @@ -11,6 +11,9 @@ of the [MetaMask developer page](https://metamask.io/developer/). ## May 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 [Solana](/wallet/how-to/use-non-evm-networks/solana) dapp support via the Wallet Standard and third-party libraries. ([#1940](https://github.com/MetaMask/metamask-docs/pull/1940)) - Documented [MetaMask SDK + Web3Auth SDK integration](/sdk/quickstart/javascript-web3auth). diff --git a/snaps/get-started/install-flask.md b/snaps/get-started/install-flask.md index e4fe30694cb..14cb0a5a845 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 fb93287ebf4..24b7591abc7 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 simultaneously", + id: "how-to/manage-networks/use-multichain" } ] }, @@ -191,6 +196,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", @@ -267,6 +277,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..6f1b2f49f0f --- /dev/null +++ b/wallet/concepts/multichain-api.md @@ -0,0 +1,123 @@ +--- +description: Learn about the Multichain API. +--- + +# About the Multichain API + +:::tip Experimental +The Multichain API is an experimental feature and currently only available on the extension (not on mobile). +::: + +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 networks without having to request chain switches. + This feature reduces development overhead involved with ensuring the correct network is targeted for a given dapp-proposed transaction. + +- **Extensibility** - The Multichain API can be integrated with + [interoperability Snaps](https://snaps.metamask.io/explore/), providing a standards-based interface + to connect wallets with dapps on non-EVM networks. + +- **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 cross-ecosystem multichain wallet connection flows, trigger transactions across different networks more seamlessly, 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 methods for dapps to manage multichain connections: + +- [`wallet_createSession`](../reference/multichain-api.md#wallet_createsession) - Creates a multichain connection with a wallet, with specified properties and +authorization scopes. +Dapps can update the connection using the same method. +- [`wallet_invokeMethod`](../reference/multichain-api.md#wallet_invokemethod) - Calls a subset of the [Wallet JSON-RPC API methods](../reference/json-rpc-methods/index.md) on +a specified chain. +- [`wallet_getSession`](../reference/multichain-api.md#wallet_getsession) - Gets +the scopes and properties of the active connection. +- [`wallet_revokeSession`](../reference/multichain-api.md#wallet_revokesession) - Revokes the active connection. + +The API also includes events that wallets can send to dapps: + +- [`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 provider API is not optimized for multichain usage, and we recommend +[starting directly with the Multichain API](../how-to/manage-networks/use-multichain.md). +The Multichain API is backwards compatible mainly to support dapps that use third-party libraries +with dependencies on the legacy provider. + +:::note +A multichain connection will overwrite a connection with the legacy EIP-1193 provider, and vice versa. +::: + +## 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/concepts/wallet-api.md b/wallet/concepts/wallet-api.md index 0801245d1ba..02ea9cc6817 100644 --- a/wallet/concepts/wallet-api.md +++ b/wallet/concepts/wallet-api.md @@ -22,7 +22,7 @@ This API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193), an request users' EVM accounts, read data from blockchains the user is connected to, suggest that the user sign messages and transactions, and more. -:::info Note +:::info EIP-6963: Wallet interoperability MetaMask supports [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963), which introduces an alternative wallet detection mechanism to the `window.ethereum` injected provider. This alternative mechanism enables dapps to support [wallet interoperability](wallet-interoperability.md) @@ -46,6 +46,13 @@ The MetaMask Ethereum provider API contains the following: View the [provider API reference](../reference/provider-api.md) for all the provider properties, methods, and events. +:::note Multichain API +MetaMask supports the [Multichain API](multichain-api.md) for interacting with multiple blockchain networks and ecosystems simultaneously. +While the Multichain API is backwards compatible with the provider API, the provider API is not optimized for multichain usage. +If you intend to support multichain interactions, we recommend +[starting directly with the Multichain API](../how-to/manage-networks/use-multichain.md). +::: + ## JSON-RPC API MetaMask uses the [`request()`](../reference/provider-api.md#request) 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..07c2a474701 --- /dev/null +++ b/wallet/how-to/manage-networks/use-multichain.md @@ -0,0 +1,233 @@ +--- +description: Interact with multiple networks simultaneously using the Multichain API. +toc_max_heading_level: 4 +--- + +# Interact with multiple networks simultaneously + +:::tip Experimental +The Multichain API is an experimental feature and currently only available on the extension (not on mobile). +::: + +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 (Chrome) +const extensionPort = chrome.runtime.connect(EXTENSION_ID) + +// Set up a message listener for events. +extensionPort.onMessage.addListener((msg) => { + if (msg.data.method === "wallet_notify") { + console.log("wallet_notify:", msg.data.params) + 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-348", + 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-348", + data: { + jsonrpc: "2.0", + method: "wallet_createSession", + params: { + optionalScopes: { + "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-348", + 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-348", + 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-348", + data: { + jsonrpc: "2.0", + method: "wallet_invokeMethod", + params: { + // Specify a chain ID where the user has sufficient gas. + scope: "eip155:1", // Ethereum Mainnet + 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 84c039069aa..780d890a66d 100644 --- a/wallet/reference/json-rpc-methods/index.md +++ b/wallet/reference/json-rpc-methods/index.md @@ -14,6 +14,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..dea721fa0a1 --- /dev/null +++ b/wallet/reference/multichain-api.md @@ -0,0 +1,386 @@ +--- +description: See the Multichain API reference. +--- + +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + +# Multichain API + +:::tip Experimental +The Multichain API is an experimental feature and currently only available on the extension (not on mobile). +::: + +Dapps can call Multichain API [methods](#methods) to create and manage +[CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) multichain 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` - (Optional) [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) authorization scopes the wallet can support in order to be used 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, you can 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](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md) + 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 connection is valid. +- `requiredScopes`: `object` - (Optional) [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) authorization scopes the wallet must support to be compatible with the dapp. + We don't recommend using `requiredScopes` with MetaMask. + MetaMask treats all `requiredScopes` as `optionalScopes`. + +#### 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", "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": [] + } + } + } +} +``` + + + + +```json +{ + "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-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": [], + "accounts": ["eip155:1:0xabc123"] + }, + "eip155:137": { + "methods": ["eth_sendTransaction"], + "notifications": [], + "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": [], + "accounts": ["eip155:1:0xabc123"] + }, + "eip155:137": { + "methods": ["eth_sendTransaction"], + "notifications": [], + "accounts": ["eip155:137:0xdef456"] + } + } + } +} +``` \ No newline at end of file