SDKs & Libraries
Chain provides official client libraries for popular languages. SDKs handle authentication, request signing, pagination, error handling, and webhook verification.
Available SDKs
JS
Node.js
v2.x — Stable
npm install @chain/nodePY
Python
v2.x — Stable
pip install chain-sdkGO
Go
Coming soon
RB
Ruby
Coming soon
Installation
# npm
npm install @chain/node
# yarn
yarn add @chain/node
# pnpm
pnpm add @chain/nodeQuick Start
import Chain from '@chain/node';
const chain = new Chain('sk_live_...');
// Register a wallet
const wallet = await chain.wallets.create({
label: 'Treasury',
address: '0x1a2b3c4d5e6f7890abcdef1234567890abcdef12',
blockchain: 'ethereum',
is_primary: true,
});
// Create a funding request
const funding = await chain.funding.create({
amount: 10000,
currency: 'USD',
bank_account_id: 'ba_abc123',
wallet_id: wallet.id,
});
// Issue a card
const card = await chain.cards.create({
type: 'virtual',
cardholder_name: 'Jane Doe',
business_user_id: 'usr_abc123',
currency: 'USD',
});
console.log(card.id, card.last_four);Error Handling
import Chain, { ChainError } from '@chain/node';
const chain = new Chain('sk_live_...');
try {
const payout = await chain.payouts.create({
amount: 5000,
currency: 'USD',
payee_id: 'payee_abc',
payout_type: 'fiat',
wallet_id: 'wal_xyz789',
});
} catch (error) {
if (error instanceof ChainError) {
console.error('Status:', error.status);
console.error('Code:', error.code);
console.error('Message:', error.message);
if (error.status === 429) {
// Retry after the specified delay
const retryAfter = error.headers['retry-after'];
}
}
}Pagination
SDKs provide auto-pagination helpers. Iterate over large collections without manually managing cursors.
// Auto-pagination
for await (const wallet of chain.wallets.list({ limit: 10 })) {
console.log(wallet.id, wallet.label);
}
// Or collect all results
const allWallets = await chain.wallets.list().toArray();Webhook Helpers
Built-in verification
SDKs include helpers to verify webhook signatures and parse event payloads with full type safety.
import { Webhook } from '@chain/node';
const webhook = new Webhook(process.env.CHAIN_WEBHOOK_SECRET);
app.post('/webhooks', (req, res) => {
const event = webhook.verify(req.body, req.headers);
switch (event.type) {
case 'funding.completed':
// event.data is fully typed
handleFunding(event.data);
break;
case 'card.authorization.request':
handleAuth(event.data);
break;
}
res.sendStatus(200);
});