useSetConnectedWallet

Hook for setting a wallet instance as "connected" - once done, the wallet connection hooks like useWallet , useAddress , useSigner , useConnectionStatus etc will return the data for that wallet instance

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

Example

import {
useCreateWalletInstance,
useSetConnectionStatus,
useSetConnectedWallet,
metamaskWallet,
} from "@thirdweb-dev/react";
const walletConfig = metamaskWallet();
function Example() {
const createWalletInstance = useCreateWalletInstance();
const setConnectionStatus = useSetConnectionStatus();
const setConnectedWallet = useSetConnectedWallet();
// Call this function to connect your wallet
const handleConnect = async () => {
// 1. create instance
const walletInstance = createWalletInstance(walletConfig);
setConnectionStatus("connecting");
try {
// 2. Call `connect` method of your wallet
await walletInstance.connect(
connectOptions, // if your wallet.connect method accepts any options, specify it here
);
// 3. Set connected wallet
setConnectedWallet(walletInstance);
props.close();
} catch (e) {
setConnectionStatus("disconnected");
console.error("failed to connect", e);
}
};
return <div> ... </div>;
}
function useSetConnectedWallet(): (
wallet: WalletInstance,
params?: ConnectParams<Record<string, any>>,
) => Promise<void>;

Returns

let returnType: (
wallet: WalletInstance,
params?: ConnectParams<Record<string, any>>,
) => Promise<void>;

A function to set a wallet instance as "connected".