Skip to content
On this page

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

ts
import { publicClient } from '.'
 
const unwatch = publicClient.watchPendingTransactions( 
  { onTransactions: hashes => console.log(hashes) }
)
/**
 * > ['0x...', '0x...', '0x...']
 * > ['0x...', '0x...']
 * > ['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.

ts
const unwatch = publicClient.watchPendingTransactions(
  { onTransactions: hashes => console.log(hashes) } 
)

batch (optional)

  • Type: boolean
  • Default: true

Whether or not to batch the transaction hashes between polling intervals.

ts
const unwatch = publicClient.watchPendingTransactions(
  { 
    batch: false, 
    onTransactions: hashes => console.log(hashes),
  }
)

onError (optional)

  • Type: (error: Error) => void

Error thrown from listening for new pending transactions.

ts
const unwatch = publicClient.watchPendingTransactions(
  { 
    onError: error => console.log(error) 
    onTransactions: hashes => console.log(hashes),
  }
)

pollingInterval (optional)

  • Type: number

Polling frequency (in ms). Defaults to the Client's pollingInterval config.

ts
const unwatch = publicClient..watchPendingTransactions(
  { 
    pollingInterval: 1_000, 
    onTransactions: hashes => console.log(hashes),
  }
)

JSON-RPC Methods

Released under the MIT License.