SDK Documentation
Canonical TypeScript SDKs for Loop Protocol: the base on-chain SDK plus the BYOAA/KYA gateway SDK for attested-agent integrations.
Installation
@loopprotocol/sdk
Core Loop Protocol SDK for on-chain programs, vaults, Cred, OXO, VTP/AVP, shopping, capture modules, and enclave primitives.
npm install @loopprotocol/sdk
# or
pnpm add @loopprotocol/sdk@loopprotocol/sdk-byoaa
Gateway SDK for attested-agent registration, permissions, KYA decisions, typed errors, and externally-verifiable audit-pack export.
npm install @loopprotocol/sdk-byoaa @loopprotocol/sdk
# or
pnpm add @loopprotocol/sdk-byoaa @loopprotocol/sdkQuick Start
Connect, wrap USDC to Cred, and start stacking for yield.
import { Loop } from "@loopprotocol/sdk";
import { Connection, Keypair } from "@solana/web3.js";
// Initialize
const connection = new Connection("https://api.mainnet-beta.solana.com");
const wallet = Keypair.generate(); // Use your wallet
const loop = new Loop({ connection, wallet });
// Wrap USDC to Cred (1:1)
const wrapTx = await loop.cred.wrap({
amount: 100_000_000, // 100 USDC (6 decimals)
});
console.log("Wrapped:", wrapTx);
// Stack Cred for yield
const stackTx = await loop.vault.stack({
amount: 100_000_000, // 100 Cred
lockPeriod: 30, // 30 days
});
console.log("Stacked:", stackTx);
// Check position
const position = await loop.vault.getPosition(wallet.publicKey);
console.log("APY:", position.currentApy);BYOAA / KYA Gateway SDK
Use the BYOAA SDK when a hosted or self-custodied agent needs to act with proof: register the agent, grant scoped permissions, request allow/review/deny decisions, and export tamper-evident audit packs.
import { LoopByoaaClient } from "@loopprotocol/sdk-byoaa";
const loop = new LoopByoaaClient({
apiKey: process.env.LOOP_BYOAA_API_KEY!, // dev keys route to https://dev-api.kya.looplocal.io by default
});
const agent = await loop.agents.register({
external_id: "friend-test-agent",
display_name: "Friend Test Agent",
purpose: "Dev adopter integration test",
risk_tier: "low",
});
await loop.permissions.grant({
agent_id: agent.id,
on_behalf_of_user_id: "user_123",
layer: "shopping",
action_class: "purchase",
amount_cap_cents: 2500,
});
const decision = await loop.decisions.request({
agent_id: agent.id,
on_behalf_of_user_id: "user_123",
intended_action: {
layer: "shopping",
action_class: "purchase",
amount_cents: 1250,
target: { merchant_name: "Loop Demo Merchant" },
},
});
const pack = await loop.audit.exportPack({
range: { from: new Date(Date.now() - 86_400_000), to: new Date() },
format: "json",
});
console.log(decision.outcome, pack.manifest);Configuration
const loop = new Loop({
connection,
wallet,
cluster: "mainnet-beta",
});const loop = new Loop({
connection,
wallet,
cluster: "devnet",
});Vaults
Core primitive for value custody. Each user has a personal vault managed by their agent within on-chain policy constraints.
// Initialize a vault
const initTx = await loop.vault.initialize({
owner: wallet.publicKey,
agent: agentPublicKey,
policy: {
dailyLimit: 1000_000_000, // 1000 Cred
autoStack: true,
requireUserAbove: 500_000_000,
},
});
// Get vault info
const vault = await loop.vault.get(wallet.publicKey);
console.log("Balance:", vault.credBalance);
console.log("Staked:", vault.stakedAmount);
console.log("Agent:", vault.agent);Cred Token
Protocol's stable unit of account, backed 1:1 by USDC.
// Wrap USDC → Cred
const wrapTx = await loop.cred.wrap({
amount: 100_000_000, // 100 USDC
destination: vaultAddress, // Optional: direct to vault
});
// Unwrap Cred → USDC
const unwrapTx = await loop.cred.unwrap({
amount: 50_000_000, // 50 Cred
});
// Check balance
const balance = await loop.cred.getBalance(wallet.publicKey);Stacking
Stack Cred to earn yield from protocol fees. Longer lock periods = higher APY.
// Stack with lock period
const stackTx = await loop.vault.stack({
amount: 1000_000_000, // 1000 Cred
lockPeriod: 90, // 90 days for bonus APY
});
// Unstake (after lock expires)
const unstakeTx = await loop.vault.unstake({
amount: 500_000_000,
});
// Claim yield
const claimTx = await loop.vault.claimYield();
// Get staking info
const position = await loop.vault.getPosition(wallet.publicKey);
console.log({
staked: position.stakedAmount,
apy: position.currentApy,
pendingYield: position.pendingYield,
unlockDate: position.unlockDate,
});Service Agents
Register agents with bonding curve tokens.
// Register a new agent
const registerTx = await loop.agents.register({
name: "ShopCapture Pro",
capabilities: ["shopping_capture", "data_licensing"],
feePercentage: 5, // 5% of captured value
metadata: {
description: "Captures value from retail purchases",
website: "https://shopcapture.ai",
},
});
// Get agent info
const agent = await loop.agents.get(agentPublicKey);
console.log("Token Price:", agent.tokenPrice);
console.log("Subscribers:", agent.subscriberCount);
// Subscribe to an agent
const subscribeTx = await loop.agents.subscribe({
agent: agentPublicKey,
vault: vaultAddress,
});
// Buy agent tokens (bonding curve)
const buyTx = await loop.agents.buyTokens({
agent: agentPublicKey,
amount: 100,
maxPrice: 1_500_000, // Slippage protection
});Program IDs
Deployed program addresses on Solana mainnet.
| Program | Address |
|---|---|
| CRED | HYQJwCJ5wH9o4sb9sVPyvSSeY9DtsznZGy2AfpiBaBaG |
| VAULT | J8HhLeRv5iQaSyYQBXJoDwDKbw4V8uA84WN93YrVSWQT |
| SHOPPING | HiewKEBy6YVn3Xi5xdhyrsfPr3KjKg6Jy8PXemyeteXJ |
| Cred Mint | 9GQMCAK3MpZF1hEbwqA9d4mRGtippGV9hyr8fxmz6eA |