사전 요구사항
- LaserSell API 키 (여기서 발급).
- Solana 키페어 파일 (바이트의 JSON 배열).
- Node.js 18+ (TypeScript 예제용) 또는 선호하는 언어의 런타임.
AI로 코딩하시나요? LaserSell MCP 서버를 에디터에 추가하면 AI 어시스턴트가 실시간으로 LaserSell 문서를 검색할 수 있습니다. Claude Code, Claude Desktop, Cursor, Windsurf에서 작동합니다.
예제 1: 매도 트랜잭션 빌드, 서명, 전송
이 예제는 LaserSell API를 호출하여 서명되지 않은 매도 트랜잭션을 빌드하고, 로컬에서 서명하고, 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);
예제 2: Exit Intelligence Stream으로 자동 매도
Exit Intelligence Stream에 연결하여 지갑을 모니터링하고 전략 임계값에 도달하면 자동으로 청산을 실행합니다.
매수 전에 스트림을 연결하세요. 스트림은 온체인 토큰 도착을 감시하여 포지션을 감지합니다. 스트림이 연결 및 구성되기 전에 /v1/buy를 호출하면 포지션이 추적되지 않습니다. 항상 스트림을 먼저 시작한 다음 매수 트랜잭션을 제출하세요.
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);
}
}
다음 단계