3.5 KiB
title, description
| title | description |
|---|---|
| useTransaction | Hook for fetching transactions given hashes or block identifiers. |
useTransaction
Hook for fetching transactions given hashes or block identifiers.
Import
import { useTransaction } from 'wagmi'
Usage
::: code-group
import { useTransaction } from 'wagmi'
function App() {
const result = useTransaction({
hash: '0x0fa64daeae54e207aa98613e308c2ba8abfe274f75507e741508cc4db82c8cb5',
})
}
<<< @/snippets/react/config.ts[config.ts] :::
Parameters
import { type UseTransactionParameters } from 'wagmi'
blockHash
bigint | undefined
Block hash to get transaction at (with index).
import { useTransaction } from 'wagmi'
function App() {
const result = useTransaction({
blockHash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d', // [!code focus]
index: 0,
})
}
blockNumber
bigint | undefined
Block number to get transaction at (with index).
import { useTransaction } from 'wagmi'
function App() {
const result = useTransaction({
blockNumber: 17829139n, // [!code focus]
index: 0,
})
}
blockTag
'latest' | 'earliest' | 'pending' | 'safe' | 'finalized' | undefined
Block tag to get transaction at (with index).
import { useTransaction } from 'wagmi'
function App() {
const result = useTransaction({
blockTag: 'safe', // [!code focus]
index: 0,
})
}
chainId
config['chains'][number]['id'] | undefined
ID of chain to use when fetching data.
import { useTransaction } from 'wagmi'
import { mainnet } from 'wagmi/chains'
function App() {
const result = useTransaction({
chainId: mainnet.id, // [!code focus]
hash: '0x0fa64daeae54e207aa98613e308c2ba8abfe274f75507e741508cc4db82c8cb5',
})
}
config
Config | undefined
Config to use instead of retrieving from the nearest WagmiProvider.
::: code-group
import { useTransaction } from 'wagmi'
import { config } from './config' // [!code focus]
function App() {
const result = useTransaction({
hash: '0x0fa64daeae54e207aa98613e308c2ba8abfe274f75507e741508cc4db82c8cb5',
config, // [!code focus]
})
}
<<< @/snippets/react/config.ts[config.ts] :::
hash
`0x${string}` | undefined
Hash to get transaction. enabled set to false if hash and index are undefined.
import { useTransaction } from 'wagmi'
function App() {
const result = useTransaction({
hash: '0x0fa64daeae54e207aa98613e308c2ba8abfe274f75507e741508cc4db82c8cb5', // [!code focus]
})
}
index
number | undefined
An index to be used with a block identifier (hash, number, or tag). enabled set to false if index and hash are undefined.
import { useTransaction } from 'wagmi'
function App() {
const result = useTransaction({
blockTag: 'safe',
index: 0 // [!code focus]
})
}
Return Type
import { type UseTransactionReturnType } from 'wagmi'