SDK Quickstart

SDK Quickstart

The @piratecrewfun/pirate-sdk package is the fastest path to integrating with the Pirate API. It wraps the HTTP endpoints, signs transactions locally with your Solana keypair, and submits the Jito bundle in a single call — so you never handle base64 transaction blobs by hand.

Prefer raw HTTP? Every SDK call maps 1:1 to an endpoint in the API Reference. The SDK is optional.

Install

npm install @piratecrewfun/pirate-sdk @solana/web3.js

@solana/web3.js is a peer dependency — version ^1.98.0.

Initialize

import { PirateSDK } from "@piratecrewfun/pirate-sdk";

const sdk = new PirateSDK({
  apiKey: process.env.PIRATE_API_KEY!,
  secretKey: process.env.WALLET_SECRET_KEY!, // base58, hex, Uint8Array, or Keypair
  network: "mainnet-beta", // or "devnet" | "testnet"
  // rpcUrl: "https://your-helius-or-quicknode.url"  ← optional override
});
OptionRequiredDefaultNotes
apiKeyyesGet one at developer.piratecrew.fun
secretKeyyesThe wallet that pays for and owns the new token
networknomainnet-betaIgnored if rpcUrl is set
rpcUrlnoSolana public RPCStrongly recommended for production — use Helius/QuickNode
commitmentnoconfirmedStandard web3.js commitment level
timeoutno30 000 msPer-request HTTP timeout
maxRetriesno3Retries on transient API failures

Create a token

const result = await sdk.createCoin({
  name: "Black Pearl",
  symbol: "PEARL",
  image: imageFile,           // File (browser) or base64 string (Node)
  description: "Captain Jack approved",
  buyAmount: 0.5,             // SOL to spend on the dev-buy (optional)
  website: "https://blackpearl.xyz",
  x: "https://x.com/blackpearl",
  telegram: "https://t.me/blackpearl",
});

console.log(result);
// {
//   poolAddress: "…",
//   mintAddress: "…",
//   signatures: ["…", "…"],
//   verification: { message: "Pool confirmed" }
// }

createCoin runs the full flow end-to-end:

  1. Calls POST /v2/pools to build the unsigned transactions.
  2. Signs them locally with your wallet keypair plus the ephemeral mint/config keypairs returned by the API.
  3. Submits the signed bundle via POST /v2/transactions with bundle: true.
  4. Polls GET /v2/pools/{address} until the resource flips to status: "live".

Each step uses the credentials you passed to the constructor — no further config required.

Check your wallet balance

const sol = await sdk.getBalance();           // your wallet
const otherSol = await sdk.getBalance(pubkey); // any pubkey

Returns SOL (not lamports).

Clean up

sdk.destroy(); // zeroes the in-memory secret key

Call this before your process exits if you care about wiping the key from RAM (recommended in long-running services).

Errors

All SDK methods throw on failure. The two most common types:

  • ValidationError — thrown synchronously from the constructor for bad inputs (invalid network, malformed RPC URL, invalid public key).
  • Error — thrown from createCoin / getBalance when the API or the chain rejects the request. The message preserves the API's error.message, so a 400 from the NSFW check surfaces as "Failed to create Coin: image rejected: violence".

Wrap calls in try/catch and inspect error.message for routing logic. See Errors & Retries for HTTP status semantics.

Full example

import { PirateSDK } from "@piratecrewfun/pirate-sdk";
import { readFileSync } from "node:fs";

async function main() {
  const sdk = new PirateSDK({
    apiKey: process.env.PIRATE_API_KEY!,
    secretKey: process.env.WALLET_SECRET_KEY!,
    network: "mainnet-beta",
    rpcUrl: process.env.HELIUS_RPC_URL,
  });

  try {
    const image = readFileSync("./pearl.png").toString("base64");

    const { poolAddress, mintAddress, signatures } = await sdk.createCoin({
      name: "Black Pearl",
      symbol: "PEARL",
      image,
      buyAmount: 0.1,
    });

    console.log(`Pool:  https://solscan.io/account/${poolAddress}`);
    console.log(`Mint:  https://solscan.io/token/${mintAddress}`);
    console.log(`Txs:   ${signatures.join(", ")}`);
  } finally {
    sdk.destroy();
  }
}

main().catch(console.error);