> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oaknetwork.org/llms.txt
> Use this file to discover all available pages before exploring further.

# 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.

<Tip>
  **Getting started**

  You need deployed contract addresses and testnet access. Contact [support@oaknetwork.org](mailto:support@oaknetwork.org) to begin your onboarding.
</Tip>

## 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](/contracts-sdk/examples/platform-enlistment) if you are a new platform joining Oak Protocol. Start with [All-or-Nothing](/contracts-sdk/examples/all-or-nothing-campaign) or [Keep-What's-Raised](/contracts-sdk/examples/keep-whats-raised-campaign) 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.

```typescript theme={null}
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:

| 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                   |

<Info>
  **Platform Onboarding**

  Platform Onboarding is a coordinated process between the Protocol Admin and the Platform Admin. See [Platform Enlistment](/contracts-sdk/examples/platform-enlistment) for the complete walkthrough, or contact [support@oaknetwork.org](mailto:support@oaknetwork.org) to get started.
</Info>

## Scenario Overview

| # | Scenario                                                                          | What you will learn                                                                                                                                            |
| - | --------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 0 | [Platform Enlistment](/contracts-sdk/examples/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](/contracts-sdk/examples/all-or-nothing-campaign)        | Full crowdfunding lifecycle with a funding goal — success path and failure path                                                                                |
| 2 | [Keep-What's-Raised Campaign](/contracts-sdk/examples/keep-whats-raised-campaign) | Flexible funding with mid-campaign withdrawals, tips, and configurable fees                                                                                    |
| 3 | [Payment Treasury Flow](/contracts-sdk/examples/payment-treasury-flow)            | E-commerce payment flow with line items, confirmations, and refunds                                                                                            |
| 4 | [Event Monitoring](/contracts-sdk/examples/event-monitoring)                      | Building dashboards with historical logs, real-time watchers, and metrics                                                                                      |
| 5 | [Error Handling](/contracts-sdk/examples/error-handling)                          | Simulating transactions, catching typed errors, and safe send patterns                                                                                         |
| 6 | [Advanced Patterns](/contracts-sdk/examples/advanced-patterns)                    | Multicall batching, signer overrides, item registry, and protocol configuration                                                                                |
