Saltar al contenido principal

Prerrequisitos

  • Una clave API de LaserSell (obtén una aquí).
  • Un archivo de par de claves de Solana (array JSON de bytes).
  • Node.js 18+ (para el ejemplo en TypeScript) o el runtime de tu lenguaje preferido.
¿Usas IA para programar? Añade el servidor MCP de LaserSell a tu editor para que tu asistente de IA pueda buscar documentación de LaserSell en tiempo real. Funciona con Claude Code, Claude Desktop, Cursor y Windsurf.

Ejemplo 1: Construir, firmar y enviar una transacción de venta

Este ejemplo llama a LaserSell API para construir una transacción de venta sin firmar, la firma localmente y la envía a través de 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);

Ejemplo 2: Auto venta con el Exit Intelligence Stream

Conecta el Exit Intelligence Stream para monitorear wallets y ejecutar automáticamente salidas cuando se alcancen los umbrales de tu estrategia.
Conecta el stream antes de comprar. El stream detecta posiciones observando las llegadas de tokens en cadena. Si llamas a /v1/buy antes de que el stream esté conectado y configurado, la posición no será rastreada. Siempre inicia el stream primero, luego envía tu transacción de compra.
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);
  }
}

Siguientes pasos