Skip to content

watchDidFill

The watchDidFill waits for an order to be filled on the destination chain. This involves waiting for a Filled event to be emitted on the destination outbox contract, and returns the destination transaction hash.

Usage

import { watchDidFill } from '@omni-network/core'

import { watchDidFill } from '@omni-network/core'
 
const { unwatch, status, destTxHash } = await watchDidFill({
  // ... params
});

Parameters

PropTypeRequiredDescription
clientClientYesChain ID of the destination chain (where the action occurs and the expense is spent on behalf of the user).
outboxAddressnumberYesThe address of the inbox contract, retrieved using the getContracts function.
orderId0x${string}YesOrder identifier defined on a ResolvedOrder
onLogs(logs: Log[]) => voidYesCallback that'll be invoked with the logs of the Filled event.
pollingIntervalnumberNoPolling interval in milliseconds, defaults to the client polling interval.
onError(error: Error) => voidNoOptional callback that'll be invoked when an error occurs.

Return

watchDidFill returns three values:

status

Describes the state of the watch API.

'pending' | 'filled' | 'idle'

destTxHash

The transaction hash on the destination chain that fills the order.

`Hex` | `0x${string}`

unwatch

Terminates watching of contract events.

() => void

Example

import {watchDidFill } from '@omni-network/core'
 
const { unwatch, status, destTxHash } = await watchDidFill({
  client: viemWalletClient,
  outboxAddress: contracts.outbox,
  orderId: resolvedOrder.orderId,
  onLogs: (logs) => {
    console.log('Filled event found:', logs[0].transactionHash)
  },
})
 
// Stop watching for the Filled event
unwatch()