Skip to main content

Wallet

caution

This module is only available with local mode set to true

This module interacts with and maintains the state of the user's browser wallet. Use the chainIds setting

Properties

Get wallet status

The state$ property is an observable that emits the state of the wallet.

const wallet = sdk.wallet

wallet.state$.subscribe((state)=> {
console.log(`Address: ${state.account}; ChainID: ${state.chainId}`)
})
Wallet State

The wallet state is an object that satisfies the WalletState interface and has the following properties:

interface WalletState {
account: string;
chainId: number;
}

Get wallet account

The account property has the value of the account of the connected wallet.

const wallet = sdk.wallet

const address = wallet.account // 0xa73a3b8ACa335855EeaC2f9Fb505BB0360A1B703

Methods

Check if the wallet is connected

The isAuthenticated method returns an Observable<boolean> indicating whether the wallet is connected.

const wallet = sdk.wallet

wallet.isAuthenticated().subscribe(isAuth => {
console.log(`Wallet is connected: ${isAuth}`)
})

Get the wallet provider

The getProvider method returns a Promise<Provider> containing the connected wallet instance.

const wallet = sdk.wallet

const provider = await wallet.getProvider()
Provider

This method returns an instance of Web3Provider from the ethers.js library; See Web3Provider

Get the network ID of the wallet

The getChainId method returns a Promise<number> containing the network ID of the connected wallet.

const wallet = sdk.wallet

const chainId = await wallet.getChainId(); // 80001

Obtain information from the wallet's network

The getChainData method returns a Promise<ChainData> containing the network information of the connected wallet.

const wallet = sdk.wallet

const data = await wallet.getChainData()
Chain Data

See more about the Chain interface in ChainData

Get the signer of the wallet

The getSigner method returns a Promise<JsonRpcSigner> containing the signer of the connected wallet.

const wallet = sdk.wallet

const signer = await wallet.getSigner()
JsonRpcSigner

This method returns an instance of JsonRpcSigner from the ethers.js library. See JsonRpcSigner

Connect browser wallet

The connectToProvider method returns a Promise<void> that connects the wallet to a network.

const wallet = sdk.wallet

await wallet.connectToProvider(WalletProviders.Metamask);
Wallet Providers

The available wallet providers are WalletProviders.Metamask and WalletProviders.Coinbase

Change the network of the wallet

The changeNetwork method returns a Promise<void> that changes the network of the wallet.

const wallet = sdk.wallet;

constchainId = 80001;

await wallet.changeNetwork(chainId);