Order Fill Listener

Typescript examples use ethersjs v6.

Full example script is available listen_fill.ts.


This example listens for OrderFill events emitted from the OrderProcessor contract using a websocket connection.

This example can be expanded to include listeners for other types of events, including OrderCancelled and OrderFulfilled which represent final states that close out the order request.

After an ethers provider has been created using the websocket RPC URL, an event filter is created to listen for OrderFill events pertaining to a specific account. Then, the process waits for matching events.

// ------------------ Listen ------------------

// fill event filter for a specific account
const filter = orderProcessor.filters.OrderFill(null, requester);

// listen for fill events
await orderProcessor.on(filter, (event: ethers.ContractEventPayload) => {
  const [orderId, requesterAccount, fillAmount, receivedAmount, feesPaid] = event.args;
  console.log(`Account ${requesterAccount} Order ${orderId} filled for ${fillAmount}, received ${receivedAmount}, paid ${feesPaid}`);

Last updated