Skip to main content

Installation

npm install @lasersell/lasersell-sdk
The package ships with TypeScript declarations and supports both ESM and CommonJS.

Modules

ImportPurpose
ExitApiClientBuild unsigned buy/sell transactions.
StreamClientLow level WebSocket stream client.
StreamSessionHigh level stream with position tracking.
signUnsignedTxSign an unsigned base64 transaction.
signUnsignedTxB64FastFast path in place signing (returns base64).
sendTransactionSubmit a signed transaction.
sendTargetRpc, sendTargetHeliusSender, sendTargetAstralaneSend target constructors.

API Client

import {
  ExitApiClient,
  type BuildSellTxRequest,
  type BuildBuyTxRequest,
} from "@lasersell/lasersell-sdk";

const client = ExitApiClient.withApiKey("YOUR_API_KEY");

// Build sell
const sellRequest: BuildSellTxRequest = {
  mint: "TOKEN_MINT",
  user_pubkey: "WALLET",
  amount_tokens: 1_000_000,
  slippage_bps: 2_000,
  output: "SOL",
};
const sellResponse = await client.buildSellTx(sellRequest);
const txB64 = sellResponse.tx;

// Build buy
const buyRequest: BuildBuyTxRequest = {
  mint: "TOKEN_MINT",
  user_pubkey: "WALLET",
  amount: 0.1, // 0.1 SOL
  slippage_bps: 2_000,
};
const buyResponse = await client.buildBuyTx(buyRequest);

Client Options

const client = ExitApiClient.withOptions("YOUR_API_KEY", {
  connect_timeout_ms: 500,
  attempt_timeout_ms: 2000,
  retry_policy: {
    max_attempts: 3,
    initial_backoff_ms: 50,
    max_backoff_ms: 200,
    jitter_ms: 50,
  },
});

Exit Intelligence Stream Session

import {
  StreamClient,
  StreamSession,
  sendTransaction,
  sendTargetHeliusSender,
  signUnsignedTx,
} from "@lasersell/lasersell-sdk";

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

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

  switch (event.type) {
    case "position_opened":
      console.log("New position:", event.handle.mint);
      break;

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

    case "pnl_update":
      if (event.message.type === "pnl_update") {
        console.log(
          `PnL position=${event.message.position_id} profit=${event.message.profit_units}`
        );
      }
      break;
  }
}

Lane Splitting

For high throughput scenarios, split the Exit Intelligence Stream into priority lanes:
const connection = await client.connectLanes(configure, {
  lowPriorityCapacity: 512,
});
const [sender, highRx, lowRx] = connection.split();

// High priority: exit signals, position events
for await (const msg of highRx) {
  // Handle critical messages
}

Liquidity Snapshots and Partial Sells

Tier 1+ only. Requires a Professional or Advanced subscription. See the announcement for full details.
StreamSession caches the latest liquidity snapshot per position. Query slippage bands, maximum sellable amounts, and liquidity trends:
const bands = session.getSlippageBands(positionId);
const maxTokens = session.getMaxSellAtSlippage(positionId, 500); // 5% slippage
const trend = session.getLiquidityTrend(positionId); // "growing" | "stable" | "draining"
Use buildPartialSellTx() to sell a portion of a position based on slippage data:
const maxTokens = session.getMaxSellAtSlippage(positionId, 500);
if (maxTokens !== undefined) {
  const response = await client.buildPartialSellTx(handle, maxTokens, 500, "SOL");
}

Mirror Trading

Configure watch wallets to mirror trades from other wallets. When a watched wallet opens a position on a supported market, the stream sends a mirror_buy_signal with an unsigned transaction for your wallet to execute.
import {
  StreamClient,
  StreamSession,
  sendTransaction,
  sendTargetHeliusSender,
  signUnsignedTx,
} from "@lasersell/lasersell-sdk";

const walletPubkey = "YOUR_WALLET_PUBKEY";

const client = new StreamClient("YOUR_API_KEY");
const session = await StreamSession.connect(client, {
  wallet_pubkeys: [walletPubkey],
  strategy: {
    target_profit_pct: 50,
    stop_loss_pct: 25,
  },
  watch_wallets: [
    {
      pubkey: "WatchedWalletPubkey...",
      auto_buy: {
        wallet_pubkey: walletPubkey,
        amount_quote_units: 100_000_000,
        amount_usd1_units: null,
      },
      mirror_sell: false,
    },
  ],
  mirror_config: {
    max_positions_per_wallet: 1,
    cooldown_sec: 30,
    max_active_sol: 5.0,
    buy_slippage_bps: 2500,
  },
});

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

  switch (event.type) {
    case "mirror_buy_signal": {
      const { mint, unsigned_tx_b64 } = event.message;
      const signed = signUnsignedTx(unsigned_tx_b64, keypair);
      const sig = await sendTransaction(sendTargetHeliusSender(), signed);
      session.sender().mirrorBuyResult(mint, true);
      console.log("Mirror buy submitted:", sig);
      break;
    }

    case "mirror_buy_failed":
      console.log(`Mirror buy failed: ${event.message.reason}`);
      break;

    case "exit_signal_with_tx": {
      if (event.message.type === "exit_signal_with_tx") {
        const signed = signUnsignedTx(event.message.unsigned_tx_b64, keypair);
        const sig = await sendTransaction(sendTargetHeliusSender(), signed);
        console.log("Exit submitted:", sig);
      }
      break;
    }
  }
}
The watch_wallets array specifies which wallets to mirror. Each entry includes an auto_buy configuration that controls how much to spend when mirroring a trade, and a mirror_sell flag that determines whether to also mirror sell transactions. The mirror_config object sets global limits: max_positions_per_wallet caps concurrent mirrored positions, cooldown_sec enforces a delay between mirror buys, max_active_sol limits total SOL exposure, and buy_slippage_bps sets the slippage tolerance for mirror buy transactions.

Transaction Helpers

import {
  signUnsignedTx,
  signUnsignedTxB64Fast,
  signAndSendUnsignedTxB64,
  sendTransaction,
  sendTransactionB64To,
  encodeSignedTx,
  sendTargetRpc,
  sendTargetHeliusSender,
  sendTargetAstralane,
  sendTargetDefaultRpc,
} from "@lasersell/lasersell-sdk";

// Standard sign
const signedTx = signUnsignedTx(unsignedTxB64, keypair);

// Fast sign (returns base64 string)
const signedB64 = signUnsignedTxB64Fast(unsignedTxB64, keypair);

// Sign + send in one step
const sig = await signAndSendUnsignedTxB64(
  sendTargetHeliusSender(),
  unsignedTxB64,
  keypair,
);

// Send a pre-signed transaction
const sig2 = await sendTransaction(sendTargetRpc("https://rpc.example.com"), signedTx);

// Send a pre-signed base64 string
const sig3 = await sendTransactionB64To(sendTargetHeliusSender(), signedB64);

Error Handling

import { ExitApiError, TxSubmitError, StreamClientError } from "@lasersell/lasersell-sdk";

try {
  await client.buildSellTx(request);
} catch (error) {
  if (error instanceof ExitApiError) {
    // error.kind, error.status, error.body, error.isRetryable()
  }
  if (error instanceof TxSubmitError) {
    // error.kind, error.target, error.status
  }
  if (error instanceof StreamClientError) {
    // error.kind
  }
}

Complete Example

See the Quickstart for a full working example that builds, signs, and submits a sell transaction.