Source: Full executable TypeScript in contract/src/examples/04-event-monitoring/. This page summarizes the flow — read the source for complete per-step code.
The Story
ArtFund’s product team is building an analytics dashboard for their platform. They need to show platform operators and campaign creators a live view of everything happening on-chain — new campaigns launching, backers pledging, refunds being claimed, and funds being withdrawn. The dashboard has two layers:- A historical data layer that loads past events when the page first opens (e.g., “show me every campaign created since launch”)
- A real-time layer that subscribes to new events as they happen on-chain and updates the UI instantly
Role Reference
All event queries are read-only and can be called by anyone — no wallet or private key is required.Steps
Step 1: Historical Campaign Events
When ArtFund’s dashboard loads for the first time, it queries the CampaignInfoFactory for all historicalCampaignCreated events. In production, store the last synced block number and only fetch new events on subsequent loads.
Step 2: Treasury-Specific Events
Each treasury emits events for every financial action — pledges, refunds, withdrawals — building a detailed activity feed per campaign.Step 3: Real-Time Watchers
After loading historical data, ArtFund subscribes to live events so the dashboard updates instantly as new activity happens. Watchers use WebSocket connections under the hood and fire a callback every time a matching event is emitted. Each watcher returns anunwatch function that should be called on component unmount.
Step 4: Decode Raw Logs
When you receive raw log data from a transaction receipt or an external indexer (like The Graph), use the SDK’sdecodeLog method on any entity’s events object. It returns a typed event with the event name and decoded arguments — no manual ABI parsing.
Step 5: Metrics Aggregation
For high-level dashboard statistics — total platforms, campaign health, treasury financials — the SDK provides a dedicated metrics module with pre-built aggregation functions. It is imported from a separate subpath:@oaknetwork/contracts-sdk/metrics.