Skip to content
Docs
/
Hooks
/
useContract

useContract

Hook for declaratively creating an ethers.js Contract instance.

import { useContract } from 'wagmi'
💡

If needing to invoke a read or write method from a contract, it is recommended to use useContractRead or useContractWrite instead of imperatively calling the function.

Usage

The following examples use the ENS Registry Contract.

import { useContract } from 'wagmi'

function App() {
  const contract = useContract({
    addressOrName: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
    contractInterface: ensRegistryABI,
  })
}

Return Values

ethers.Contract

Configuration

addressOrName

Contract address or ENS name.

import { useContract } from 'wagmi'

function App() {
  const contract = useContract({
    addressOrName: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
    contractInterface: ensRegistryABI,
  })
}

contractInterface

Contract ABI in JSON or JS object format. An ethers.js Interface is also allowed.

import { useContract } from 'wagmi'

function App() {
  const contract = useContract({
    addressOrName: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
    contractInterface: ensRegistryABI,
  })
}

signerOrProvider (optional)

An ethers.js Provider or Signer.

import { useContract, useProvider } from 'wagmi'

function App() {
  const provider = useProvider()
  const contract = useContract({
    addressOrName: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
    contractInterface: ensRegistryABI,
    signerOrProvider: provider,
  })
}