watchPendingTransactions
Watches and returns pending transaction hashes.
This Action will batch up all the pending transactions found within the pollingInterval, and invoke them via onTransactions.
Usage
import { } from './client'
const = .(
{ : => .() }
)
> ['0x...', '0x...', '0x...', ...]Returns
UnwatchFn
A function that can be invoked to stop watching for new pending transaction hashes.
Parameters
onTransactions
- Type:
(hashes: '0x${string}'[]) => void
The new pending transaction hashes.
const = .(
{ : => .() }
)batch (optional)
- Type:
boolean - Default:
true
Whether or not to batch the transaction hashes between polling intervals.
const = .(
{
: false,
: => .(),
}
)onError (optional)
- Type:
(error: Error) => void
Error thrown from listening for new pending transactions.
const = .(
{
: => .(),
: => .(),
}
)poll (optional)
- Type:
boolean - Default:
falsefor WebSocket Clients,truefor non-WebSocket Clients
Whether or not to use a polling mechanism to check for new pending transactions instead of a WebSocket subscription.
This option is only configurable for Clients with a WebSocket Transport.
import { , } from 'viem'
import { } from 'viem/chains'
const = ({
: ,
: ()
})
const = .(
{
: => .(),
: true,
}
)pollingInterval (optional)
- Type:
number
Polling frequency (in ms). Defaults to the Client's pollingInterval config.
const = .(
{
: 1_000,
: => .(),
}
)JSON-RPC Methods
- When
poll: true- Calls
eth_newPendingTransactionFilterto initialize the filter. - Calls
eth_getFilterChangeson a polling interval.
- Calls
- When
poll: false& WebSocket Transport, uses a WebSocket subscription viaeth_subscribeand the"newPendingTransactions"event.