Skip to main content

Examples

Real-world, scenario-driven examples that walk you through every capability of the Oak Contracts SDK. Each scenario tells a story — a platform onboarding, a crowdfunding campaign, an e-commerce checkout — and implements it step by step with working code.

Whether you are a developer integrating Oak into your product or a stakeholder evaluating the protocol, these examples show exactly how the SDK works in practice.

Getting started

You need deployed contract addresses and testnet access. Contact support@oaknetwork.org to begin your onboarding.

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

Start with Platform Enlistment if you are a new platform joining Oak Protocol. Start with All-or-Nothing or Keep-What's-Raised if your platform is already onboarded and you want to launch a campaign.

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.

import { createOakContractsClient, CHAIN_IDS } from "@oaknetwork/contracts-sdk";

const oak = createOakContractsClient({
chainId: CHAIN_IDS.CELO_TESTNET_SEPOLIA,
rpcUrl: process.env.RPC_URL,
privateKey: process.env.PRIVATE_KEY! as `0x${string}`,
});

Then pick a scenario and follow the steps in order.

Roles

Four roles appear throughout these examples. Understanding who does what is key to following each scenario:

RoleWho they areWhat they do
Protocol AdminThe Oak Network teamEnlists new platforms, approves treasury implementations, governs global protocol parameters
Platform AdminThe 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 CreatorA 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 / BuyerA user who supports a campaign or makes a purchasePledges for rewards, processes crypto payments, claims refunds if eligible
Platform Onboarding

Platform 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

#ScenarioWhat you will learn
0Platform EnlistmentHow a new platform joins Oak Protocol — enlistment, treasury registration, approval, plus optional configuration (line items, claim delay, data keys, adapter)
1All-or-Nothing CampaignFull crowdfunding lifecycle with a funding goal — success path and failure path
2Keep-What's-Raised CampaignFlexible funding with mid-campaign withdrawals, tips, and configurable fees
3Payment Treasury FlowE-commerce payment flow with line items, confirmations, and refunds
4Event MonitoringBuilding dashboards with historical logs, real-time watchers, and metrics
5Error HandlingSimulating transactions, catching typed errors, and safe send patterns
6Advanced PatternsMulticall batching, signer overrides, item registry, and protocol configuration