Skip to main content

useMetamask

Hook for connecting to a Metamask enabled web3 provider.

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

Usage

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

function App() {
const [connectMetamask, { data, error }] = useMetamask();

if (error) {
console.error(error);
}

return (
<button onClick={connectMetamask}>
Connect Metamask
</button>
);
}

Return Value

The hook returns a tuple of [connectMetamask, { data, error }].

The connectMetamask function is used to connect to the Metamask provider.

The data object contains the web3 provider data when the connection is successful.

The error object contains an error message if the connection fails.