Skip to content

useContractWrite

Hook for calling a Contract write method.

import { useContractWrite } from 'wagmi'

Usage

The following examples use the WAGMIGOTCHI Contract.

import { useContractWrite } from 'wagmi'

const App = () => {
  const [{ data, error, loading }, write] = useContractWrite(
    {
      addressOrName: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
      contractInterface: wagmigotchiABI,
    },
    'feed',
  )

  return ...
}

Return Values

result

{
  data?: TransactionResponse
  error?: Error
  loading?: boolean
}

write

(
  config: {
    args: any | any[]
    overrides?: Overrides
  } = {},
) => Promise<{ data?: TransactionResponse; error?: Error }>

Arguments

contractConfig

See useContract for more info.

functionName

Name of function to call.

import { useContractWrite } from 'wagmi'

const App = () => {
  const [{ data, error, loading }, write] = useContractWrite(
    {
      addressOrName: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
      contractInterface: wagmigotchiABI,
    },
    'sleep',
  )

  return ...
}

Configuration

args (optional)

Arguments to pass to function call. Accepts any | any[].

import { useContractWrite } from 'wagmi'

const App = () => {
  const [{ data, error, loading }, write] = useContractWrite(
    {
      addressOrName: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
      contractInterface: wagmigotchiABI,
    },
    'feed',
    {
      args: [],
    }
  )

  return ...
}

overrides (optional)

Overrides to pass to function call.

import { useContractWrite } from 'wagmi'

const App = () => {
  const [{ data, error, loading }, write] = useContracWrite(
    {
      addressOrName: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
      contractInterface: wagmigotchiABI,
    },
    'feed',
    {
      overrides: { from: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e' }
    }
  )

  return ...
}