SAP Explorer Docs
SDK Reference

Client Setup

Creating and configuring SapClient and SapConnection for different environments.

Client Setup

The SDK provides two main entry points: SapClient for direct Anchor provider usage and SapConnection for environment-based configuration.

SapClient

SapClient is the root object from which all modules and registries are accessed. It requires an AnchorProvider or an existing Anchor Program.

From Provider

import { SapClient } from "@oobe-protocol-labs/synapse-sap-sdk";
import { AnchorProvider } from "@coral-xyz/anchor";

// AnchorProvider.env() reads ANCHOR_PROVIDER_URL and ANCHOR_WALLET
// from process environment. Common in scripts and tests.
// Default commitment: "confirmed" (voted by 2/3 of validators).
const client = SapClient.from(AnchorProvider.env());

From Program

const client = SapClient.fromProgram(myAnchorProgram);

Properties

PropertyTypeDescription
programProgramUnderlying Anchor program
walletPubkeyPublicKeyProvider wallet (default authority and payer)

SapConnection

SapConnection wraps Solana Connection with cluster-aware configuration and factory methods.

Factory Methods

MethodEndpointUse Case
SapConnection.devnet()api.devnet.solana.comTesting
SapConnection.mainnet(rpcUrl?)Custom or Solana defaultProduction
SapConnection.localnet()localhost:8899Local development
SapConnection.fromKeypair(url, keypair)CustomScripts, bots, CLIs

Devnet

// SapConnection.devnet() creates a connection to api.devnet.solana.com.
// Call .fromKeypair() to get a SapClient with signing capability.
const conn = SapConnection.devnet();
const client = conn.fromKeypair(testKeypair);

Mainnet with Synapse Gateway

// For production, use a dedicated RPC provider.
// The Synapse Gateway provides optimal routing for SAP operations.
// Replace the URL with your own endpoint and API key.
const conn = SapConnection.mainnet("https://us-1-mainnet.oobeprotocol.ai/rpc?api_key=");
const client = conn.createClient(wallet);

Custom Configuration

// Full manual configuration for advanced use cases.
const conn = new SapConnection({
  rpcUrl: "https://us-1-mainnet.oobeprotocol.ai/rpc?api_key=",  // required
  wsUrl: "wss://us-1-mainnet.oobeprotocol.ai/ws?api_key=",      // optional: auto-derived from rpcUrl
  commitment: "finalized",                                       // optional: default "confirmed"
  cluster: "mainnet-beta",                                       // optional: auto-detected from URL
});
PropertyTypeDefaultDescription
rpcUrlstringRequiredSolana JSON-RPC endpoint
wsUrlstringAuto-derivedWebSocket endpoint
commitmentCommitment"confirmed"Default commitment level
clusterSapClusterAuto-detectedExplicit cluster hint

Environment-Based Setup

A common pattern for applications that run across environments:

function createClient(env: "development" | "staging" | "production") {
  const keypair = Keypair.fromSecretKey(/* load from env or vault */);

  // Map each environment to the appropriate RPC endpoint.
  // Development uses localnet (free, instant finality).
  // Staging uses devnet (free, slower, shared rate limit).
  // Production uses a dedicated RPC provider (paid, fast, no rate limit).
  const rpcUrls: Record<string, string> = {
    development: "http://localhost:8899",
    staging: "https://api.devnet.solana.com",
    production: "https://us-1-mainnet.oobeprotocol.ai/rpc?api_key=",
  };

  const { client } = SapConnection.fromKeypair(rpcUrls[env], keypair);
  return client;
}

Commitment Levels

LevelLatencyGuaranteeWhen to Use
processed~400 msOptimistic, may be rolled backDebug only
confirmed~400 msSupermajority votedReads, most writes
finalized~6 to 12 sRooted, irreversibleEscrow, attestations, critical writes

The SDK defaults to "confirmed" which is suitable for most operations.