clawchain/wagmi/site/react/api/hooks/useWaitForTransactionReceipt.md

4.2 KiB

title, description
title description
useWaitForTransactionReceipt Hook that waits for the transaction to be included on a block, and then returns the transaction receipt. If the transaction reverts, then the action will throw an error. Replacement detection (e.g. sped up transactions) is also supported.

useWaitForTransactionReceipt

Hook that waits for the transaction to be included on a block, and then returns the transaction receipt. If the transaction reverts, then the action will throw an error. Replacement detection (e.g. sped up transactions) is also supported.

Import

import { useWaitForTransactionReceipt } from 'wagmi'

Usage

::: code-group

import { useWaitForTransactionReceipt } from 'wagmi'

function App() {
  const result = useWaitForTransactionReceipt({
    hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
  })
}

<<< @/snippets/react/config.ts[config.ts] :::

Parameters

import { type UseWaitForTransactionReceiptParameters } from 'wagmi'

chainId

config['chains'][number]['id'] | undefined

ID of chain to use when fetching data.

import { useWaitForTransactionReceipt } from 'wagmi'
import { mainnet } from 'wagmi/chains'

function App() {
  const result = useWaitForTransactionReceipt({
    chainId: mainnet.id, // [!code focus]
    hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
  })
}

config

Config | undefined

Config to use instead of retrieving from the nearest WagmiProvider.

::: code-group

import { useWaitForTransactionReceipt } from 'wagmi'
import { config } from './config' // [!code focus]

function App() {
  const result = useWaitForTransactionReceipt({
    hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
    config, // [!code focus]
  })
}

<<< @/snippets/react/config.ts[config.ts] :::

confirmations

number | undefined

The number of confirmations (blocks that have passed) to wait before resolving.

import { useWaitForTransactionReceipt } from 'wagmi'

function App() {
  const result = useWaitForTransactionReceipt({
    confirmations: 2, // [!code focus]
    hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
  })
}

onReplaced

(({ reason: 'replaced' | 'repriced' | 'cancelled'; replacedTransaction: Transaction; transaction: Transaction; transactionReceipt: TransactionReceipt }) => void) | undefined

Optional callback to emit if the transaction has been replaced.

import { useWaitForTransactionReceipt } from 'wagmi'

function App() {
  const result = useWaitForTransactionReceipt({
    hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
    onReplaced: replacement => console.log(replacement), // [!code focus]
  })
}

pollingInterval

number | undefined

import { useWaitForTransactionReceipt } from 'wagmi'

function App() {
  const result = useWaitForTransactionReceipt({
    hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
    pollingInterval: 1_000, // [!code focus]
  })
}

hash

`0x${string}` | undefined

The transaction hash to wait for. enabled set to false if hash is undefined.

import { useWaitForTransactionReceipt } from 'wagmi'

function App() {
  const result = useWaitForTransactionReceipt({
    hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d', // [!code focus]
  })
}

Return Type

import { type UseWaitForTransactionReceiptReturnType } from 'wagmi'

Action