Skip to main content
These docs track the Aeneid release of @piplabs/cdr-sdk (v0.2.1).

Prerequisites

  • Node.js 18+ and npm 8+
  • Node.js 22+ if you plan to use HeliaProvider
  • A funded wallet on Aeneid testnet
  • viem (v2.21+) for blockchain interactions

Install

viem (v2.21+) is a required peer dependency.
Storage providers are optional and pull their own peer dependencies. Install them only for the backend you use: helia, multiformats, and @helia/unixfs for HeliaProvider, @storacha/client for StorachaProvider, or @filoz/synapse-sdk for SynapseProvider.
If you plan to mint DATA Foundation license tokens in an IP-gated flow, also install @story-protocol/core-sdk.

Initialize WASM

The CDR SDK uses a WebAssembly module for threshold cryptography. You must initialize it once before performing any encryption or decryption operations.
In a React application, initialize WASM in a provider component or top-level effect so it’s ready before any CDR operations are attempted.

Browser and Bundler Guidance

  • Vite / webpack - Import the SDK from normal ESM application code and call initWasm() before the first encryption or decryption. If your SSR build tries to evaluate the SDK server-side, move the import behind a client-only boundary.
  • Next.js / SSR - Keep browser wallet flows in "use client" components. For route handlers or scripts that use CDR cryptography, run them in the Node runtime instead of Edge.
  • Edge runtime - The current release is not documented for Edge runtimes. Prefer the browser or Node.js runtime on Aeneid.
  • TypeScript - Use modern ESM resolution. moduleResolution: "Bundler" is a good default for browser apps; moduleResolution: "NodeNext" fits pure Node ESM projects.

DATA Foundation API REST Endpoint

Every CDRClient requires an apiUrl: the base URL of a DATA Foundation API REST endpoint. The SDK reads all DKG state (active round, global public key, threshold, participant count, registered validators, and validator attestations) over this REST API. Contract state such as vaults and fees is still read over the EVM publicClient.
For production deployments you can point apiUrl at your own Story node’s REST gateway instead of the shared endpoint. Configure it through an environment variable so it is easy to swap.

Create the CDR Client

The CDRClient provides three sub-clients:
  • observer - Read-only queries (fees, vault data, DKG state). Always available.
  • uploader - Encryption and vault allocation. Requires a walletClient.
  • consumer - Decryption and read requests. Requires a walletClient.

In React (Wallet Connector)

In a React app, you typically get the wallet from a connector like Privy, RainbowKit, or wagmi. Create a read-only CDRClient up front, and build a write-capable client on demand from the wallet’s provider.
hooks/use-cdr-client.ts
Then in your components:

With Private Key (Backend / Scripts)

For server-side code, scripts, or CLI tools, you can use a private key directly:

Read-Only (No Wallet)

If you only need to query vault data or DKG state, you can omit the walletClient:
Attempting to use client.uploader or client.consumer without a walletClient will throw a WalletClientRequiredError.

Network Configuration

Supported Network

Testnet

Custom RPC URL

You can point the SDK to any Aeneid-compatible RPC endpoint by changing the http() transport URL. This is useful for third-party RPC providers with higher rate limits. The apiUrl is configured independently; point it at the shared DATA Foundation API endpoint or your own Story node’s REST gateway.

Using Environment Variables

A common pattern is to configure the network via environment variables:
config.ts
.env

Quick Start: End-to-End Secret Example

The script below creates an owner-only vault, writes a small secret, then reads it back with the same wallet. It is fully runnable once WALLET_PRIVATE_KEY is set.
quickstart-cdr.ts
This example sends three transactions total: allocate(), write(), and read(). For larger payloads, switch to uploadFile() / downloadFile() with deployed condition contracts (such as the DATA Foundation license-gated pattern in IP Asset Vaults).
Any EOA address works as a write or read condition; only that EOA can perform the matching action. The high-level uploadCDR() / uploadFile() helpers validate that condition addresses point at deployed contracts, so EOA conditions go through the low-level allocate() call with skipConditionValidation: true.

Next Steps

Error Handling

The SDK throws typed errors you can catch and handle:
On-chain transaction reverts (for example, a failed condition check) surface as the underlying viem contract errors, not a CDR-specific error class.
All errors extend CDRError, which has a code property for programmatic handling: