Skip to main content

Getting Started

To get started, install the package into your project.

npm i @thirdweb-dev/wallets

Now youre ready to use any of our supported wallets.

// 1. Import the wallet you want to use from the package
import { CoinbaseWallet } from "@thirdweb-dev/wallets";

// 2. Instantiate the wallet class
const coinbaseWallet = new CoinbaseWallet();

// 3. Connect to the wallet (prompts the user when required)
const walletAddress = await coinbaseWallet.connect();

// 4. Use the connected wallet to access information such as the signer
const signer = await coinbaseWallet.getSigner();

Methods available on a Wallet Instance

All wallets in wallet SDK extend from the AbstractWallet base class, and all client-side wallets (web, mobile) extend from AbstractClientWallet base class. Each wallet may have its own unique methods. Below are the common methods shared by all wallets

getAddress

Get the address of the currently connected wallet

const address = await wallet.getAddress();
getChainId

Get the chain ID of the network the wallet is currently connected to

const chainId = await wallet.getChainId();
getSigner

Get the signer for the currently connected wallet.

const signer = await wallet.getSigner();
signMessage

Sign a message with the currently connected wallet. This function must be implemented by the parent class.

const signature = await wallet.signMessage("Hello world!");
verifySignature

Verify if a signature is valid or not

const isValid = await wallet.verifySignature(
"Message",
"Signature",
"wallet_address",
);
transfer

Transfer native or ERC20 tokens from this wallet to another wallet

// for native tokens
const txResult = await wallet.transfer(recipientAddress, amount);

// for ERC20 tokens
const txResult = await wallet.transfer(recipientAddress, amount, tokenAddress);

recipientAddress

Address of the recipient to send the tokens to

string

amount

Amount of tokens to send

string | number

Return Value

Promise<TransactionResult>
getBalance

Get the the native token balance or ERC20 token balance of the wallet.

// for native token balance
const balance = await wallet.getBalance();

// for ERC20 token balance
const balance = await wallet.getBalance(tokenAddress);

tokenAddress

Address of the ERC20 token. If no address is provided, the native token balance is returned.

Return Value

Promise<{
symbol: string;
value: BigNumber;
name: string;
decimals: number;
displayValue: string;
}>;

Usage with thirdweb SDKs