Skip to content

SDK — Getting Started ​

Installation ​

Install via npm:

bash
npm install stellar-agent-guard-sdk

🛠️ Usage Examples ​

1. Pre-Flight Interception ​

typescript
import { PreFlightInterceptor } from "stellar-agent-guard-sdk";
import { Keypair } from "@stellar/stellar-sdk";

const interceptor = new PreFlightInterceptor({
  rpcUrl: "https://soroban-testnet.stellar.org",
  guard: "CAPADGEK457RHKN4RYVUMDJTFHDSG7R5HREQONKLYK7MFKC5WFENPP44",
  agent: Keypair.fromSecret(process.env.AGENT_SECRET!),
  source: Keypair.fromSecret(process.env.SOURCE_SECRET!),
});

const decision = await interceptor.check({
  contractId: "CDCYDGBGS5AZ5BZS6XY2SK2PHJHSOEGTN3N4INCK34KF6GU2BGC7Z6MB",
  method: "transfer",
  args: [/* from, to, amount */],
});

if (decision.kind === "admissible") {
  console.log("Allowed! Resource fee:", decision.estimatedResourceFee);
} else if (decision.kind === "blocked") {
  console.log("Blocked by guard:", decision.reason);
}

2. LangChain Tool Middleware ​

typescript
import { createGuardToolMiddleware } from "stellar-agent-guard-sdk/adapters/langchain";

const guardedTool = createGuardToolMiddleware(myStellarTransferTool, {
  interceptor,
});

3. Telemetry Event Monitoring ​

typescript
import { GuardTelemetryListener } from "stellar-agent-guard-sdk";

const listener = new GuardTelemetryListener({
  rpcUrl: "https://soroban-testnet.stellar.org",
  guard: "CAPADGEK457RHKN4RYVUMDJTFHDSG7R5HREQONKLYK7MFKC5WFENPP44",
});

for await (const page of listener.watch()) {
  for (const event of page.events) {
    console.log(`Event ${event.kind}:`, event.detail);
  }
}