Skip to main content

useConnect

Hook for connecting any supported wallet to your app.

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

const connect = useConnect();

Usage

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

const metamask = metamaskWallet();

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

return <button onClick={() => connect(metamask)}>Connect to MetaMask</button>;
}

Configuration

wallet (required)

The wallet to connect to your app with.

Must be of type AbstractBrowserWallet.

Learn more about the available wallet options.

chainId (optional)

To connect to a specific chain when connecting the wallet, pass the chainId in a configuration object as shown below.

This will prompt the user to switch to the given network after they connect.

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

const metamask = metamaskWallet();

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

return (
<button
onClick={() =>
connect(
metamask,
{ chainId: 1 },
)
}
>
Connect to MetaMask
</button>
);
}