PBJ SDK documentation

Quickstart

Install the SDK, configure a client, and make your first typed PBJ request in a few minutes.

Configure environment variables

dotenv
PBJ_API_KEY=pbj_test_replace_me
PBJ_API_URL=https://api.pbjspace.dev
PBJ_SOLANA_NETWORK=devnet
PBJ_SOLANA_RPC_URL=

The SDK does not load environment files automatically. Your application is responsible for mapping these values into client options.

Create a client

ts
import { PBJClient } from "pbjspace";

export const pbj = new PBJClient({
  apiKey: process.env.PBJ_API_KEY!,
  ...(process.env.PBJ_API_URL
    ? { baseUrl: process.env.PBJ_API_URL }
    : {}),
  network: "devnet",
});

Make your first request

ts
const projects = await pbj.projects.list({ limit: 20 });

for (const project of projects.data) {
  console.log(project.id, project.name);
}

Collection methods return { data, nextCursor, hasMore }. Item methods return typed objects directly.

Use it in Next.js

Initialize the SDK in server-only code such as a Route Handler. Verify your application user before forwarding a request to PBJ.

ts
// app/api/projects/route.ts
import { pbj } from "@/lib/pbj";

export async function GET() {
  const projects = await pbj.projects.list({ limit: 20 });
  return Response.json(projects);
}