useContract
Hook for declaratively creating an ethers 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 Value
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 Interface is also allowed.
import { useContract } from 'wagmi'
function App() {
const contract = useContract({
addressOrName: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
contractInterface: ensRegistryABI,
})
}
signerOrProvider (optional)
import { useContract, useProvider } from 'wagmi'
function App() {
const provider = useProvider()
const contract = useContract({
addressOrName: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
contractInterface: ensRegistryABI,
signerOrProvider: provider,
})
}