@blend-money/节点
用于Blend协议的服务器侧 SDK. API 密钥被认证为服务器对服务器集成.
安装
pnpm add @blend-money/node
快速启动
import { BlendServerSdk } from "@blend-money/node";
const sdk = new BlendServerSdk({
apiKey: "sk_live_...",
accountTypeId: "your-account-type",
});
// 1. Discover what's available
const chains = await sdk.discover.depositChains();
const tokens = await sdk.discover.depositTokens(8453);
// 2. Look up an account by EOA address
const account = await sdk.lookupAccount("0x...");
// { accountId, safeAddress, chainsDeployed }
// 3. Or create one if it doesn't exist
const newAccount = await sdk.createAccount("0x...", 8453);
// 4. Get a scoped client for the account
const client = sdk.forAccount(account.accountId);
// 5. Use account data and session lifecycle
const balance = await client.account.balance();
const sessions = await client.sessions.list();
配置
const sdk = new BlendServerSdk({
// Required
apiKey: "sk_live_...", // Server-side API key (X-API-Key header)
accountTypeId: "your-account-type", // Product identifier for URL routing
// Optional
baseUrl: "https://...", // API base URL override
fiatCurrency: "EUR", // ISO 4217 code for multi-currency
timeoutMs: 15000, // Request timeout (default: 15000)
retries: 3, // Max retries for 429/5xx (default: 3)
});
API 参考
发现
无需界定账户范围.
const chains = await sdk.discover.depositChains();
// [{ chainId, name, displayName, iconUrl }]
const tokens = await sdk.discover.depositTokens(8453);
// [{ chainId, address, symbol, name, decimals, logoURI, price }]
const destinations = await sdk.discover.withdrawDestinations();
// [{ chainId, name, loanTokenAddress }]
const yieldData = await sdk.discover.yield();
// { accountTypeId, yieldBreakdown: [{ chainId, vaultAddress, breakdown, summary }] }
账户查询
const account = await sdk.lookupAccount("0x...");
// { accountId, safeAddress, chainsDeployed }
账户创建
const account = await sdk.createAccount("0x...", 8453);
// { accountId, safeAddress, chainsDeployed }
范围客户端
forAccount() 返回完整 BlendClient 范围为特定账户,可获取发现、账户数据和会话周期.
const client = sdk.forAccount(account.accountId);
// Account data
const balance = await client.account.balance();
const positions = await client.account.positions();
const returns = await client.account.returns();
// Safe management
const resolution = await client.account.safe.resolve(8453);
await client.account.safe.request(8453);
// Session lifecycle
const session = await client.sessions.createSession({ forceReset: true });
const quoted = await client.sessions.quoteDeposit(session.intentId, { ... });
const locked = await client.sessions.lock(session.intentId, { signerAddress: "0x..." });
const submitted = await client.sessions.submit(session.intentId, { txHashes: [...] });
const result = await client.sessions.execute(session.intentId, { ... });
const sessions = await client.sessions.list();
await client.sessions.cancel(session.intentId);
见 @blend-money/fe 读取 用于账户数据、会话周期、金额助手和错误处理的完整文档——范围化客户API是相同的.
数额
从 @blend-money/core数字 :
import { parseAmount, formatAmount } from "@blend-money/node";
const smallest = parseAmount("100.50", 6); // "100500000"
const human = formatAmount("100500000", 6); // "100.5"
处理错误
所有错误类型都从 @blend-money/core数字 :
import { SdkError, SESSION_ERROR_CODES } from "@blend-money/node";
try {
await client.account.balance();
} catch (err) {
if (err instanceof SdkError) {
console.log(err.code); // e.g. "INTENT_NOT_FOUND"
console.log(err.status); // HTTP status
console.log(err.getUserMessage()); // human-readable message
console.log(err.isRetryable()); // true for 429, 5xx, network errors
}
}
发展
从单列波根:
pnpm install # Install all dependencies
pnpm --filter @blend-money/node build # Build this package
pnpm --filter @blend-money/node dev # Watch mode
pnpm --filter @blend-money/node test # Run tests (interactive)
pnpm --filter @blend-money/node test:run # Run tests (CI)
pnpm --filter @blend-money/node check-types # Type check
或运行 pnpm build, (中文(简体) ), pnpm test:run等从单列波根运行到所有软件包.
许可证
麻省理工学院