Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Hooks

Every txKit component is built on a public headless hook. Hooks are exported from the package root - import everything from @txkit/react. There are no subpath exports.

Index

HookReturnsDocumented in
useTxKitResolved config + theme + Pro flagTxKitProvider - useTxKit
useWalletStateWallet state machineConnectWallet - useWalletState
useDisplayUriWalletConnect QR pairing URIBelow
useTokenBalanceSingle token balanceTokenBalance - useTokenBalance
useTokenBalancesMulti-token batch via multicallTokenBalance - useTokenBalances
useTokenPriceFiat price (DeFiLlama + forex)TokenBalance - useTokenPrice
useTransactionFlowMulti-step flow state + actionsTransactionButton - Tier 3 hook
useFlowStateFlow entry by flowIdBelow
useFlowStoreRaw flow store handleBelow
useBalanceInvalidationManual balance refreshBelow
useBalanceContextBalanceWatcher context valueBelow

useDisplayUri

WalletConnect-only. Captures the pairing URI emitted asynchronously by the WC connector after connect() is called, so you can render a QR code or copy a deep link before the wallet pairs.

import { useDisplayUri } from '@txkit/react'
 
const { displayUri, isLoadingUri } = useDisplayUri(connector, isPending)
ParamTypeDescription
connectorConnector | undefinedThe WC connector currently in pending state
isPendingbooleanTrue while connect is in flight - hook resets URI when this drops
ReturnsTypeDescription
displayUristring | undefinedWC pairing URI, e.g. wc:abc123@2?... - render to QR or copy
isLoadingUribooleanTrue between connect() call and display_uri event

The URI is one-shot - after pairing, displayUri becomes undefined. The hook reads connector.emitter (a wagmi runtime property), so it returns undefined for connectors that don't emit display_uri (injected, Coinbase Wallet) - no error, just falsy values.

useFlowState

Subscribes to a single flow entry from the flow store. Place anywhere inside TxKitProvider - powers FlowSteps, FlowProgress, and FlowToast under the hood.

import { useFlowState, DEFAULT_FLOW_ID } from '@txkit/react'
 
const entry = useFlowState() // defaults to DEFAULT_FLOW_ID
 
if (!entry) {
  return null
}
 
const { flow, steps, actions } = entry
return <pre>{flow.status} - step {flow.currentStepIndex} of {steps.length}</pre>
ParamTypeDefault
flowIdstringDEFAULT_FLOW_ID ('__default__')
ReturnsTypeDescription
entryFlowEntry | undefinedundefined if no TransactionButton with this flowId is mounted

FlowEntry shape: { flow: FlowState; steps: FlowStep[]; actions: FlowActions }. Use useTransactionFlow directly when you want the headless hook (you own the steps array). Use useFlowState when you're building a sibling visualizer that just observes whatever TransactionButton mounted.

useFlowStore

Raw access to the flow store handle. Returns null when used outside TxKitProvider. Power-user tool for registering custom flows or implementing your own compound components.

import { useFlowStore } from '@txkit/react'
 
const store = useFlowStore()
const allFlows = store ? Array.from(store.entries.entries()) : []

The flow store uses useSyncExternalStore semantics - direct mutations on store.entries will not trigger re-renders. Use setFlowEntry and notifyFlowListeners (also exported) for that.

useBalanceInvalidation

Manual refresh of TanStack Query balance caches. Use after operations that change balances outside of txKit's awareness - external bridges, faucet funding, manual wagmi writeContract calls.

import { useBalanceInvalidation } from '@txkit/react'
 
const { invalidateAll, invalidateAffected } = useBalanceInvalidation()
 
// After a faucet drip
invalidateAll()
 
// After a custom tx whose receipt logs you have
invalidateAffected(receipt.logs, senderAddress)
ReturnsTypeDescription
invalidateAll() => voidInvalidates every ['balance'] and ['readContracts'] query - simple but coarse
invalidateAffected(logs, sender) => voidSurgical: parses Transfer / Deposit / Withdrawal logs and invalidates only the matching (address, token) tuples

useTransactionFlow calls invalidateAffected automatically after each step completes - you only need this hook for balance changes that happen outside the flow.

useBalanceContext

Read access to the BalanceWatcher context value. BalanceWatcher is the invisible component inside TxKitProvider that watches useWatchBlockNumber and throttles balance-query invalidations on new blocks (configurable via config.blockWatching.{ enabled, throttleMs }). It is also gated by useActiveBrowserTab - background tabs do not invalidate.

import { useBalanceContext } from '@txkit/react'
 
const balanceCtx = useBalanceContext()
 
if (balanceCtx) {
  console.log('Last block:', balanceCtx.lastBlockNumber)
  balanceCtx.invalidateBalance(myAddress, USDC_ADDRESS)
}
ReturnsTypeDescription
null-When called outside TxKitProvider (graceful degradation, no throw)
lastBlockNumberbigint | undefinedMost recent block observed by the watcher
invalidateBalance(address, token?) => voidInvalidate cached balance for one (address, token) pair. Omit token for native
invalidateAllBalances() => voidInvalidate everything BalanceWatcher tracks

This is the lowest-level hook - prefer useBalanceInvalidation for app code, prefer useTokenBalance for rendering. Reach for useBalanceContext only when building a custom block-aware component.

See also