• Core
  • Actions
  • waitForTransaction

waitForTransaction

Action for declaratively waiting until transaction is processed. Pairs well with writeContract and sendTransaction.

import { waitForTransaction } from '@wagmi/core'

Usage

import { waitForTransaction } from '@wagmi/core'
 
const data = await waitForTransaction({
  hash: '0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060',
})

Return Value

TransactionReceipt

Configuration

hash

Transaction hash to monitor. Works well with writeContract and sendTransaction.

import {
  prepareWriteContract,
  waitForTransaction,
  writeContract,
} from '@wagmi/core'
 
const { config } = await prepareWriteContract({
  address: '0xecb504d39723b0be0e3a9aa33d646642d1051ee1',
  abi: wagmigotchiABI,
  functionName: 'feed',
})
const { hash } = await writeContract(config)
const data = await waitForTransaction({
  hash,
})

chainId (optional)

Force a specific chain id for waiting on transaction. The wagmi Client's ethers provider must be set up as a chain-aware function for this to work correctly.

import { waitForTransaction } from '@wagmi/core'
 
const waitForTransaction = await waitForTransaction({
  chainId: 1,
  hash: '0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060',
})

confirmations (optional)

Waits until confirmations number of blocks are mined on top of the block containing the transaction. Defaults to 1. If confirmations is 0, action will not wait and return immediately without blocking, likely resulting in data being null.

import { waitForTransaction } from '@wagmi/core'
 
const waitForTransaction = await waitForTransaction({
  confirmations: 1,
  hash: '0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060',
})

onSpeedUp (optional)

Callback to invoke when the transaction has been sped up (replaced with higher gas fee values).

import { waitForTransaction } from '@wagmi/core'
 
const waitForTransaction = await waitForTransaction({
  hash: '0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060',
  onSpeedUp: (transaction) => console.log(transaction),
})

timeout (optional)

Maximum amount of time to wait before timing out in milliseconds. Defaults to 0 (will wait until transaction processes).

import { waitForTransaction } from '@wagmi/core'
 
const waitForTransaction = await waitForTransaction({
  hash: '0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060',
  timeout: 2_000, // 2 seconds
})