ChainStream TypeScript SDK
Official TypeScript/JavaScript client library for ChainStream API.
Installation
npm install @chainstream-io/sdk
pnpm add @chainstream-io/sdk
yarn add @chainstream-io/sdk
Quick Start
import { ChainStreamClient } from '@chainstream-io/sdk';
const client = new ChainStreamClient('your-access-token', {
autoConnectWebSocket: false
});
const unsubscribe = client.stream.subscribeTokenStats({
chain: 'solana',
tokenAddress: 'So11111111111111111111111111111111111111112',
callback: (data) => {
console.log('Token stats:', data);
}
});
unsubscribe.unsubscribe();
Batch subscribe token metrics
Ranking token metric list streams are deprecated and no longer published by the server. For ranking or new-pool cards, collect the token addresses first, then subscribe to per-token metric streams in one batch:
const unsubs = client.stream.batchSubscribe(() =>
tokenAddresses.flatMap(tokenAddress => [
client.stream.subscribeTokenStats({ chain: 'sol', tokenAddress, callback: onStats }),
client.stream.subscribeTokenHolders({ chain: 'sol', tokenAddress, callback: onHolders }),
client.stream.subscribeTokenSupply({ chain: 'sol', tokenAddress, callback: onSupply }),
client.stream.subscribeTokenLiquidity({ chain: 'sol', tokenAddress, callback: onGeneralStat }),
]),
);
For new-pool experiences, subscribe with subscribeNewPool({ chain: 'sol' }), read the token address from the pool event, batch subscribe the token metrics above, and use subscribeDexPoolBalance for pool liquidity updates.
Prediction PNL realtime
Prediction PNL realtime uses compact wire fields, but the SDK callback maps them back to the same summary, dailyPnls, and changedTokens field names returned by GET /v1/prediction/wallets/{wallet}/pnl.
const wallet = '0x674f8fc1ee68c44e988e25316984cd7ea354ca64';
const tag = 'worldcup_2026';
const initial = await client.prediction.getPredictionWalletPnl(wallet, {
tag,
limit: 50,
sort_by: 'totalPnl',
order: 'desc',
});
renderPredictionPnl(initial.summary, initial.tokens);
const unsubscribeTag = client.stream.subscribePredictionWalletPnl({
wallet,
tag,
callback: event => {
renderPredictionPnlSummary(event.summary);
mergeChangedTokens(event.changedTokens);
},
});
const unsubscribeToken = client.stream.subscribePredictionWalletPnl({
wallet,
tokenId: '115556263888245616435851357148058235707004733438163639091106356867234218207169',
callback: event => {
mergeChangedTokens(event.changedTokens);
},
});
Wallet-global prediction PNL channels are available through subscribePredictionWalletPnl({ wallet }), but the backend keeps them disabled by default to avoid unnecessary global aggregation and push load.
Features
- REST API client generated from OpenAPI
- WebSocket streaming for real-time data
- Full TypeScript type definitions
- Support for multiple subscription types:
- Token stats, candles, holders
- Wallet balances and PnL
- Trade activities
- Ranking lists
- And more...
Documentation
For detailed documentation, visit https://docs.chainstream.io
Development
pnpm install
pnpm build
pnpm test
pnpm orval
pnpm lint
pnpm format
License
MIT