Skip to main content

Sessions (CAIP-25)

A session is an authorized connection between your dapp and MetaMask that can span multiple blockchain ecosystems and chains, as defined in CAIP-25. When a user approves a connection, MetaMask creates a session including the approved scopes and accounts.

MetaMask Connect Multichain provides the method getSession to get information about the current session, and the method disconnect to end or update the session. For more information about the session lifecycle, see CAIP-316.

A session is persistent, meaning it survives across page reloads and new tabs.

A session includes sessionScopes, which contains the chains the user approved, each with its associated accounts. The following example extracts the approved Ethereum Mainnet and Solana Mainnet accounts from sessionScopes:

const session = await client.provider.getSession()

const ethAccounts = session.sessionScopes['eip155:1']?.accounts || []
const solAccounts = session.sessionScopes['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp']?.accounts || []
note

MetaMask doesn't support session IDs.

Next steps

  • Scopes: Understand CAIP-2 chain identifiers used in sessions.
  • Accounts: Learn how CAIP-10 account IDs identify accounts across chains.
On this page