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
});| Option | Required | Default | Notes |
|---|---|---|---|
apiKey | yes | — | Get one at developer.piratecrew.fun |
secretKey | yes | — | The wallet that pays for and owns the new token |
network | no | mainnet-beta | Ignored if rpcUrl is set |
rpcUrl | no | Solana public RPC | Strongly recommended for production — use Helius/QuickNode |
commitment | no | confirmed | Standard web3.js commitment level |
timeout | no | 30 000 ms | Per-request HTTP timeout |
maxRetries | no | 3 | Retries 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:
- Calls
POST /v2/poolsto build the unsigned transactions. - Signs them locally with your wallet keypair plus the ephemeral mint/config keypairs returned by the API.
- Submits the signed bundle via
POST /v2/transactionswithbundle: true. - Polls
GET /v2/pools/{address}until the resource flips tostatus: "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 pubkeyReturns SOL (not lamports).
Clean up
sdk.destroy(); // zeroes the in-memory secret keyCall 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 fromcreateCoin/getBalancewhen the API or the chain rejects the request. The message preserves the API'serror.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);