Skip to main content

Contracts SDK

The @oaknetwork/contracts package is a TypeScript SDK for interacting with Oak Network smart contracts. It provides a type-safe client with full read/write access to all Oak protocol contracts, built on top of viem.

Testnet first

Start by pointing the SDK at Celo Sepolia testnet (CHAIN_IDS.CELO_TESTNET_SEPOLIA) to experiment without risking real funds.

Deployed addresses

You need deployed contract addresses to use this SDK — including factory addresses (for example CampaignInfoFactory, TreasuryFactory) and any protocol contracts you call through the client. The SDK interacts with Oak Network smart contracts that must already be deployed on-chain. To get your contract addresses and sandbox environment access, contact our team at support@oaknetwork.org.

Highlights

  • Flexible signers — simple keyed client, read-only RPC client, per-entity or per-call signer overrides, or full viem PublicClient / WalletClient setup (see Client Configuration)
  • Entity factories for every on-chain contract: oak.globalParams(address), oak.campaignInfo(address), etc.
  • Typed reads, writes, and simulations — every method is fully typed with TypeScript
  • Typed error decodingparseContractError() turns raw revert data into SDK errors with recovery hints
  • Pure utility exports — hashing, encoding, time helpers, and chain resolution with zero client dependency
  • Tree-shakeable entry points — import only what you need: @oaknetwork/contracts/utils, @oaknetwork/contracts/client, etc.

Quick example

import { createOakContractsClient, CHAIN_IDS, keccak256, toHex } from '@oaknetwork/contracts';

const oak = createOakContractsClient({
chainId: CHAIN_IDS.CELO_TESTNET_SEPOLIA,
rpcUrl: 'https://forno.celo-sepolia.celo-testnet.org',
privateKey: '0x...',
});

const gp = oak.globalParams('0x...');

const admin = await gp.getProtocolAdminAddress();
const fee = await gp.getProtocolFeePercent();

console.log('Admin:', admin, 'Fee:', fee);

See the full walkthrough in the Quickstart guide.

Contract entities

The SDK ships 8 contract entity modules. Call the factory method on the client to get a typed entity for a deployed contract address.

EntityFactoryWhat it does
GlobalParamsoak.globalParams(address)Protocol-wide configuration registry
CampaignInfoFactoryoak.campaignInfoFactory(address)Deploy new CampaignInfo contracts
CampaignInfooak.campaignInfo(address)Per-campaign configuration and state
TreasuryFactoryoak.treasuryFactory(address)Deploy treasury contracts for campaigns
PaymentTreasuryoak.paymentTreasury(address)Fiat-style payments via a payment gateway
AllOrNothingoak.allOrNothingTreasury(address)Crowdfunding — funds released only if goal is met
KeepWhatsRaisedoak.keepWhatsRaisedTreasury(address)Crowdfunding — creator keeps all funds raised
ItemRegistryoak.itemRegistry(address)Manage items available for purchase in campaigns

Entry points

Import pathContents
@oaknetwork/contractsEverything — client, types, utils, errors
@oaknetwork/contracts/clientcreateOakContractsClient only
@oaknetwork/contracts/contractsContract entity factories only
@oaknetwork/contracts/utilsUtility functions only (no client)
@oaknetwork/contracts/errorsError classes and parseContractError only

Next up