How to Read These Examples
Each scenario in the source repo contains:- A README.md with the story, the roles involved, and a summary of each step
- Numbered TypeScript files (
01-...,02-...) that you can read top-to-bottom like a tutorial
Multi-token ERC-20 support
Oak is multi-token:GlobalParams stores currencyToTokens — seeded in initialize(currencies, tokensPerCurrency), then maintained by the protocol owner with addTokenToCurrency / removeTokenFromCurrency, readable via getTokensForCurrency(currency). Campaign creation copies that list onto CampaignInfo; treasuries check isTokenAccepted on every pledgeToken / paymentToken. In code, use globalParams.getTokensForCurrency(...) or campaign.getAcceptedTokens() to populate wallet UIs or validation. Balances, fees, refunds, and raised-amount reads are per token address, in native decimals (normalized where the protocol aggregates across tokens).
The numbered examples use one stablecoin (e.g. USDC) so the files stay easy to read. In production, swap in any address from your campaign’s accepted-token list and match decimals when you build amounts.
Quick Start
Every example imports from@oaknetwork/contracts-sdk. The shared setup file shows the common client setup pattern used across all examples.
Roles
Four roles appear throughout these examples. Understanding who does what is key to following each scenario:| Role | Who they are | What they do |
|---|---|---|
| Protocol Admin | The Oak Network team | Enlists new platforms, approves treasury implementations, governs global protocol parameters |
| Platform Admin | The operations team running a platform (e.g., an e-commerce site or crowdfunding portal) | Registers treasury models, configures fees and line items, confirms and cancels payments |
| Campaign Creator | A user who launches a campaign on a platform (e.g., an artist, a startup founder) | Creates campaigns, deploys treasuries, adds reward tiers, withdraws raised funds |
| Backer / Buyer | A user who supports a campaign or makes a purchase | Pledges for rewards, processes crypto payments, claims refunds if eligible |
Platform OnboardingPlatform Onboarding is a coordinated process between the Protocol Admin and the Platform Admin. See Platform Enlistment for the complete walkthrough, or contact support@oaknetwork.org to get started.
Scenario Overview
| # | Scenario | What you will learn |
|---|---|---|
| 0 | Platform Enlistment | How a new platform joins Oak Protocol — enlistment, treasury registration, approval, plus optional configuration (line items, claim delay, data keys, adapter) |
| 1 | All-or-Nothing Campaign | Full crowdfunding lifecycle with a funding goal — success path and failure path |
| 2 | Keep-What’s-Raised Campaign | Flexible funding with mid-campaign withdrawals, tips, and configurable fees |
| 3 | Payment Treasury Flow | E-commerce payment flow with line items, confirmations, and refunds |
| 4 | Event Monitoring | Building dashboards with historical logs, real-time watchers, and metrics |
| 5 | Error Handling | Simulating transactions, catching typed errors, and safe send patterns |
| 6 | Advanced Patterns | Multicall batching, signer overrides, item registry, and protocol configuration |