Skip to main content

useConnect

Hook for connecting any supported wallet config to your app.

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

const connect = useConnect();

The wallet also needs to be added in ThirdwebProvider's supportedWallets if you want the wallet to auto-connect on next page load.

Usage

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

const metamaskConfig = metamaskWallet();

function App() {
const connect = useConnect();

return (
<button
onClick={async () => {
const wallet = await connect(metamaskConfig, connectOptions);
console.log("connected to ", wallet);
}}
>
Connect to MetaMask
</button>
);
}

Configuration

walletConfig

The wallet to connect to your app with.

Must be of type WalletConfig.

Learn more about the available wallet options.

connectOptions

connectOptions depends on the wallet you are connecting.

If you are using typescript, connect will automatically infer the type of connectOptions based on the walletConfig you pass in.