@chainstream-io/sdk 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +332 -25
- package/dist/{WatchlistApi-Bs1J8X9y.d.cts → WatchlistApi-Cxzs25LV.d.cts} +2325 -2259
- package/dist/{WatchlistApi-Bs1J8X9y.d.ts → WatchlistApi-Cxzs25LV.d.ts} +2325 -2259
- package/dist/{index-BSb_7Tx_.d.ts → index-C1Sl0lsa.d.ts} +1 -1
- package/dist/{index-VnEIrX1W.d.cts → index-xAErxElK.d.cts} +1 -1
- package/dist/index.cjs +371 -310
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +371 -310
- package/dist/index.mjs.map +1 -1
- package/dist/openapi/index.cjs +1637 -1545
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.d.cts +2 -2
- package/dist/openapi/index.d.ts +2 -2
- package/dist/openapi/index.mjs +1632 -1545
- package/dist/openapi/index.mjs.map +1 -1
- package/dist/stream/index.d.cts +2 -2
- package/dist/stream/index.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,46 +1,353 @@
|
|
|
1
|
-
|
|
1
|
+
# ChainStream JavaScript/TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@chainstream-io/sdk)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
* Node.js
|
|
7
|
-
* Webpack
|
|
8
|
-
* Browserify
|
|
6
|
+
A comprehensive JavaScript/TypeScript SDK for interacting with the ChainStream DEX Aggregator API and real-time streaming services. This SDK provides full TypeScript support and works seamlessly in Node.js, browser, and modern bundler environments.
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
* ES5 - you must have a Promises/A+ library installed
|
|
12
|
-
* ES6
|
|
8
|
+
## Features
|
|
13
9
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
- 🔄 **Real-time Streaming**: WebSocket-based real-time data streaming for tokens, trades, wallets, and more
|
|
11
|
+
- 🪙 **Token Management**: Create, query, and manage tokens across multiple blockchains
|
|
12
|
+
- 💱 **DEX Aggregation**: Access to multiple decentralized exchanges with swap routing and quote services
|
|
13
|
+
- 💼 **Wallet Operations**: Track wallet balances, PnL, and token holdings
|
|
14
|
+
- 📊 **Trading Data**: Real-time trade data, market statistics, and ranking information
|
|
15
|
+
- 🔗 **Multi-chain Support**: Support for multiple blockchain networks
|
|
16
|
+
- 🎁 **Red Packet**: Create and manage red packet (hongbao) campaigns
|
|
17
|
+
- 📦 **IPFS Integration**: Upload and manage files on IPFS
|
|
18
|
+
- 🔍 **Blockchain Data**: Query blockchain information, gas prices, and transaction details
|
|
19
|
+
- ⚡ **Job Management**: Asynchronous job processing with SSE-based status tracking
|
|
20
|
+
- 📈 **Rankings & Analytics**: Token rankings, top traders, and market analytics
|
|
21
|
+
- 🎯 **Watchlist**: Manage token watchlists for monitoring
|
|
17
22
|
|
|
18
|
-
|
|
23
|
+
## Installation
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
```bash
|
|
26
|
+
npm install @chainstream-io/sdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
or
|
|
21
30
|
|
|
22
|
-
|
|
31
|
+
```bash
|
|
32
|
+
yarn add @chainstream-io/sdk
|
|
23
33
|
```
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
### Basic Usage
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { DexClient } from '@chainstream-io/sdk';
|
|
41
|
+
|
|
42
|
+
// Initialize client with access token
|
|
43
|
+
const client = new DexClient('your-access-token');
|
|
44
|
+
|
|
45
|
+
// Use API services
|
|
46
|
+
const tokens = await client.token.listTokens({
|
|
47
|
+
chain: 'solana',
|
|
48
|
+
limit: 10
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
console.log(tokens);
|
|
26
52
|
```
|
|
27
53
|
|
|
28
|
-
###
|
|
54
|
+
### Using Token Provider
|
|
29
55
|
|
|
30
|
-
|
|
56
|
+
For dynamic token management:
|
|
31
57
|
|
|
32
|
-
|
|
58
|
+
```typescript
|
|
59
|
+
import { DexClient, TokenProvider } from '@chainstream-io/sdk';
|
|
33
60
|
|
|
34
|
-
|
|
61
|
+
class MyTokenProvider implements TokenProvider {
|
|
62
|
+
async getToken(): Promise<string> {
|
|
63
|
+
// Fetch token from your auth service
|
|
64
|
+
const response = await fetch('https://your-auth-service.com/token');
|
|
65
|
+
const data = await response.json();
|
|
66
|
+
return data.accessToken;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const client = new DexClient(new MyTokenProvider());
|
|
71
|
+
```
|
|
35
72
|
|
|
36
|
-
|
|
73
|
+
### Custom Configuration
|
|
37
74
|
|
|
75
|
+
```typescript
|
|
76
|
+
const client = new DexClient('your-access-token', {
|
|
77
|
+
serverUrl: 'https://api-dex.chainstream.io',
|
|
78
|
+
streamUrl: 'wss://realtime-dex.chainstream.io/connection/websocket',
|
|
79
|
+
debug: true
|
|
80
|
+
});
|
|
38
81
|
```
|
|
39
|
-
|
|
82
|
+
|
|
83
|
+
## API Services
|
|
84
|
+
|
|
85
|
+
The SDK provides the following API services through the `DexClient`:
|
|
86
|
+
|
|
87
|
+
### Token API (`client.token`)
|
|
88
|
+
- List and search tokens
|
|
89
|
+
- Get token details, metadata, and market data
|
|
90
|
+
- Query token holders and supply information
|
|
91
|
+
- Get token price data and statistics
|
|
92
|
+
|
|
93
|
+
### DEX API (`client.dex`)
|
|
94
|
+
- List available DEXes
|
|
95
|
+
- Get swap quotes and routes
|
|
96
|
+
- Execute token swaps
|
|
97
|
+
- Create new tokens
|
|
98
|
+
|
|
99
|
+
### DEX Pool API (`client.dexpool`)
|
|
100
|
+
- Query DEX pool information
|
|
101
|
+
- Get pool balances and liquidity data
|
|
102
|
+
|
|
103
|
+
### Trade API (`client.trade`)
|
|
104
|
+
- Get trade history and details
|
|
105
|
+
- Query trade events and statistics
|
|
106
|
+
|
|
107
|
+
### Wallet API (`client.wallet`)
|
|
108
|
+
- Get wallet balances
|
|
109
|
+
- Calculate wallet PnL (Profit and Loss)
|
|
110
|
+
- Query wallet token holdings
|
|
111
|
+
|
|
112
|
+
### Ranking API (`client.ranking`)
|
|
113
|
+
- Get token rankings
|
|
114
|
+
- Query top traders
|
|
115
|
+
- Access gainers and losers data
|
|
116
|
+
|
|
117
|
+
### Transaction API (`client.transaction`)
|
|
118
|
+
- Send transactions
|
|
119
|
+
- Estimate gas limits
|
|
120
|
+
- Get gas prices
|
|
121
|
+
|
|
122
|
+
### Blockchain API (`client.blockchain`)
|
|
123
|
+
- Query blockchain information
|
|
124
|
+
- Get latest block data
|
|
125
|
+
- Access network identification data
|
|
126
|
+
|
|
127
|
+
### Moonshot API (`client.moonshot`)
|
|
128
|
+
- Create tokens on Solana Moonshot platform
|
|
129
|
+
- Submit token creation transactions
|
|
130
|
+
|
|
131
|
+
### Pumpfun API (`client.pumpfun`)
|
|
132
|
+
- Create tokens on Pumpfun platform
|
|
133
|
+
- Manage Pumpfun token operations
|
|
134
|
+
|
|
135
|
+
### Red Packet API (`client.redPacket`)
|
|
136
|
+
- Create red packet campaigns
|
|
137
|
+
- Claim red packets
|
|
138
|
+
- Query red packet details and claims
|
|
139
|
+
|
|
140
|
+
### IPFS API (`client.ipfs`)
|
|
141
|
+
- Upload files to IPFS
|
|
142
|
+
- Query IPFS file information
|
|
143
|
+
|
|
144
|
+
### Watchlist API (`client.watchlist`)
|
|
145
|
+
- Create and manage watchlists
|
|
146
|
+
- Add/remove tokens from watchlists
|
|
147
|
+
|
|
148
|
+
### Jobs API (`client.jobs`)
|
|
149
|
+
- Query job status
|
|
150
|
+
- Get job details
|
|
151
|
+
|
|
152
|
+
## Real-time Streaming
|
|
153
|
+
|
|
154
|
+
The SDK includes a powerful streaming API for real-time data:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
// Subscribe to token updates
|
|
158
|
+
const unsubscribe = client.stream.subscribeTokenMetadata(
|
|
159
|
+
'solana',
|
|
160
|
+
'token-address',
|
|
161
|
+
(data) => {
|
|
162
|
+
console.log('Token metadata updated:', data);
|
|
163
|
+
}
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
// Subscribe to trade events
|
|
167
|
+
const unsubscribeTrade = client.stream.subscribeTradeActivity(
|
|
168
|
+
'solana',
|
|
169
|
+
{ token: 'token-address' },
|
|
170
|
+
(data) => {
|
|
171
|
+
console.log('New trade:', data);
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
// Subscribe to wallet balance changes
|
|
176
|
+
const unsubscribeBalance = client.stream.subscribeWalletBalance(
|
|
177
|
+
'solana',
|
|
178
|
+
'wallet-address',
|
|
179
|
+
(data) => {
|
|
180
|
+
console.log('Balance updated:', data);
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
// Unsubscribe when done
|
|
185
|
+
unsubscribe();
|
|
186
|
+
unsubscribeTrade();
|
|
187
|
+
unsubscribeBalance();
|
|
40
188
|
```
|
|
41
189
|
|
|
42
|
-
|
|
190
|
+
### Batch Subscriptions
|
|
191
|
+
|
|
192
|
+
For efficient bulk operations:
|
|
43
193
|
|
|
194
|
+
```typescript
|
|
195
|
+
// Batch multiple subscriptions
|
|
196
|
+
const unsubscribes = client.stream.batchSubscribe(() => {
|
|
197
|
+
const unsub1 = client.stream.subscribeTokenMetadata(
|
|
198
|
+
'solana',
|
|
199
|
+
'token1',
|
|
200
|
+
(data) => console.log('Token 1:', data)
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const unsub2 = client.stream.subscribeTokenMetadata(
|
|
204
|
+
'solana',
|
|
205
|
+
'token2',
|
|
206
|
+
(data) => console.log('Token 2:', data)
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
return [unsub1, unsub2];
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// Unsubscribe all at once
|
|
213
|
+
client.stream.batchUnsubscribe(unsubscribes);
|
|
44
214
|
```
|
|
45
|
-
|
|
215
|
+
|
|
216
|
+
## Job Management
|
|
217
|
+
|
|
218
|
+
For long-running operations, use the job system:
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
// Start a job (returns job ID)
|
|
222
|
+
const job = await client.jobs.createJob({
|
|
223
|
+
// job parameters
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// Wait for job completion
|
|
227
|
+
try {
|
|
228
|
+
const result = await client.waitForJob(job.id, 60000); // 60 second timeout
|
|
229
|
+
console.log('Job completed:', result);
|
|
230
|
+
} catch (error) {
|
|
231
|
+
console.error('Job failed:', error);
|
|
232
|
+
}
|
|
46
233
|
```
|
|
234
|
+
|
|
235
|
+
## Usage Examples
|
|
236
|
+
|
|
237
|
+
### Get Token List
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
const tokens = await client.token.listTokens({
|
|
241
|
+
chain: 'solana',
|
|
242
|
+
limit: 20,
|
|
243
|
+
offset: 0
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
console.log(`Found ${tokens.data.length} tokens`);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Get Swap Quote
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
const quote = await client.dex.getQuote({
|
|
253
|
+
chain: 'solana',
|
|
254
|
+
swapInput: {
|
|
255
|
+
fromToken: 'SOL',
|
|
256
|
+
toToken: 'USDC',
|
|
257
|
+
amount: '1000000000', // 1 SOL (in smallest unit)
|
|
258
|
+
slippage: 0.01 // 1%
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
console.log(`You'll receive ${quote.toAmount} ${quote.toToken}`);
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Execute Swap
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
const swap = await client.dex.swap({
|
|
269
|
+
chain: 'solana',
|
|
270
|
+
swapInput: {
|
|
271
|
+
fromToken: 'SOL',
|
|
272
|
+
toToken: 'USDC',
|
|
273
|
+
amount: '1000000000',
|
|
274
|
+
slippage: 0.01,
|
|
275
|
+
wallet: 'your-wallet-address'
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
console.log('Swap transaction:', swap.txHash);
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Get Wallet Balance
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
const balance = await client.wallet.getWalletBalances({
|
|
286
|
+
chain: 'solana',
|
|
287
|
+
address: 'wallet-address'
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
console.log('Wallet balances:', balance.balances);
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Get Wallet PnL
|
|
294
|
+
|
|
295
|
+
```typescript
|
|
296
|
+
const pnl = await client.wallet.getWalletPnl({
|
|
297
|
+
chain: 'solana',
|
|
298
|
+
address: 'wallet-address'
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
console.log('Wallet PnL:', pnl);
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### Create Red Packet
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
const redPacket = await client.redPacket.createRedPacket({
|
|
308
|
+
chain: 'solana',
|
|
309
|
+
createRedPacketInput: {
|
|
310
|
+
token: 'USDC',
|
|
311
|
+
totalAmount: '1000000',
|
|
312
|
+
count: 10,
|
|
313
|
+
// ... other parameters
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
console.log('Red packet created:', redPacket.id);
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Upload to IPFS
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
const file = new File(['content'], 'filename.txt');
|
|
324
|
+
const ipfsResult = await client.ipfs.uploadFile({
|
|
325
|
+
file: file
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
console.log('IPFS hash:', ipfsResult.hash);
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Get Token Rankings
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
const rankings = await client.ranking.getTokenRankings({
|
|
335
|
+
chain: 'solana',
|
|
336
|
+
type: 'volume',
|
|
337
|
+
limit: 10
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
console.log('Top tokens:', rankings.data);
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## TypeScript Support
|
|
344
|
+
|
|
345
|
+
The SDK is written in TypeScript and provides full type definitions. All API methods, request parameters, and response types are fully typed for better developer experience and IDE autocomplete support.
|
|
346
|
+
|
|
347
|
+
## License
|
|
348
|
+
|
|
349
|
+
MIT
|
|
350
|
+
|
|
351
|
+
## Support
|
|
352
|
+
|
|
353
|
+
For issues, questions, or contributions, please visit our [GitHub repository](https://github.com/chainstream-io/openapi-sdk-generator).
|