Skip to main content

useSetConnectedWallet

Hook for setting a connected wallet. Once a walletInstance is set using this hook, the wallet instance will be available from useWallet hook.

This is only useful if you are manually connecting a wallet as mentioned in Build your Wallet

import { useSetConnectedWallet } from "@thirdweb-dev/react";

const setConnectedWallet = useSetConnectedWallet();

setConnectedWallet(walletInstance);

Usage

import { useSetConnectedWallet, metamaskWallet } from "@thirdweb-dev/react";

const metamaskConfig = metamaskWallet();

function App() {
const setConnectedWallet = useSetConnectedWallet();
const createWalletInstance = useCreateWalletInstance();

const handleConnect = async () => {
// create a wallet instance using useCreateWalletInstance
const metamaskWalletInstance = createWalletInstance(metamaskConfig);
// connect the wallet instance
await metamaskWalletInstance.connect();

// set the connected wallet as connected
setConnectedWallet(walletInstance);
};

return <div> ... </div>;
}

Configuration

walletInstance

walletInstance is of type WalletInstance - which is an instance type of Abstract Client Wallet class