getTransaction
Returns a transaction by its Safe transaction hash or Ethereum transaction hash.
Usage
_20import { useSafe } from '@safe-global/safe-react-hooks'_20_20function TransactionStatus({ safeTxHash, ethereumTxHash }) {_20 const { getTransaction } = useSafe()_20 const {_20 data,_20 // ..._20 } = getTransaction({_20 safeTxHash // Optional_20 // ethereumTxHash // Optional_20 })_20_20 return (_20 <>_20 {data && JSON.stringify(data)}_20 </>_20 )_20}_20_20export default TransactionStatus
Parameters
UseTransactionParams
Parameters to customize the hook behavior. Either safeTxHash
or ethereumTxHash
must be provided.
_10import { UseTransactionParams } from '@safe-global/safe-react-hooks'
safeTxHash
(Optional)
- Type:
string
Hash of the Safe transaction to be fetched.
_10const result = getTransaction({_10 safeTxHash: '0x...'_10})
ethereumTxHash
(Optional)
- Type:
string
Hash of the Ethereum transaction to be fetched.
_10const result = getTransaction({_10 ethereumTxHash: '0x...'_10})
config
(Optional)
- Type:
SafeConfig
The configuration used instead of the one from the nearest SafeProvider
.
_10import { config } from './config.ts'_10_10const result = getTransaction({_10 safeTxHash: '0x...',_10 config_10})
Returns
UseTransactionReturnType<Params>
_10import { UseTransactionReturnType } from '@safe-global/safe-react-hooks'
TanStack Query documentation (opens in a new tab)
data
- Type:
SafeMultisigTransactionResponse
(opens in a new tab) |UseTransactionReturnTypeWagmi
(opens in a new tab) - Default:
undefined
The last successfully resolved data for the query.
If safeTxHash
is provided, it returns the SafeMultisigTransactionResponse
(opens in a new tab) type.
If ethereumTxHash
is provided, it returns the UseTransactionReturnTypeWagmi
(opens in a new tab) type.
dataUpdatedAt
- Type:
number
The timestamp for when the query most recently returned the status
as 'success'
.
error
- Type:
null | TError
- Default:
null
The error object for the query, if an error was thrown.
errorUpdatedAt
- Type:
number
The timestamp for when the query most recently returned the status
as 'error'
.
errorUpdateCount
- Type:
number
The sum of all errors.
failureCount
- Type:
number
The failure count for the query.
Incremented every time the query fails.
Reset to 0
when the query succeeds.
failureReason
- Type:
null | TError
The failure reason for the query retry.
Reset to null
when the query succeeds.
fetchStatus
- Type:
'fetching' | 'idle' | 'paused'
fetching
Is true whenever the queryFn
is executing, which includes initial pending as well as background refetches.
paused
The query wanted to fetch, but has been paused.
idle
The query is not fetching.
See Network Mode (opens in a new tab) for more information.
isError
/ isPending
/ isSuccess
- Type:
boolean
The boolean variables derived from status
.
isFetched
- Type:
boolean
Will be true if the query has been fetched.
isFetchedAfterMount
- Type:
boolean
Will be true
if the query has been fetched after the component mounted.
This property can be used to not show any previously cached data.
isFetching
/ isPaused
- Type:
boolean
The boolean variables derived from fetchStatus
.
isLoading
- Type:
boolean
Is true
whenever the first fetch for a query is in-flight.
Is the same as isFetching && !isPending
.
isLoadingError
- Type:
boolean
Will be true
if the query failed while fetching for the first time.
isPlaceholderData
- Type:
boolean
Will be true
if the data shown is the placeholder data.
isRefetchError
- Type:
boolean
Will be true
if the query failed while refetching.
isRefetching
- Type:
boolean
Is true
whenever a background refetch is in-flight, which does not include initial 'pending'
.
Is the same as isFetching && !isPending
.
isStale
- Type:
boolean
Will be true
if the data in the cache is invalidated or if the data is older than the given staleTime
.
refetch
- Type:
(options: { throwOnError: boolean, cancelRefetch: boolean }) => Promise<UseQueryResult>
A function to manually refetch the query.
throwOnError
- When set to
true
, an error will be thrown if the query fails. - When set to
false
, an error will be logged if the query fails.
- When set to
cancelRefetch
- When set to
true
, a currently running request will be cancelled before a new request is made. - When set to
false
, no refetch will be made if there is already a request running. - Defaults to
true
- When set to
status
- Type:
'error' | 'pending' | 'success'
pending
if there's no cached data and no query attempt was finished yet.
error
if the query attempt resulted in an error. The corresponding error
property has the error received from the attempted fetch.
success
if the query has received a response with no errors and is ready to display its data. The corresponding data
property on the query is the data received from the successful fetch or if the query's enabled
property is set to false
and has not been fetched yet data
is the first initialData
supplied to the query on initialization.