Simple Summary
An interface for wallet to manage multiple chains.
Inspired by EIP-3085 and EIP-3326.
Abstract
JavaScript wallet providers may implements wallet_addStarknetChain
and wallet_switchStarknetChain
RPC methods. This allow dapps to add a new chain and switch to another known chain.
Motivation
Dapps can require to interact to a specific Starknet chain in order to work. wallet_switchStarknetChain
enables dapps to request that the wallet switches its active chain to whichever one is required by the dapp.
Wallets having a limited list of pre-defined chains, dapps may require to use another chain. wallet_addStarknetChain
enables dapps to request that the wallet add a new chain.
Specification
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”,
and “OPTIONAL” in this document are to be interpreted as described in RFC-2119.
RPC methods
wallet_addStarknetChain
The method accepts a single object parameter, with a chainId and some chain metadata. The method returns null if the chain was added to the wallet, and an error otherwise.
The wallet MAY reject the request for any reason.
Adding a new chain does not necessarily mean that the wallet will automatically switch to it.
Parameters
wallet_addStarknetChain
accepts a single object parameter, specified by the following TypeScript interface:
interface AddStarknetChainParameters {
id: string // What the purpose
chainId: string // A 0x-prefixed hexadecimal string
chainName: string
rpcUrl: string
accountImplementation?: string
nativeCurrency?: {
name: string
symbol: string // 2-6 characters long
decimals: 18
}
}
wallet_switchStarknetChain
The method accepts a single object parameter with a chainId field. The method returns null if the wallet switched its active chain, and an error otherwise.
The method presupposes that the wallet has a concept of a single “active chain”. The active chain is defined as the chain that the wallet is forwarding RPC requests to.
Parameters
wallet_switchStarknetChain
accepts a single object parameter, specified by the following TypeScript interface:
interface SwitchStarknetChainParameters {
chainId: string;
}
If a field does not meet the requirements of this specification, the wallet MUST reject the request.
- chainId
- MUST specify the integer ID of the chain as a hexadecimal string.
- The chain ID MUST be known to the wallet.
- The wallet MUST be able to switch to the specified chain and service RPC requests to it.
- The method MUST return null if the request was successful, and an error otherwise.
- If the wallet does not have a concept of an active chain, the wallet MUST reject the request.
Events
chainChanged
Based on EIP-1193
The Provider emits chainChanged
when connecting to a new chain.
Provider.on('chainChanged', listener: (chainId: string) => void): Provider;
chainId
MUST be presented as a hexadecimal string.