Wallet
Wallet interface
id: TWalletId; onConnectRequested?: () => Promise<void>; autoConnect: ( connect: ( disconnect: () => Promise<void>; getChain: () => | undefined switchChain: ( ) => 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(
let returnType: { address: Address; onTransactionRequested?: ( ) => Promise<void>; sendBatchTransaction?: ( txs: Array<SendTransactionOption>, ) => Promise<SendTransactionResult>; sendRawTransaction?: ( tx: SendRawTransactionOptions, ) => Promise<SendTransactionResult>; sendTransaction: ( tx: SendTransactionOption, ) => Promise<SendTransactionResult>; signMessage: ({ message, }: { message: SignableMessage; }) => Promise<Hex>; signTransaction?: (tx: TransactionSerializable) => Promise<Hex>; signTypedData: ( _typedData: TypedDataDefinition<typedData, primaryType>, ) => Promise<Hex>; watchAsset?: (asset: WatchAssetParams) => Promise<boolean>;};
Prompt the user to connect the wallet.
function connect(
Options to connect the wallet. Depending on the wallet id, The options can be different.
let returnType: { address: Address; onTransactionRequested?: ( ) => Promise<void>; sendBatchTransaction?: ( txs: Array<SendTransactionOption>, ) => Promise<SendTransactionResult>; sendRawTransaction?: ( tx: SendRawTransactionOptions, ) => Promise<SendTransactionResult>; sendTransaction: ( tx: SendTransactionOption, ) => Promise<SendTransactionResult>; signMessage: ({ message, }: { message: SignableMessage; }) => Promise<Hex>; signTransaction?: (tx: TransactionSerializable) => Promise<Hex>; signTypedData: ( _typedData: TypedDataDefinition<typedData, primaryType>, ) => Promise<Hex>; watchAsset?: (asset: WatchAssetParams) => Promise<boolean>;};
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
Switch the wallet to a different network by passing the Chain
object of the network
function switchChain(): 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.