Skip to main content

TypeScript SDK

The official TypeScript SDK for Crowd.Credit, compatible with Node.js 18+ and modern browsers.

Installation

npm install @crowd-credit/sdk
# or
yarn add @crowd-credit/sdk
# or
pnpm add @crowd-credit/sdk

Setup

import { CrowdCreditClient } from '@crowd-credit/sdk';

const client = new CrowdCreditClient({
apiKey: process.env.CROWD_CREDIT_API_KEY!,
});

Usage Examples

Account Management

// Get account details
const account = await client.accounts.me();
console.log(`Account: ${account.walletAddress}`);

// Get KYC status
const kyc = await client.accounts.getKycStatus();

Deposits

// List deposits
const deposits = await client.deposits.list({ limit: 10 });

// Get deposit summary
const summary = await client.deposits.getSummary();
console.log(`Total deposited: $${summary.totalValue}`);

Credit

// Get credit line
const creditLine = await client.credit.getLine();
console.log(`Available: $${creditLine.available}`);
console.log(`Health factor: ${creditLine.healthFactor}`);

// Get graduation tier
const tier = await client.credit.getTier();
console.log(`Current tier: ${tier.name}`);

Yield

// Get yield summary
const yieldSummary = await client.yield.getSummary();
console.log(`Total earned: $${yieldSummary.totalEarned}`);

// Get daily yield history
const history = await client.yield.getHistory({
from: '2026-01-01',
to: '2026-03-07',
});

Webhook Verification

import { verifyWebhookSignature } from '@crowd-credit/sdk';

app.post('/webhooks', (req, res) => {
const isValid = verifyWebhookSignature(
JSON.stringify(req.body),
req.headers['x-webhook-signature'] as string,
process.env.WEBHOOK_SECRET!
);

if (!isValid) {
return res.status(401).send('Invalid signature');
}

// Process the webhook event
const event = req.body;
console.log(`Received event: ${event.type}`);
res.sendStatus(200);
});

Error Handling

import { CrowdCreditError, RateLimitError } from '@crowd-credit/sdk';

try {
await client.credit.draw({ amount: '1000' });
} catch (error) {
if (error instanceof RateLimitError) {
console.log(`Rate limited. Retry after ${error.retryAfter}s`);
} else if (error instanceof CrowdCreditError) {
console.log(`API error: ${error.code} - ${error.message}`);
}
}

Next Steps