• Core
  • Actions
  • getContract

getContract

Action for retrieving a type-safe viem Contract Instance.

import { getContract } from '@wagmi/core'

Usage

The following examples use the ENS Registry contract.

import { getContract } from '@wagmi/core'
 
const contract = getContract({
  address: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
  abi: ensRegistryABI,
})

Return Value

GetContractReturnType | null

Configuration

address

Contract address.

import { getContract } from '@wagmi/core'
 
const contract = getContract({
  address: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
  abi: ensRegistryABI,
})

abi

Contract ABI.

By defining inline or adding a const assertion to abi, TypeScript will infer the correct types for properties and methods on the contract object. See the wagmi TypeScript docs for more information.

import { getContract } from '@wagmi/core'
 
const contract = getContract({
  address: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
  abi: ensRegistryABI,
})

walletClient (optional)

A viem Wallet Client with a connected account.

import { getContract, getWalletClient } from '@wagmi/core'
 
const walletClient = await getWalletClient()
const contract = getContract({
  address: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
  abi: ensRegistryABI,
  walletClient,
})