Skip to main content

Prerequisites

  • A LaserSell API key (get one here).
  • A Solana keypair file (JSON array of bytes).
  • Node.js 18+ (for the TypeScript example) or the runtime for your preferred language.
Using AI to code? Add the LaserSell MCP server to your editor so your AI assistant can search LaserSell documentation in real time. Works with Claude Code, Claude Desktop, Cursor, and Windsurf.

Example 1: Build, Sign, and Send a Sell Transaction

This example calls the LaserSell API to build an unsigned sell transaction, signs it locally, and submits through Helius Sender.
import { readFile } from "node:fs/promises";
import { Keypair } from "@solana/web3.js";
import {
  ExitApiClient,
  sendTransaction,
  sendTargetHeliusSender,
  signUnsignedTx,
  type BuildSellTxRequest,
} from "@lasersell/lasersell-sdk";

const apiKey = process.env.LASERSELL_API_KEY!;
const keypairPath = "./keypair.json";

// Load keypair
const raw = await readFile(keypairPath, "utf8");
const keypair = Keypair.fromSecretKey(
  Uint8Array.from(JSON.parse(raw))
);

// Build unsigned tx
const client = ExitApiClient.withApiKey(apiKey);
const request: BuildSellTxRequest = {
  mint: "So11111111111111111111111111111111111111112",
  user_pubkey: keypair.publicKey.toBase58(),
  amount_tokens: 1_000_000,
  slippage_bps: 2_000,
  output: "SOL",
};
const unsignedTxB64 = await client.buildSellTxB64(request);

// Sign locally
const signedTx = signUnsignedTx(unsignedTxB64, keypair);

// Submit
const signature = await sendTransaction(
  sendTargetHeliusSender(),
  signedTx
);
console.log("Signature:", signature);

Example 2: Auto Sell with the Exit Intelligence Stream

Connect the Exit Intelligence Stream to monitor wallets and automatically execute exits when your strategy thresholds are reached.
Connect the stream before you buy. The stream detects positions by watching for on chain token arrivals. If you call /v1/buy before the stream is connected and configured, the position will not be tracked. Always start the stream first, then submit your buy transaction.
import { readFile } from "node:fs/promises";
import { Keypair } from "@solana/web3.js";
import {
  StreamClient,
  StreamSession,
  sendTransaction,
  sendTargetHeliusSender,
  signUnsignedTx,
} from "@lasersell/lasersell-sdk";

const apiKey = process.env.LASERSELL_API_KEY!;
const raw = await readFile("./keypair.json", "utf8");
const signer = Keypair.fromSecretKey(Uint8Array.from(JSON.parse(raw)));

const client = new StreamClient(apiKey);
const session = await StreamSession.connect(client, {
  wallet_pubkeys: [signer.publicKey.toBase58()],
  strategy: {
    target_profit_pct: 5,
    stop_loss_pct: 1.5,
  },
  deadline_timeout_sec: 45,
  send_mode: "helius_sender",
  tip_lamports: 1000,
});

while (true) {
  const event = await session.recv();
  if (event === null) break;

  if (event.type === "exit_signal_with_tx") {
    const signed = signUnsignedTx(event.message.unsigned_tx_b64, signer);
    const sig = await sendTransaction(sendTargetHeliusSender(), signed);
    console.log("Exit submitted:", sig);
  }
}

Next Steps