Docs

walletConnect

walletConnect allows you to connect to the a wallet Using WalletConnect protocol

Example

import { walletConnect } from "thirdweb/wallets";
import { client } from "./client";
const wallet = walletConnect({
client,
dappMetadata: {
name: "My Dapp",
url: "https://my-dapp.com",
logoUrl: "https://my-dapp.com/logo.png",
description: "Some description of my dapp",
},
});
async function connectUsingWCModal() {
try {
// connect using WalletConnect's official QR code modal
const account = await wallet.connect({
showQrModal: true,
});
console.log("connected to", account);
} catch (e) {
console.error("error connecting to metamask", e);
}
}
async function connectUsingCustomQRScan() {
try {
// connect using WalletConnect's official QR code modal
const account = await wallet.connect({
showQrModal: false,
onDisplayUri: (uri) => {
// display the uri to the user
// once the user scans the uri, the wallet will bed connected
// and the promise returned by `wallet.connect` will be resolved
},
});
console.log("connected to", account);
} catch (e) {
console.error("error connecting to metamask", e);
}
}

If you want the wallet to be connected to a specific blockchain, you can pass a Chain object to the connect method. This will trigger a chain switch if the wallet provider is not already connected to the specified chain.

You can create a Chain object using the defineChain function. At minimum, you need to pass the id of the blockchain.

import { defineChain } from "thirdweb";
const mumbai = defineChain({
id: 80001,
});
const address = await wallet.connect({ chain: mumbai });

Refer to WalletConnectConnectionOptions to see the options that wallet.connect method accepts.

Parameters

Returns

The WalletConnect instance