Skip to main content

SDK Installation

Detailed instructions for installing and configuring the Seesaw SDK.

Package Installation

npm

npm install @seesaw/sdk @solana/web3.js

yarn

yarn add @seesaw/sdk @solana/web3.js

pnpm

pnpm add @seesaw/sdk @solana/web3.js

Peer Dependencies

The SDK requires these peer dependencies:

PackageVersionPurpose
@solana/web3.js^1.9.0Solana connection and transactions

Optional Dependencies

For additional functionality:

PackagePurpose
@solana/spl-tokenToken account operations
@pythnetwork/clientDirect Pyth price reads
npm install @solana/spl-token @pythnetwork/client

TypeScript Configuration

Add to your tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "lib": ["ES2020"],
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true
  }
}

Environment Setup

Connection Configuration

import { Connection, clusterApiUrl } from '@solana/web3.js';

// Mainnet
const mainnetConnection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed');

// Devnet (for testing)
const devnetConnection = new Connection(clusterApiUrl('devnet'), 'confirmed');

// Custom RPC
const customConnection = new Connection('https://your-rpc-provider.com', {
  commitment: 'confirmed',
  confirmTransactionInitialTimeout: 60000,
});

Program ID Configuration

import { PublicKey } from '@solana/web3.js';

// Mainnet program ID
const MAINNET_PROGRAM_ID = new PublicKey('SEESAW_MAINNET_PROGRAM_ID');

// Devnet program ID
const DEVNET_PROGRAM_ID = new PublicKey('SEESAW_DEVNET_PROGRAM_ID');

Environment Variables

Create a .env file:

# Network
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
SEESAW_PROGRAM_ID=<program_id>

# Optional
PYTH_PROGRAM_ID=FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH

Load with:

import 'dotenv/config';

const connection = new Connection(process.env.SOLANA_RPC_URL!);
const programId = new PublicKey(process.env.SEESAW_PROGRAM_ID!);

Wallet Setup

Keypair from File

import { Keypair } from '@solana/web3.js';
import fs from 'fs';

const secretKey = JSON.parse(fs.readFileSync('/path/to/wallet.json', 'utf-8'));
const wallet = Keypair.fromSecretKey(Uint8Array.from(secretKey));

Keypair from Environment

const secretKey = JSON.parse(process.env.WALLET_SECRET_KEY!);
const wallet = Keypair.fromSecretKey(Uint8Array.from(secretKey));

Browser Wallet Adapter

import { useWallet } from '@solana/wallet-adapter-react';

function TradingComponent() {
  const { publicKey, signTransaction } = useWallet();

  // Use publicKey and signTransaction with SDK
}

Verification

Verify installation with a simple test:

import { Connection, PublicKey } from '@solana/web3.js';
import { findMarketPda, parseMarket } from '@seesaw/sdk';

async function verifyInstallation() {
  const connection = new Connection('https://api.mainnet-beta.solana.com');
  const programId = new PublicKey('SEESAW_PROGRAM_ID');

  // Calculate current market ID
  const durationSeconds = 900; // default; use market's actual duration
  const marketId = BigInt(Math.floor(Date.now() / 1000 / durationSeconds));

  // Derive market PDA
  const [marketPda] = findMarketPda(marketId, programId);
  console.log('Market PDA:', marketPda.toBase58());

  // Try to fetch market
  const marketAccount = await connection.getAccountInfo(marketPda);

  if (marketAccount) {
    const market = parseMarket(marketAccount.data);
    console.log('Market found:', market);
  } else {
    console.log('No market exists for this epoch yet');
  }

  console.log('SDK installed successfully!');
}

verifyInstallation().catch(console.error);

Common Issues

BigInt Serialization

If you encounter BigInt serialization errors:

// Add this to handle BigInt in JSON
(BigInt.prototype as any).toJSON = function () {
  return this.toString();
};

Buffer Not Defined

In browser environments, you may need to polyfill Buffer:

npm install buffer
import { Buffer } from 'buffer';
window.Buffer = Buffer;

RPC Rate Limits

If hitting rate limits:

const connection = new Connection('https://api.mainnet-beta.solana.com', {
  commitment: 'confirmed',
  httpHeaders: {
    Authorization: `Bearer ${process.env.RPC_API_KEY}`,
  },
});

Next Steps