CoinbaseWallet
Wallet Interface to connect Coinbase Wallet extension or mobile app.
import { CoinbaseWallet } from "@thirdweb-dev/wallets"; const wallet = new CoinbaseWallet(); await wallet.connect();
The options
object contains the following properties:
clientId (recommended)
Provide clientId
to use the thirdweb RPCs for given chains
You can create a client ID for your application from thirdweb dashboard .
chains (optional)
Provide an array of chains you want to support.
Must be an array of Chain
objects, from the @thirdweb-dev/chains
package.
Defaults to our default chains .
dappMetadata (optional)
Information about your app that the wallet will display when your app tries to connect to it.
Must be an object containing name
, url
and optionally description
and logoUrl
properties.
import { CoinbaseWallet } from "@thirdweb-dev/wallets"; const walletWithOptions = new CoinbaseWallet({ dappMetadata: { name: "thirdweb powered dApp", url: "https://thirdweb.com", description: "thirdweb powered dApp", // optional logoUrl: "https://thirdweb.com/favicon.ico", // optional },});
headlessMode (optional)
This is only relevant applies when coinbase extension wallet is NOT installed on user's browser.
By default headlessMode
is set to false
- which means that when user does not have coinbase wallet extension installed, a QR Code scan modal will open when calling the connect
method to allow the user to connect to their coinbase mobile app by scanning the QR code.
If headlessMode is set to true
and coinbase wallet extension is not installed, the wallet will NOT open a QR Code scan modal - This is useful if you want to create a custom QR Code modal.
you can use the getQrUrl
method to get the QR Code url and create your own QR Code Modal
Must be a boolean
.
Get the QR Code url to render a custom QR Code Modal for connecting to Coinbase Wallet.
This method is only relevant when coinbase extension wallet is NOT installed on user's browser and headlessMode
is set to true
.
const wallet = new CoinbaseWallet({ headlessMode: true }); const qrUrl = await wallet.getQrUrl();// render a QR Code Modal with the qrUrl const walletAddress = await wallet.connect(); // this is resolved when user scans the QR Code and wallet is connected console.log("connected to", walletAddress);
function getQrUrl(): Promise<string>;
AbstractClientWallet.addListener
function addListener( event: T, fn: ( ) => void, context?: any,): this;
let fn: () => void;
AbstractClientWallet.autoConnect
auto-connect the wallet if possible
function autoConnect(connectOptions?: { chainId?: number;}): Promise<string>;
AbstractClientWallet.connect
Connect wallet
function connect(connectOptions?: { chainId?: number;}): Promise<string>;
AbstractClientWallet.disconnect
Disconnect the wallet
function disconnect(): Promise<void>;
AbstractClientWallet.emit
Calls each of the listeners registered for a given event.
function emit( event: T,): boolean;
AbstractClientWallet.eventNames
Return an array listing the events for which the emitter has registered listeners.
AbstractClientWallet.getAddress
Returns the account address of the connected wallet
function getAddress(): Promise<string>;
AbstractClientWallet.getBalance
Returns the balance of the connected wallet for the specified token address. If no token address is specified, it returns the balance of the native token
function getBalance( tokenAddress: string,): Promise<{ decimals: number; displayValue: string; name: string; symbol: string; value: BigNumber;}>;
AbstractClientWallet.getChainId
Returns the chain id of the network that the wallet is connected to
function getChainId(): Promise<number>;
AbstractClientWallet.getPersonalWallet
If the wallet uses another "personal wallet" under the hood, return it
This is only useful for wallets like Safe or Smart Wallet uses a "personal wallet" under the hood to sign transactions. This method returns that wallet
AbstractClientWallet.getSigner
Get ethers Signer object of the connected wallet
function getSigner(): Promise<Signer>;
AbstractClientWallet.listenerCount
Return the number of listeners listening to a given event.
AbstractClientWallet.listeners
Return the listeners registered for a given event.
function listeners( event: T,): Array< ( ) => void>;
let returnType: Array< ( ) => void>;
AbstractClientWallet.off
function off( event: T, fn?: ( ) => void, context?: any, once?: boolean,): this;
let fn: () => void;
AbstractClientWallet.on
Add a listener for a given event.
function on( event: T, fn: ( ) => void, context?: any,): this;
let fn: () => void;
AbstractClientWallet.once
Add a one-time listener for a given event.
function once( event: T, fn: ( ) => void, context?: any,): this;
let fn: () => void;
AbstractClientWallet.removeListener
Remove the listeners of a given event.
function removeListener( event: T, fn?: ( ) => void, context?: any, once?: boolean,): this;
let fn: () => void;
AbstractClientWallet.signMessage
Sign a message with the connected wallet and return the signature
function signMessage(message: string | Bytes): Promise<string>;
AbstractClientWallet.switchChain
Switch to different Network/Blockchain in the connected wallet
function switchChain(chainId: number): Promise<void>;
AbstractClientWallet.transfer
Transfers some amount of tokens to the specified address
function transfer( to: string, amount: string | number, currencyAddress: string,): Promise<Omit<TransactionResultWithMetadata<unknown>, "data">>;
AbstractClientWallet.updateChains
Update the chains supported by the wallet. This is useful if wallet was initialized with some chains and this needs to be updated without re-initializing the wallet
function updateChains(chains: Array<Chain>): Promise<void>;
AbstractClientWallet.verifySignature
Verify the signature of a message. It returns true
if the signature is valid, false
otherwise
function verifySignature( message: string, signature: string, address: string, _chainId?: number,): Promise<boolean>;
let walletId: string;
let prefixed: string | boolean;