useContract
Hook for creating declarative ethers.js Contract.
import { useContract } from 'wagmi'
Usage
The following examples use the ENS Registry Contract.
import { useNetwork } from 'wagmi'
const App = () => { const contract = useContract({ addressOrName: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e', contractInterface: ensRegistryABI, })
return ...}
Return Values
ethers.Contract
Configuration
addressOrName
Contract address or ENS name.
import { useNetwork } from 'wagmi'
const App = () => { const contract = useContract({ addressOrName: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e', contractInterface: ensRegistryABI, })
return ...}
contractInterface
Contract ABI in JSON or JS object format. An ethers.js Interface is also allowed.
import { useNetwork } from 'wagmi'
const App = () => { const contract = useContract({ addressOrName: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e', contractInterface: ensRegistryABI, })
return ...}
signerOrProvider (optional)
An ethers.js Provider or Signer.
import { useContract, useProvider } from 'wagmi'
const App = () => { const provider = useProvider() const contract = useContract({ addressOrName: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e', contractInterface: ensRegistryABI, signerOrProvider: provider, })
return ...}