clawchain/wagmi/site/vue/api/composables/useWaitForTransactionReceipt.md

4.3 KiB

title, description
title description
useWaitForTransactionReceipt Composable 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

Composable 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/vue'

Usage

::: code-group

<script setup lang="ts">
import { useWaitForTransactionReceipt } from '@wagmi/vue'

const result = useWaitForTransactionReceipt({
  hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
})
</script>

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

Parameters

import { type WaitForTransactionReceiptParameters } from '@wagmi/core'

chainId

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

ID of chain to use when fetching data.

<script setup lang="ts">
import { useWaitForTransactionReceipt } from '@wagmi/vue'
import { mainnet } from '@wagmi/vue/chains'

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

config

Config | undefined

Config to use instead of retrieving from the WagmiPlugin.

::: code-group

<script setup lang="ts">
import { useWaitForTransactionReceipt } from '@wagmi/vue'
import { config } from './config' // [!code focus]

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

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

confirmations

number | undefined

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

<script setup lang="ts">
import { useWaitForTransactionReceipt } from '@wagmi/vue'

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

onReplaced

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

Optional callback to emit if the transaction has been replaced.

<script setup lang="ts">
import { useWaitForTransactionReceipt } from '@wagmi/vue'

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

pollingInterval

number | undefined

<script setup lang="ts">
import { useWaitForTransactionReceipt } from '@wagmi/vue'

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

hash

`0x${string}` | undefined

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

<script setup lang="ts">
import { useWaitForTransactionReceipt } from '@wagmi/vue'

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

Return Type

import { type UseWaitForTransactionReceiptReturnType } from '@wagmi/vue'

Action