Skip to content
LogoLogo

Watch Blocked Transfers

receivePolicy.watchBlocked

Watches for blocked transfer events.

Usage

import {  } from './viem.config'
 
const  = ..()
 
.(() => {
  for (const  of ) .(.)
{ token: '0x20c0000000000000000000000000000000000001', receiver: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb', blockedNonce: 1n, amount: 1000000n, receiptVersion: 1, receipt: '0x1234' }
})
 
// Later, tear down the watcher.
.()

Also callable standalone: Actions.receivePolicy.watchBlocked(client, options), with Actions imported from 'viem/tempo'.

Recipes

Auto-Claim Blocked Deposits

Filter args.receiver to your account and release each blocked payment with receivePolicy.claimSync as it lands. The account must be the policy's configured claimer.

import {  } from './viem.config'
 
const  = ..({
  : { : .. },
})
 
.(async () => {
  for (const  of )
    await ..({
      : ..,
      : ..,
    })
})

Backfill Missed Events After Downtime

Pass fromBlock to replay TransferBlocked events your indexer missed. Persist each claim receipt: it is the only way to claim or burn the funds later.

import {  } from './viem.config'
 
const  = new <bigint, `0x${string}`>()
 
// Resume from the last block the indexer processed.
const  = ..({
  : 1_284_000n,
})
 
.(() => {
  for (const  of ) .(.., ..)
})

Return Value

Returns a watcher handle. Watching starts when the first listener (or async iterator) attaches, and stops when off is called.

type ReturnType = {
  /** Registers a log listener. Starts the watcher on first registration. Returns an unregister function. */
  onLogs: (fn: (logs: readonly Log[]) => void) => () => void
  /** Registers an error listener. Returns an unregister function. */
  onError: (fn: (error: Error) => void) => () => void
  /** Tears down the watcher: removes listeners, ends iterators, stops the poll or subscription. */
  off: () => void
  /** Async-iterates emitted log batches (latest-only stream). */
  [Symbol.asyncIterator]: () => AsyncIterableIterator<{ logs: readonly Log[] }>
}

Each log is decoded, with the event arguments on args:

type Log = {
  /** Decoded `TransferBlocked` event arguments. */
  args: {
    token: Address
    receiver: Address
    blockedNonce: bigint
    amount: bigint
    receiptVersion: number
    receipt: Hex
  }
  /** Name of the emitted event. */
  eventName: 'TransferBlocked'
  // ...standard log fields (address, blockHash, blockNumber, logIndex, transactionHash, ...)
}

Parameters

args

  • Type: object
type Args = {
  token?: Address | Address[] | null
  receiver?: Address | Address[] | null
  blockedNonce?: bigint | bigint[] | null
}

Indexed argument values to filter logs by.

batch

  • Type: boolean
  • Default: true

Whether to batch the logs found within a poll interval into a single emission. When false, each log is emitted on its own.

fromBlock

  • Type: bigint

Block number from which to start watching for logs.

poll

  • Type: boolean

Whether to poll for new logs instead of using a subscription. Defaults to true when the transport cannot subscribe or fromBlock is provided.

pollingInterval

  • Type: number
  • Default: client.pollingInterval

Polling frequency (in ms).