waitForTransactionReceipt
Action 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
ts
import { waitForTransactionReceipt } from '@wagmi/core'
Usage
ts
import { waitForTransactionReceipt } from '@wagmi/core'
import { config } from './config'
const transactionReceipt = waitForTransactionReceipt(config, {
hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
Parameters
ts
import { type WaitForTransactionReceiptParameters } from '@wagmi/core'
chainId
config['chains'][number]['id'] | undefined
ID of chain to use when fetching data.
ts
import { waitForTransactionReceipt } from '@wagmi/core'
import { mainnet } from '@wagmi/core/chains'
import { config } from './config'
const transactionReceipt = await waitForTransactionReceipt(config, {
chainId: mainnet.id,
hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
confirmations
number | undefined
The number of confirmations (blocks that have passed) to wait before resolving.
ts
import { waitForTransactionReceipt } from '@wagmi/core'
import { config } from './config'
const transactionReceipt = await waitForTransactionReceipt(config, {
confirmations: 2,
hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
onReplaced
(({ reason: 'replaced' | 'repriced' | 'cancelled'; replacedTransaction: Transaction; transaction: Transaction; transactionReceipt: TransactionReceipt }) => void) | undefined
Optional callback to emit if the transaction has been replaced.
ts
import { waitForTransactionReceipt } from '@wagmi/core'
import { config } from './config'
const transactionReceipt = await waitForTransactionReceipt(config, {
hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
onReplaced: replacement => console.log(replacement),
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
hash
`0x${string}`
The transaction hash to wait for.
ts
import { waitForTransactionReceipt } from '@wagmi/core'
import { config } from './config'
const transactionReceipt = await waitForTransactionReceipt(config, {
hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
pollingInterval
number | undefined
- Polling frequency (in milliseconds).
- Defaults to the Config's
pollingInterval
config.
ts
import { waitForTransactionReceipt } from '@wagmi/core'
import { config } from './config'
const transactionReceipt = await waitForTransactionReceipt(config, {
hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
pollingInterval: 1_000,
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
Return Type
ts
import { type WaitForTransactionReceiptReturnType } from '@wagmi/core'
The transaction receipt.
Error
ts
import { type WaitForTransactionReceiptErrorType } from '@wagmi/core'
TanStack Query
ts
import {
type WaitForTransactionReceiptData,
type WaitForTransactionReceiptOptions,
type WaitForTransactionReceiptQueryFnData,
type WaitForTransactionReceiptQueryKey,
waitForTransactionReceiptQueryKey,
waitForTransactionReceiptQueryOptions,
} from '@wagmi/core/query'