Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Webhooks & events · Boson Protocol
Skip to content

Webhooks & events

Marketplace operators need to react to on-chain state changes — a new offer, a commit on a listed offer, a dispute, a redemption. Three eventing surfaces are available; see Concepts → Eventing & indexing for the canonical reference.

A simple webhook listener (RPC)

import { ethers } from "ethers"
import offerAbi from "@bosonprotocol/common/dist/cjs/abis/IBosonOfferHandler.json"
import exchangeAbi from "@bosonprotocol/common/dist/cjs/abis/IBosonExchangeHandler.json"
import disputeAbi from "@bosonprotocol/common/dist/cjs/abis/IBosonDisputeHandler.json"
 
const diamond = new ethers.Contract(DIAMOND_ADDRESS, [...offerAbi, ...exchangeAbi, ...disputeAbi], provider)
 
const handlers: Record<string, (args: any) => Promise<void>> = {
  OfferCreated: async (args) => postToCRM("offer_created", args),
  BuyerCommitted: async (args) => postToCRM("buyer_committed", args),
  VoucherRedeemed: async (args) => postToCRM("voucher_redeemed", args),
  DisputeRaised: async (args) => postToCRM("dispute_raised", args),
}
 
for (const [evt, fn] of Object.entries(handlers)) {
  diamond.on(evt, (...args) => fn(args))
}

Reorg-safe pattern

1. Receive event
2. dedupe = `${txHash}:${logIndex}`
3. if (alreadyProcessed(dedupe)) return
4. wait N confirmations  // 2-3 L2, 12+ L1
5. process
6. mark processed

See Recipes → Webhook server for a full implementation.

Subgraph polling

For lower-volume use cases, poll the subgraph every 30s:

setInterval(async () => {
  const newOffers = await sdk.getOffers({
    where: { createdAt_gt: lastSeenCreatedAt.toString() },
    orderBy: "createdAt",
    orderDirection: "asc",
  })
  for (const o of newOffers) await process(o)
  lastSeenCreatedAt = newOffers.at(-1)?.createdAt ?? lastSeenCreatedAt
}, 30_000)

Critical events for marketplace operators

EventReason to listen
OfferCreatedIndex for search; notify followers of seller
OfferVoidedRemove from search; refund pending displays
BuyerCommittedUpdate inventory; notify seller; award protocol-agent fee
VoucherRedeemedTrigger fulfillment; close pre-order list
DisputeRaisedPause inventory; surface support flow
ExchangeCompletedUpdate reputation / score; close order

Next