Skip to main content

useContract

Hook for connecting to a smart contract.

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

Usage

Provide your smart contract address as the first parameter. The second parameter is contract type; which is strongly recommended if your contract is a prebuilt contract, but not required.

Once connected, contract will be an instance of your smart contract.

The ABI is resolved automatically from our on-chain registry.

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

function App() {
const { contract, isLoading, error } = useContract("{{contract_address}}");
}
Import Smart Contracts

If your smart contract was not deployed using thirdweb, youll need to import it on the dashboard.

Configuration

Contract Type (optional)

If your contract is a prebuilt contract, it is strongly recommended you provide the contract's name as the second argument to gain access to improved top-level functions and type inference.

View available contract types
  • NFT Drop: "nft-drop"
  • Signature Drop: "signature-drop"
  • Edition Drop: "edition-drop"
  • NFT Collection: "nft-collection"
  • Edition: "edition"
  • Multiwrap: "multiwrap"
  • Pack: "pack"
  • Token Drop: "token-drop"
  • Token: "token"
  • Marketplace: "marketplace" | "marketplace-v3"
  • Split: "split"
  • Vote: "vote"

When a contract type is provided, the contract object will be typed as the contract's class. For example, if you provide the contract type pack, the contract object will be returned typed as an instance of the Pack class, unlocking all of the top-level functions specific to the pack.

const { contract, isLoading, error } = useContract(
"{{contract_address}}",
"contract-type",
);