Wallet
Wallet interface
id: TWalletId; onConnectRequested?: () => Promise<void>; autoConnect: ( connect: ( disconnect: () => Promise<void>; getChain: () => | undefined | { readonly blockExplorers?: Array<{ apiUrl?: string; name: string; url: string; }>; readonly experimental?: { increaseZeroByteCount?: boolean }; readonly faucets?: Array<string>; readonly icon?: Icon; readonly id: number; readonly name?: string; readonly nativeCurrency?: { decimals?: number; name?: string; symbol?: string; }; readonly rpc: string; readonly testnet?: true; }; switchChain: (chain: { readonly blockExplorers?: Array<{ apiUrl?: string; name: string; url: string; }>; readonly experimental?: { increaseZeroByteCount?: boolean }; readonly faucets?: Array<string>; readonly icon?: Icon; readonly id: number; readonly name?: string; readonly nativeCurrency?: { decimals?: number; name?: string; symbol?: string; }; readonly rpc: string; readonly testnet?: true; }) => Promise<void>;};
function onConnectRequested(): Promise<void>;
Subscribe to wallet for certain events like chainChanged
, accountChanged
, disconnect
, etc.
wallet.subscribe("chainChanged", (chain) => { console.log("wallet is now connected to network:", chain);}); wallet.subscribe("accountChanged", (account) => { console.log("wallet is now connected to account:", account);}); wallet.subscribe("disconnect", () => { console.log("wallet is disconnected");});
Re-connect the wallet automatically without prompting the user for connection.
This is useful to automatically connect the wallet if it was already connected in the past to reconnect wallet when user re-visits the website after some time or refreshes the page.
function autoConnect(
Prompt the user to connect the wallet.
function connect(
Options to connect the wallet. Depending on the wallet id, The options can be different.
Disconnect the wallet
function disconnect(): Promise<void>;
Get the Account
object that the wallet is currently connected to.
If the wallet is not connected, it returns undefined
.
Refer to Account vs Wallet to understand the difference between Account
and Wallet
interface
const account = wallet.getAccount();
Get the Chain
object of the network that the wallet is currently connected to.
If the wallet is not connected, it returns undefined
.
const chain = wallet.getChain();
function getChain(): | undefined | { readonly blockExplorers?: Array<{ apiUrl?: string; name: string; url: string; }>; readonly experimental?: { increaseZeroByteCount?: boolean }; readonly faucets?: Array<string>; readonly icon?: Icon; readonly id: number; readonly name?: string; readonly nativeCurrency?: { decimals?: number; name?: string; symbol?: string; }; readonly rpc: string; readonly testnet?: true; };
let returnType: | undefined | { readonly blockExplorers?: Array<{ apiUrl?: string; name: string; url: string; }>; readonly experimental?: { increaseZeroByteCount?: boolean }; readonly faucets?: Array<string>; readonly icon?: Icon; readonly id: number; readonly name?: string; readonly nativeCurrency?: { decimals?: number; name?: string; symbol?: string; }; readonly rpc: string; readonly testnet?: true; };
Switch the wallet to a different network by passing the Chain
object of the network
function switchChain(chain: { readonly blockExplorers?: Array<{ apiUrl?: string; name: string; url: string; }>; readonly experimental?: { increaseZeroByteCount?: boolean }; readonly faucets?: Array<string>; readonly icon?: Icon; readonly id: number; readonly name?: string; readonly nativeCurrency?: { decimals?: number; name?: string; symbol?: string; }; readonly rpc: string; readonly testnet?: true;}): Promise<void>;
The Chain
object of the network to switch to.
You can create a Chain
object using the defineChain
function.
At minimum, you need to pass the id
of the blockchain to defineChain
function to create a Chain
object.
let chain: { readonly blockExplorers?: Array<{ apiUrl?: string; name: string; url: string; }>; readonly experimental?: { increaseZeroByteCount?: boolean }; readonly faucets?: Array<string>; readonly icon?: Icon; readonly id: number; readonly name?: string; readonly nativeCurrency?: { decimals?: number; name?: string; symbol?: string; }; readonly rpc: string; readonly testnet?: true;};