@covalenthq/client-sdk 2.3.5 → 2.3.6
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 +596 -596
- package/dist/index.js +201 -213
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,596 +1,596 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<a href="https://goldrush.dev/products/goldrush/" target="_blank" rel="noopener noreferrer">
|
|
3
|
-
<img alt="GoldRush TS SDK Logo" src="./repo-static/ts-sdk-banner.png" style="max-width: 100%;"/>
|
|
4
|
-
</a>
|
|
5
|
-
</div>
|
|
6
|
-
|
|
7
|
-
<br/>
|
|
8
|
-
|
|
9
|
-
<p align="center">
|
|
10
|
-
<a href="https://www.npmjs.com/package/@covalenthq/client-sdk">
|
|
11
|
-
<img src="https://img.shields.io/npm/v/@covalenthq/client-sdk" alt="NPM">
|
|
12
|
-
</a>
|
|
13
|
-
<a href="https://www.npmjs.com/package/@covalenthq/client-sdk">
|
|
14
|
-
<img src="https://img.shields.io/npm/dm/@covalenthq/client-sdk" alt="NPM downloads">
|
|
15
|
-
</a>
|
|
16
|
-
<img src="https://img.shields.io/github/license/covalenthq/covalent-api-sdk-ts" alt="Apache-2.0">
|
|
17
|
-
</p>
|
|
18
|
-
|
|
19
|
-
# GoldRush SDK for TypeScript
|
|
20
|
-
|
|
21
|
-
The GoldRush SDK is the fastest way to integrate the GoldRush API for working with blockchain data. The SDK works with all [supported chains](https://www.covalenthq.com/docs/networks/) including Mainnets and Testnets.
|
|
22
|
-
|
|
23
|
-
> Use with [`NodeJS v18`](https://nodejs.org/en) or above for best results.
|
|
24
|
-
|
|
25
|
-
> The GoldRush API is required. You can register for a free key on [GoldRush's website](https://goldrush.dev/platform/apikey)
|
|
26
|
-
|
|
27
|
-
## Using the SDK
|
|
28
|
-
|
|
29
|
-
> You can also follow the [video tutorial](https://www.youtube.com/watch?v=XSpPJP2w62E&ab_channel=Covalent)
|
|
30
|
-
|
|
31
|
-
1. Install the dependencies
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
npm install @covalenthq/client-sdk
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
2. Create a client using the `GoldRushClient`
|
|
38
|
-
|
|
39
|
-
```ts
|
|
40
|
-
import { GoldRushClient, Chains } from "@covalenthq/client-sdk";
|
|
41
|
-
|
|
42
|
-
const client = new GoldRushClient("<YOUR_API_KEY>");
|
|
43
|
-
|
|
44
|
-
const ApiServices = async () => {
|
|
45
|
-
try {
|
|
46
|
-
const balanceResp =
|
|
47
|
-
await client.BalanceService.getTokenBalancesForWalletAddress(
|
|
48
|
-
"eth-mainnet",
|
|
49
|
-
"0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de"
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
if (balanceResp.error) {
|
|
53
|
-
throw balanceResp;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
console.log(balanceResp.data);
|
|
57
|
-
} catch (error) {
|
|
58
|
-
console.error(error);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
The `GoldRushClient` can be configured with a second object argument, `settings`, and a third argument for `streamingConfig`. The settings offered are
|
|
64
|
-
|
|
65
|
-
1. **debug**: A boolean that enables server logs of the API calls, enhanced with the request URL, response time and code, and other settings. It is set as `false` by default.
|
|
66
|
-
2. **threadCount**: A number that sets the number of concurrent requests allowed. It is set as `2` by default.
|
|
67
|
-
3. **enableRetry**: A boolean that enables retrying the API endpoint in case of a `429 - rate limit` error. It is set as `true` by default.
|
|
68
|
-
4. **maxRetries**: A number that sets the number of retries to be made in case of `429 - rate limit` error. To be in effect, it requires `enableRetry` to be enabled. It is set as `2` by default.
|
|
69
|
-
5. **retryDelay**: A number that sets the delay in `ms` for retrying the API endpoint in case of `429 - rate limit` error. To be in effect, it requires `enableRetry` to be enabled. It is set as `2` by default.
|
|
70
|
-
6. **source**: A string that defines the `source` of the request of better analytics.
|
|
71
|
-
|
|
72
|
-
The `streamingConfig` is optional and configures the real-time streaming service. The available options are:
|
|
73
|
-
|
|
74
|
-
1. **shouldRetry**: A function that determines whether to retry connection based on retry count. Defaults to retry up to 5 times.
|
|
75
|
-
2. **maxReconnectAttempts**: Maximum number of reconnection attempts. Defaults to `5`.
|
|
76
|
-
3. **onConnecting**: Callback function triggered when connecting to the streaming service.
|
|
77
|
-
4. **onOpened**: Callback function triggered when connection is successfully established.
|
|
78
|
-
5. **onClosed**: Callback function triggered when connection is closed.
|
|
79
|
-
6. **onError**: Callback function triggered when an error occurs.
|
|
80
|
-
|
|
81
|
-
## Features
|
|
82
|
-
|
|
83
|
-
### 1. Name Resolution
|
|
84
|
-
|
|
85
|
-
The GoldRush SDK natively resolves the underlying wallet address for the following
|
|
86
|
-
|
|
87
|
-
1. ENS Domains (e.g. `demo.eth`)
|
|
88
|
-
2. Lens Handles (e.g. `demo.lens`)
|
|
89
|
-
3. Unstoppable Domains (e.g. `demo.x`)
|
|
90
|
-
4. RNS Domains (e.g. `demo.ron`)
|
|
91
|
-
|
|
92
|
-
### 2. Query Parameters
|
|
93
|
-
|
|
94
|
-
All the API call arguments have an option to pass `typed objects` as Query parameters.
|
|
95
|
-
|
|
96
|
-
For example, the following sets the `quoteCurrency` query parameter to `CAD` and the parameter `nft` to `true` for fetching all the token balances, including NFTs, for a wallet address:
|
|
97
|
-
|
|
98
|
-
```ts
|
|
99
|
-
const resp = await client.BalanceService.getTokenBalancesForWalletAddress(
|
|
100
|
-
"eth-mainnet",
|
|
101
|
-
"0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de",
|
|
102
|
-
{
|
|
103
|
-
quoteCurrency: "CAD",
|
|
104
|
-
nft: true,
|
|
105
|
-
}
|
|
106
|
-
);
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### 3. Exported Types
|
|
110
|
-
|
|
111
|
-
All the `interface`s used, for arguments, query parameters and responses are also exported from the package which can be used for custom usage.
|
|
112
|
-
|
|
113
|
-
For example, explicitly typecasting the response
|
|
114
|
-
|
|
115
|
-
```ts
|
|
116
|
-
import {
|
|
117
|
-
GoldRushClient,
|
|
118
|
-
type BalancesResponse,
|
|
119
|
-
type BalanceItem,
|
|
120
|
-
} from "@covalenthq/client-sdk";
|
|
121
|
-
|
|
122
|
-
const resp = await client.BalanceService.getTokenBalancesForWalletAddress(
|
|
123
|
-
"eth-mainnet",
|
|
124
|
-
"0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de",
|
|
125
|
-
{
|
|
126
|
-
quoteCurrency: "CAD",
|
|
127
|
-
nft: true,
|
|
128
|
-
}
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
const data: BalancesResponse = resp.data;
|
|
132
|
-
const items: BalanceItem[] = resp.data.items;
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### 4. Multiple Chain input formats
|
|
136
|
-
|
|
137
|
-
The SDK supports the following formats for the chain input:
|
|
138
|
-
|
|
139
|
-
1. Chain Name (e.g. `eth-mainnet`)
|
|
140
|
-
2. Chain ID (e.g. `1`)
|
|
141
|
-
3. Chain Name Enum (e.g. `ChainName.ETH_MAINNET`)
|
|
142
|
-
4. Chain ID Enum (e.g. `ChainID.ETH_MAINNET`)
|
|
143
|
-
|
|
144
|
-
### 5. Additional Non-Paginated methods
|
|
145
|
-
|
|
146
|
-
For paginated responses, the GoldRush API can at max support 100 items per page. However, the Covalent SDK leverages generators to _seamlessly fetch all items without the user having to deal with pagination_.
|
|
147
|
-
|
|
148
|
-
For example, the following fetches ALL transactions for `0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de` on Ethereum:
|
|
149
|
-
|
|
150
|
-
```ts
|
|
151
|
-
import { GoldRushClient } from "@covalenthq/client-sdk";
|
|
152
|
-
|
|
153
|
-
const ApiServices = async () => {
|
|
154
|
-
const client = new GoldRushClient("<YOUR_API_KEY>");
|
|
155
|
-
try {
|
|
156
|
-
for await (const tx of client.TransactionService.getAllTransactionsForAddress(
|
|
157
|
-
"eth-mainnet",
|
|
158
|
-
"0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de"
|
|
159
|
-
)) {
|
|
160
|
-
console.log("tx", tx);
|
|
161
|
-
}
|
|
162
|
-
} catch (error) {
|
|
163
|
-
console.log(error.message);
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
### 6. Executable pagination functions
|
|
169
|
-
|
|
170
|
-
Paginated methods have been enhanced with the introduction of `next()` and `prev()` support functions. These functions facilitate a smoother transition for developers navigating through our `links` object, which includes `prev` and `next` fields. Instead of requiring developers to manually extract values from these fields and create JavaScript API fetch calls for the URL values, the new `next()` and `prev()` functions provide a streamlined approach, allowing developers to simulate this behavior more efficiently.
|
|
171
|
-
|
|
172
|
-
```ts
|
|
173
|
-
import { GoldRushClient } from "@covalenthq/client-sdk";
|
|
174
|
-
|
|
175
|
-
const client = new GoldRushClient("<YOUR_API_KEY>");
|
|
176
|
-
const resp = await client.TransactionService.getAllTransactionsForAddressByPage(
|
|
177
|
-
"eth-mainnet",
|
|
178
|
-
"0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de"
|
|
179
|
-
); // assuming resp.data.current_page is 10
|
|
180
|
-
if (resp.data !== null) {
|
|
181
|
-
const prevPage = await resp.data.prev(); // will retrieve page 9
|
|
182
|
-
console.log(prevPage.data);
|
|
183
|
-
}
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
### 7. Utility Functions
|
|
187
|
-
|
|
188
|
-
1. **bigIntParser**: Formats input as a `bigint` value. For example
|
|
189
|
-
|
|
190
|
-
```ts
|
|
191
|
-
bigIntParser("-123"); // -123n
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
You can explore more examples [here](./test/unit/bigint-parser.test.ts)
|
|
195
|
-
|
|
196
|
-
2. **calculatePrettyBalance**: Formats large and raw numbers and bigints to human friendly format. For example
|
|
197
|
-
|
|
198
|
-
```ts
|
|
199
|
-
calculatePrettyBalance(1.5, 3, true, 4); // "0.0015"
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
You can explore more examples [here](./test/unit/calculate-pretty-balance.test.ts)
|
|
203
|
-
|
|
204
|
-
3. **isValidApiKey**: Checks for the input as a valid GoldRush API Key. For example
|
|
205
|
-
|
|
206
|
-
```ts
|
|
207
|
-
isValidApiKey(cqt_wF123); // false
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
You can explore more examples [here](./test/unit/is-valid-api-key.test.ts)
|
|
211
|
-
|
|
212
|
-
4. **prettifyCurrency**: Formats large and raw numbers and bigints to human friendly currency format. For example
|
|
213
|
-
|
|
214
|
-
```ts
|
|
215
|
-
prettifyCurrency(89.0, 2, "CAD"); // "CA$89.00"
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
You can explore more examples [here](./test/unit/is-valid-api-key.test.ts)
|
|
219
|
-
|
|
220
|
-
5. **timestampParser**: Convert ISO timestamps to various human-readable formats
|
|
221
|
-
|
|
222
|
-
```ts
|
|
223
|
-
timestampParser("2024-10-16T12:39:23.000Z", "descriptive"); // "October 16 2024 at 18:09:23"
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
You can explore more examples [here](./test/unit/timestamp-parser.test.ts)
|
|
227
|
-
|
|
228
|
-
### 8. Real-time Streaming
|
|
229
|
-
|
|
230
|
-
The GoldRush SDK now supports real-time streaming of blockchain data via WebSocket connections. This allows you to subscribe to live data feeds for OHLCV (Open, High, Low, Close, Volume) data for trading pairs and tokens, new DEX pair creations, wallet activity, and more.
|
|
231
|
-
|
|
232
|
-
```ts
|
|
233
|
-
import {
|
|
234
|
-
GoldRushClient,
|
|
235
|
-
StreamingChain,
|
|
236
|
-
StreamingInterval,
|
|
237
|
-
StreamingTimeframe,
|
|
238
|
-
StreamingProtocol,
|
|
239
|
-
} from "@covalenthq/client-sdk";
|
|
240
|
-
|
|
241
|
-
const client = new GoldRushClient(
|
|
242
|
-
"<YOUR_API_KEY>",
|
|
243
|
-
{},
|
|
244
|
-
{
|
|
245
|
-
onConnecting: () => console.log("Connecting to streaming service..."),
|
|
246
|
-
onOpened: () => console.log("Connected to streaming service!"),
|
|
247
|
-
onClosed: () => console.log("Disconnected from streaming service"),
|
|
248
|
-
onError: (error) => console.error("Streaming error:", error),
|
|
249
|
-
}
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
// Subscribe to OHLCV data for trading pairs
|
|
253
|
-
const unsubscribePairs = client.StreamingService.subscribeToOHLCVPairs(
|
|
254
|
-
{
|
|
255
|
-
chain_name: StreamingChain.BASE_MAINNET,
|
|
256
|
-
pair_addresses: ["0x9c087Eb773291e50CF6c6a90ef0F4500e349B903"],
|
|
257
|
-
interval: StreamingInterval.ONE_MINUTE,
|
|
258
|
-
timeframe: StreamingTimeframe.ONE_HOUR,
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
next: (data) => {
|
|
262
|
-
console.log("Received OHLCV pair data:", data);
|
|
263
|
-
},
|
|
264
|
-
error: (error) => {
|
|
265
|
-
console.error("Streaming error:", error);
|
|
266
|
-
},
|
|
267
|
-
complete: () => {
|
|
268
|
-
console.log("Stream completed");
|
|
269
|
-
},
|
|
270
|
-
}
|
|
271
|
-
);
|
|
272
|
-
|
|
273
|
-
// Unsubscribe when done
|
|
274
|
-
// unsubscribePairs();
|
|
275
|
-
|
|
276
|
-
// Disconnect from streaming service when finished
|
|
277
|
-
// await client.StreamingService.disconnect();
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
#### Multiple Subscriptions
|
|
281
|
-
|
|
282
|
-
The SDK uses a singleton WebSocket client internally, allowing you to create multiple subscriptions through the same `GoldRushClient`.
|
|
283
|
-
|
|
284
|
-
```ts
|
|
285
|
-
// Create a single client
|
|
286
|
-
const client = new GoldRushClient("<YOUR_API_KEY>");
|
|
287
|
-
|
|
288
|
-
// Create multiple subscriptions through the same connection
|
|
289
|
-
const unsubscribePairs = client.StreamingService.subscribeToOHLCVPairs(
|
|
290
|
-
{
|
|
291
|
-
chain_name: StreamingChain.BASE_MAINNET,
|
|
292
|
-
pair_addresses: ["0x9c087Eb773291e50CF6c6a90ef0F4500e349B903"],
|
|
293
|
-
interval: StreamingInterval.ONE_MINUTE,
|
|
294
|
-
timeframe: StreamingTimeframe.ONE_HOUR,
|
|
295
|
-
},
|
|
296
|
-
{
|
|
297
|
-
next: (data) => console.log("OHLCV Pairs:", data),
|
|
298
|
-
}
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
const unsubscribeTokens = client.StreamingService.subscribeToOHLCVTokens(
|
|
302
|
-
{
|
|
303
|
-
chain_name: StreamingChain.BASE_MAINNET,
|
|
304
|
-
token_addresses: ["0x4B6104755AfB5Da4581B81C552DA3A25608c73B8"],
|
|
305
|
-
interval: StreamingInterval.ONE_MINUTE,
|
|
306
|
-
timeframe: StreamingTimeframe.ONE_HOUR,
|
|
307
|
-
},
|
|
308
|
-
{
|
|
309
|
-
next: (data) => console.log("OHLCV Tokens:", data),
|
|
310
|
-
}
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
const unsubscribeWallet = client.StreamingService.subscribeToWalletActivity(
|
|
314
|
-
{
|
|
315
|
-
chain_name: StreamingChain.BASE_MAINNET,
|
|
316
|
-
wallet_addresses: ["0xbaed383ede0e5d9d72430661f3285daa77e9439f"],
|
|
317
|
-
},
|
|
318
|
-
{
|
|
319
|
-
next: (data) => console.log("Wallet Activity:", data),
|
|
320
|
-
}
|
|
321
|
-
);
|
|
322
|
-
|
|
323
|
-
// Unsubscribe from individual streams when needed
|
|
324
|
-
// unsubscribePairs();
|
|
325
|
-
// unsubscribeTokens();
|
|
326
|
-
// unsubscribeWallet();
|
|
327
|
-
|
|
328
|
-
// Or disconnect from all streams at once
|
|
329
|
-
// await client.StreamingService.disconnect();
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
#### React Integration
|
|
333
|
-
|
|
334
|
-
For React applications, use the `useEffect` hook to properly manage subscription lifecycle:
|
|
335
|
-
|
|
336
|
-
```tsx
|
|
337
|
-
useEffect(() => {
|
|
338
|
-
const unsubscribe = client.StreamingService.rawQuery(
|
|
339
|
-
`subscription {
|
|
340
|
-
ohlcvCandlesForPair(
|
|
341
|
-
chain_name: BASE_MAINNET
|
|
342
|
-
pair_addresses: ["0x9c087Eb773291e50CF6c6a90ef0F4500e349B903"],
|
|
343
|
-
interval: StreamingInterval.ONE_MINUTE,
|
|
344
|
-
timeframe: StreamingTimeframe.ONE_HOUR,
|
|
345
|
-
) {
|
|
346
|
-
open
|
|
347
|
-
high
|
|
348
|
-
low
|
|
349
|
-
close
|
|
350
|
-
volume
|
|
351
|
-
price_usd
|
|
352
|
-
volume_usd
|
|
353
|
-
chain_name
|
|
354
|
-
pair_address
|
|
355
|
-
interval
|
|
356
|
-
timeframe
|
|
357
|
-
timestamp
|
|
358
|
-
}
|
|
359
|
-
}`,
|
|
360
|
-
{},
|
|
361
|
-
{
|
|
362
|
-
next: (data) => console.log("Received streaming data:", data),
|
|
363
|
-
error: (err) => console.error("Subscription error:", err),
|
|
364
|
-
complete: () => console.info("Subscription completed"),
|
|
365
|
-
}
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
// Cleanup function - unsubscribe when component unmounts
|
|
369
|
-
return () => {
|
|
370
|
-
unsubscribe();
|
|
371
|
-
};
|
|
372
|
-
}, []);
|
|
373
|
-
```
|
|
374
|
-
|
|
375
|
-
#### Raw Queries
|
|
376
|
-
|
|
377
|
-
You can also use raw GraphQL queries for more streamlined and selective data scenarios:
|
|
378
|
-
|
|
379
|
-
```ts
|
|
380
|
-
const unsubscribeNewPairs = client.StreamingService.rawQuery(
|
|
381
|
-
`subscription {
|
|
382
|
-
newPairs(
|
|
383
|
-
chain_name: BASE_MAINNET,
|
|
384
|
-
protocols: [UNISWAP_V2, UNISWAP_V3]
|
|
385
|
-
) {
|
|
386
|
-
chain_name
|
|
387
|
-
protocol
|
|
388
|
-
pair_address
|
|
389
|
-
tx_hash
|
|
390
|
-
liquidity
|
|
391
|
-
base_token_metadata {
|
|
392
|
-
contract_name
|
|
393
|
-
contract_ticker_symbol
|
|
394
|
-
}
|
|
395
|
-
quote_token_metadata {
|
|
396
|
-
contract_name
|
|
397
|
-
contract_ticker_symbol
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}`,
|
|
401
|
-
{},
|
|
402
|
-
{
|
|
403
|
-
next: (data) => console.log("Raw new pairs data:", data),
|
|
404
|
-
error: (error) => console.error("Error:", error),
|
|
405
|
-
}
|
|
406
|
-
);
|
|
407
|
-
|
|
408
|
-
// Raw query for token OHLCV data
|
|
409
|
-
const unsubscribeTokenOHLCV = client.StreamingService.rawQuery(
|
|
410
|
-
`subscription {
|
|
411
|
-
ohlcvCandlesForToken(
|
|
412
|
-
chain_name: BASE_MAINNET
|
|
413
|
-
token_addresses: ["0x4B6104755AfB5Da4581B81C552DA3A25608c73B8"]
|
|
414
|
-
interval: ONE_MINUTE
|
|
415
|
-
timeframe: ONE_HOUR
|
|
416
|
-
) {
|
|
417
|
-
open
|
|
418
|
-
high
|
|
419
|
-
low
|
|
420
|
-
close
|
|
421
|
-
volume
|
|
422
|
-
volume_usd
|
|
423
|
-
quote_rate
|
|
424
|
-
quote_rate_usd
|
|
425
|
-
timestamp
|
|
426
|
-
base_token {
|
|
427
|
-
contract_name
|
|
428
|
-
contract_ticker_symbol
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}`,
|
|
432
|
-
{},
|
|
433
|
-
{
|
|
434
|
-
next: (data) => console.log("Raw token OHLCV data:", data),
|
|
435
|
-
error: (error) => console.error("Error:", error),
|
|
436
|
-
}
|
|
437
|
-
);
|
|
438
|
-
```
|
|
439
|
-
|
|
440
|
-
### 9. Standardized (Error) Responses
|
|
441
|
-
|
|
442
|
-
All the responses are of the same standardized format
|
|
443
|
-
|
|
444
|
-
```ts
|
|
445
|
-
❴
|
|
446
|
-
"data": <object>,
|
|
447
|
-
"error": <boolean>,
|
|
448
|
-
"error_message": <string>,
|
|
449
|
-
"error_code": <number>
|
|
450
|
-
❵
|
|
451
|
-
```
|
|
452
|
-
|
|
453
|
-
## Supported Endpoints
|
|
454
|
-
|
|
455
|
-
The Covalent SDK provides comprehensive support for all Class A, Class B, and Pricing endpoints that are grouped under the following _Service_ namespaces:
|
|
456
|
-
|
|
457
|
-
<details>
|
|
458
|
-
<summary>
|
|
459
|
-
1. <strong>All Chains Service</strong>: Access to the data across multiple chains and addresses.
|
|
460
|
-
</summary>
|
|
461
|
-
|
|
462
|
-
- `getAddressActivity()`: Locate chains where an address is active on with a single API call.
|
|
463
|
-
- `getMultiChainMultiAddressTransactions()`: Fetch and render the transactions across multiple chains and addresses
|
|
464
|
-
- `getMultiChainBalances()`: Fetch the token balances of an address for multiple chains. (limited to 10 chains at a time)
|
|
465
|
-
</details>
|
|
466
|
-
|
|
467
|
-
<details>
|
|
468
|
-
<summary>
|
|
469
|
-
2. <strong>Security Service</strong>: Access to the token approvals API endpoints
|
|
470
|
-
</summary>
|
|
471
|
-
|
|
472
|
-
- `getApprovals()`: Get a list of approvals across all ERC20 token contracts categorized by spenders for a wallet's assets.
|
|
473
|
-
- `getNftApprovals()`: Get a list of approvals across all NFT contracts categorized by spenders for a wallet's assets.
|
|
474
|
-
</details>
|
|
475
|
-
|
|
476
|
-
<details>
|
|
477
|
-
<summary>
|
|
478
|
-
3. <strong>Balance Service</strong>: Access to the balances endpoints
|
|
479
|
-
</summary>
|
|
480
|
-
|
|
481
|
-
- `getTokenBalancesForWalletAddress()`: Fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
|
|
482
|
-
- `getHistoricalTokenBalancesForWalletAddress()`: Fetch the historical native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address at a given block height or date. Response includes daily prices and other metadata.
|
|
483
|
-
- `getHistoricalPortfolioForWalletAddress()`: Render a daily portfolio balance for an address broken down by the token. The timeframe is user-configurable, defaults to 30 days.
|
|
484
|
-
- `getErc20TransfersForWalletAddress()`: Render the transfer-in and transfer-out of a token along with historical prices from an address. (Paginated)
|
|
485
|
-
- `getErc20TransfersForWalletAddressByPage()`: Render the transfer-in and transfer-out of a token along with historical prices from an address. (NonPaginated)
|
|
486
|
-
- `getTokenHoldersV2ForTokenAddress()`: Get a list of all the token holders for a specified ERC20 or ERC721 token. Returns historic token holders when block-height is set (defaults to latest). Useful for building pie charts of token holders. (Paginated)
|
|
487
|
-
- `getTokenHoldersV2ForTokenAddressByPage()`: Get a list of all the token holders for a specified ERC20 or ERC721 token. Returns historic token holders when block-height is set (defaults to latest). Useful for building pie charts of token holders. (Nonpaginated)
|
|
488
|
-
- `getNativeTokenBalance()`: Get the native token balance for an address. This endpoint is required because native tokens are usually not ERC20 tokens and sometimes you want something lightweight.
|
|
489
|
-
</details>
|
|
490
|
-
|
|
491
|
-
<details>
|
|
492
|
-
<summary>
|
|
493
|
-
4. <strong>Base Service</strong>: Access to the address activity, log events, chain status, and block retrieval endpoints
|
|
494
|
-
</summary>
|
|
495
|
-
|
|
496
|
-
- `getBlock()`: Fetch and render a single block for a block explorer.
|
|
497
|
-
- `getLogs()`: Get all the event logs of the latest block, or for a range of blocks. Includes sender contract metadata as well as decoded logs.
|
|
498
|
-
- `getResolvedAddress()`: Used to resolve ENS, RNS and Unstoppable Domains addresses.
|
|
499
|
-
- `getBlockHeights()`: Get all the block heights within a particular date range. Useful for rendering a display where you sort blocks by day. (Paginated)
|
|
500
|
-
- `getBlockHeightsByPage()`: Get all the block heights within a particular date range. Useful for rendering a display where you sort blocks by day. (Nonpaginated)
|
|
501
|
-
- `getLogEventsByAddress()`: Get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions. (Paginated)
|
|
502
|
-
- `getLogEventsByAddressByPage()`: Get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions. (Nonpaginated)
|
|
503
|
-
- `getLogEventsByTopicHash()`: Get all event logs of the same topic hash across all contracts within a particular chain. Useful for cross-sectional analysis of event logs that are emitted on-chain. (Paginated)
|
|
504
|
-
- `getLogEventsByTopicHashByPage()`: Get all event logs of the same topic hash across all contracts within a particular chain. Useful for cross-sectional analysis of event logs that are emitted on-chain. (Nonpaginated)
|
|
505
|
-
- `getAllChains()`: Used to build internal dashboards for all supported chains on Covalent.
|
|
506
|
-
- `getAllChainStatus()`: Used to build internal status dashboards of all supported chains.
|
|
507
|
-
- `getGasPrices()`: Get real-time gas estimates for different transaction speeds on a specific network, enabling users to optimize transaction costs and confirmation times.
|
|
508
|
-
</details>
|
|
509
|
-
|
|
510
|
-
<details>
|
|
511
|
-
<summary>
|
|
512
|
-
5. <strong>Bitcoin Service</strong>: Access to the Bitcoin wallet endpoints
|
|
513
|
-
</summary>
|
|
514
|
-
|
|
515
|
-
- `getBitcoinHdWalletBalances()`: Fetch balances for each active child address derived from a Bitcoin HD wallet.
|
|
516
|
-
- `getTokenBalancesForWalletAddress()`: Fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
|
|
517
|
-
- `getTransactionsForBtcAddress()`: Used to fetch the full transaction history of a Bitcoin wallet. Only supports non-HD bitcoin addresses.
|
|
518
|
-
</details>
|
|
519
|
-
|
|
520
|
-
<details>
|
|
521
|
-
<summary>
|
|
522
|
-
6. <strong>NFT Service</strong>: Access to the NFT endpoints
|
|
523
|
-
</summary>
|
|
524
|
-
|
|
525
|
-
- `getChainCollections()`: Used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files. (Paginated)
|
|
526
|
-
- `getChainCollectionsByPage()`: Used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files. (Nonpaginated)
|
|
527
|
-
- `getNftsForAddress()`: Used to render the NFTs (including ERC721 and ERC1155) held by an address.
|
|
528
|
-
- `getTokenIdsForContractWithMetadata()`: Get NFT token IDs with metadata from a collection. Useful for building NFT card displays. (Paginated)
|
|
529
|
-
- `getTokenIdsForContractWithMetadataByPage()`: Get NFT token IDs with metadata from a collection. Useful for building NFT card displays. (Nonpaginated)
|
|
530
|
-
- `getNftMetadataForGivenTokenIDForContract()`: Get a single NFT metadata by token ID from a collection. Useful for building NFT card displays.
|
|
531
|
-
- `getNftTransactionsForContractTokenId()`: Get all transactions of an NFT token. Useful for building a transaction history table or price chart.
|
|
532
|
-
- `getTraitsForCollection()`: Used to fetch and render the traits of a collection as seen in rarity calculators.
|
|
533
|
-
- `getAttributesForTraitInCollection()`: Used to get the count of unique values for traits within an NFT collection.
|
|
534
|
-
- `getCollectionTraitsSummary()`: Used to calculate rarity scores for a collection based on its traits.
|
|
535
|
-
- `getHistoricalFloorPricesForCollection()`: Commonly used to render a price floor chart for an NFT collection.
|
|
536
|
-
- `getHistoricalVolumeForCollection()`: Commonly used to build a time-series chart of the transaction volume of an NFT collection.
|
|
537
|
-
- `getHistoricalSalesCountForCollection()`: Commonly used to build a time-series chart of the sales count of an NFT collection.
|
|
538
|
-
- `checkOwnershipInNft()`: Used to verify ownership of NFTs (including ERC-721 and ERC-1155) within a collection.
|
|
539
|
-
- `checkOwnershipInNftForSpecificTokenId()`: Used to verify ownership of a specific token (ERC-721 or ERC-1155) within a collection.
|
|
540
|
-
</details>
|
|
541
|
-
|
|
542
|
-
<details>
|
|
543
|
-
<summary>
|
|
544
|
-
7. <strong>Pricing Service</strong>: Access to the historical token prices endpoint
|
|
545
|
-
</summary>
|
|
546
|
-
|
|
547
|
-
- `getTokenPrices()`: Get historic prices of a token between date ranges. Supports native tokens.
|
|
548
|
-
- `getPoolSpotPrices()`: Get the spot token pair prices for a specified pool contract address. Supports pools on Uniswap V2, V3 and their forks.
|
|
549
|
-
</details>
|
|
550
|
-
|
|
551
|
-
<details>
|
|
552
|
-
<summary>
|
|
553
|
-
8. <strong>Transaction Service</strong>: Access to the transactions endpoints
|
|
554
|
-
</summary>
|
|
555
|
-
|
|
556
|
-
- `getAllTransactionsForAddress()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Paginated)
|
|
557
|
-
- `getAllTransactionsForAddressByPage()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Nonpaginated)
|
|
558
|
-
- `getPaginatedTransactionsForAddress()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
|
|
559
|
-
- `getTransaction()`: Fetch and render a single transaction including its decoded log events. Additionally return semantically decoded information for DEX trades, lending and NFT sales.
|
|
560
|
-
- `getTransactionsForBlockByPage()`: Fetch all transactions including their decoded log events in a block by page number and further flag interesting wallets or transactions.
|
|
561
|
-
- `getTransactionsForBlock()`: Fetch all transactions including their decoded log events in a block by block hash and further flag interesting wallets or transactions.
|
|
562
|
-
- `getTransactionSummary()`: Fetch the earliest and latest transactions, and the transaction count for a wallet. Calculate the age of the wallet and the time it has been idle and quickly gain insights into their engagement with web3.
|
|
563
|
-
- `getTimeBucketTransactionsForAddress()`: Fetch all transactions including their decoded log events in a 15-minute time bucket interval.
|
|
564
|
-
- `getEarliestTransactionsForAddress()`: Fetch and render the earliest transactions involving an address. Frequently seen in wallet applications.
|
|
565
|
-
</details>
|
|
566
|
-
|
|
567
|
-
<details>
|
|
568
|
-
<summary>
|
|
569
|
-
9. <strong>Streaming Service</strong>: Real-time blockchain data streaming via WebSocket connections
|
|
570
|
-
</summary>
|
|
571
|
-
|
|
572
|
-
- `getClient()`: Get the underlying GraphQL WebSocket client for direct access.
|
|
573
|
-
- `isConnected`: Check the connection status of the streaming service.
|
|
574
|
-
- `subscribeToOHLCVPairs()`: Subscribe to real-time OHLCV (Open, High, Low, Close, Volume) data for specific trading pairs. Supports multiple chains and configurable intervals and timeframes.
|
|
575
|
-
- `subscribeToOHLCVTokens()`: Subscribe to real-time OHLCV (Open, High, Low, Close, Volume) data for specific tokens. Tracks token prices across their primary DEX pools with configurable intervals and timeframes.
|
|
576
|
-
- `subscribeToTokenBalances()`: Subscribe to real-time token balance updates for a specific wallet address. Tracks balance changes across native and ERC-20 tokens with USD valuations.
|
|
577
|
-
- `subscribeToWalletActivity()`: Subscribe to real-time wallet activity including transactions, token transfers, and smart contract interactions. Provides decoded transaction details for swaps, transfers, bridges, deposits, withdrawals, and approvals.
|
|
578
|
-
- `subscribeToNewPairs()`: Subscribe to real-time notifications when new liquidity pairs are created on supported decentralized exchanges (DEXes). Supports Uniswap V2/V3 across Base, Ethereum, and BSC networks.
|
|
579
|
-
- `subscribeToUpdatePairs()`: Subscribe to real-time updates for specific trading pairs including price, volume, liquidity data, price deltas, and swap counts.
|
|
580
|
-
- `rawQuery()`: Execute custom GraphQL subscription queries for advanced streaming scenarios and future extensibility.
|
|
581
|
-
- `disconnect()`: Properly disconnect from the streaming service.
|
|
582
|
-
|
|
583
|
-
</details>
|
|
584
|
-
|
|
585
|
-
## Contributing
|
|
586
|
-
|
|
587
|
-
Contributions, issues and feature requests are welcome!
|
|
588
|
-
Feel free to check [issues](https://github.com/covalenthq/covalent-api-sdk-ts/issues) page.
|
|
589
|
-
|
|
590
|
-
## Show your support
|
|
591
|
-
|
|
592
|
-
Give a ⭐️ if this project helped you!
|
|
593
|
-
|
|
594
|
-
## License
|
|
595
|
-
|
|
596
|
-
This project is [Apache-2.0](./LICENSE) licensed.
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://goldrush.dev/products/goldrush/" target="_blank" rel="noopener noreferrer">
|
|
3
|
+
<img alt="GoldRush TS SDK Logo" src="./repo-static/ts-sdk-banner.png" style="max-width: 100%;"/>
|
|
4
|
+
</a>
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<br/>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/@covalenthq/client-sdk">
|
|
11
|
+
<img src="https://img.shields.io/npm/v/@covalenthq/client-sdk" alt="NPM">
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@covalenthq/client-sdk">
|
|
14
|
+
<img src="https://img.shields.io/npm/dm/@covalenthq/client-sdk" alt="NPM downloads">
|
|
15
|
+
</a>
|
|
16
|
+
<img src="https://img.shields.io/github/license/covalenthq/covalent-api-sdk-ts" alt="Apache-2.0">
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
# GoldRush SDK for TypeScript
|
|
20
|
+
|
|
21
|
+
The GoldRush SDK is the fastest way to integrate the GoldRush API for working with blockchain data. The SDK works with all [supported chains](https://www.covalenthq.com/docs/networks/) including Mainnets and Testnets.
|
|
22
|
+
|
|
23
|
+
> Use with [`NodeJS v18`](https://nodejs.org/en) or above for best results.
|
|
24
|
+
|
|
25
|
+
> The GoldRush API is required. You can register for a free key on [GoldRush's website](https://goldrush.dev/platform/apikey)
|
|
26
|
+
|
|
27
|
+
## Using the SDK
|
|
28
|
+
|
|
29
|
+
> You can also follow the [video tutorial](https://www.youtube.com/watch?v=XSpPJP2w62E&ab_channel=Covalent)
|
|
30
|
+
|
|
31
|
+
1. Install the dependencies
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install @covalenthq/client-sdk
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
2. Create a client using the `GoldRushClient`
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { GoldRushClient, Chains } from "@covalenthq/client-sdk";
|
|
41
|
+
|
|
42
|
+
const client = new GoldRushClient("<YOUR_API_KEY>");
|
|
43
|
+
|
|
44
|
+
const ApiServices = async () => {
|
|
45
|
+
try {
|
|
46
|
+
const balanceResp =
|
|
47
|
+
await client.BalanceService.getTokenBalancesForWalletAddress(
|
|
48
|
+
"eth-mainnet",
|
|
49
|
+
"0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de"
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (balanceResp.error) {
|
|
53
|
+
throw balanceResp;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
console.log(balanceResp.data);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error(error);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The `GoldRushClient` can be configured with a second object argument, `settings`, and a third argument for `streamingConfig`. The settings offered are
|
|
64
|
+
|
|
65
|
+
1. **debug**: A boolean that enables server logs of the API calls, enhanced with the request URL, response time and code, and other settings. It is set as `false` by default.
|
|
66
|
+
2. **threadCount**: A number that sets the number of concurrent requests allowed. It is set as `2` by default.
|
|
67
|
+
3. **enableRetry**: A boolean that enables retrying the API endpoint in case of a `429 - rate limit` error. It is set as `true` by default.
|
|
68
|
+
4. **maxRetries**: A number that sets the number of retries to be made in case of `429 - rate limit` error. To be in effect, it requires `enableRetry` to be enabled. It is set as `2` by default.
|
|
69
|
+
5. **retryDelay**: A number that sets the delay in `ms` for retrying the API endpoint in case of `429 - rate limit` error. To be in effect, it requires `enableRetry` to be enabled. It is set as `2` by default.
|
|
70
|
+
6. **source**: A string that defines the `source` of the request of better analytics.
|
|
71
|
+
|
|
72
|
+
The `streamingConfig` is optional and configures the real-time streaming service. The available options are:
|
|
73
|
+
|
|
74
|
+
1. **shouldRetry**: A function that determines whether to retry connection based on retry count. Defaults to retry up to 5 times.
|
|
75
|
+
2. **maxReconnectAttempts**: Maximum number of reconnection attempts. Defaults to `5`.
|
|
76
|
+
3. **onConnecting**: Callback function triggered when connecting to the streaming service.
|
|
77
|
+
4. **onOpened**: Callback function triggered when connection is successfully established.
|
|
78
|
+
5. **onClosed**: Callback function triggered when connection is closed.
|
|
79
|
+
6. **onError**: Callback function triggered when an error occurs.
|
|
80
|
+
|
|
81
|
+
## Features
|
|
82
|
+
|
|
83
|
+
### 1. Name Resolution
|
|
84
|
+
|
|
85
|
+
The GoldRush SDK natively resolves the underlying wallet address for the following
|
|
86
|
+
|
|
87
|
+
1. ENS Domains (e.g. `demo.eth`)
|
|
88
|
+
2. Lens Handles (e.g. `demo.lens`)
|
|
89
|
+
3. Unstoppable Domains (e.g. `demo.x`)
|
|
90
|
+
4. RNS Domains (e.g. `demo.ron`)
|
|
91
|
+
|
|
92
|
+
### 2. Query Parameters
|
|
93
|
+
|
|
94
|
+
All the API call arguments have an option to pass `typed objects` as Query parameters.
|
|
95
|
+
|
|
96
|
+
For example, the following sets the `quoteCurrency` query parameter to `CAD` and the parameter `nft` to `true` for fetching all the token balances, including NFTs, for a wallet address:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
const resp = await client.BalanceService.getTokenBalancesForWalletAddress(
|
|
100
|
+
"eth-mainnet",
|
|
101
|
+
"0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de",
|
|
102
|
+
{
|
|
103
|
+
quoteCurrency: "CAD",
|
|
104
|
+
nft: true,
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 3. Exported Types
|
|
110
|
+
|
|
111
|
+
All the `interface`s used, for arguments, query parameters and responses are also exported from the package which can be used for custom usage.
|
|
112
|
+
|
|
113
|
+
For example, explicitly typecasting the response
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import {
|
|
117
|
+
GoldRushClient,
|
|
118
|
+
type BalancesResponse,
|
|
119
|
+
type BalanceItem,
|
|
120
|
+
} from "@covalenthq/client-sdk";
|
|
121
|
+
|
|
122
|
+
const resp = await client.BalanceService.getTokenBalancesForWalletAddress(
|
|
123
|
+
"eth-mainnet",
|
|
124
|
+
"0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de",
|
|
125
|
+
{
|
|
126
|
+
quoteCurrency: "CAD",
|
|
127
|
+
nft: true,
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const data: BalancesResponse = resp.data;
|
|
132
|
+
const items: BalanceItem[] = resp.data.items;
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 4. Multiple Chain input formats
|
|
136
|
+
|
|
137
|
+
The SDK supports the following formats for the chain input:
|
|
138
|
+
|
|
139
|
+
1. Chain Name (e.g. `eth-mainnet`)
|
|
140
|
+
2. Chain ID (e.g. `1`)
|
|
141
|
+
3. Chain Name Enum (e.g. `ChainName.ETH_MAINNET`)
|
|
142
|
+
4. Chain ID Enum (e.g. `ChainID.ETH_MAINNET`)
|
|
143
|
+
|
|
144
|
+
### 5. Additional Non-Paginated methods
|
|
145
|
+
|
|
146
|
+
For paginated responses, the GoldRush API can at max support 100 items per page. However, the Covalent SDK leverages generators to _seamlessly fetch all items without the user having to deal with pagination_.
|
|
147
|
+
|
|
148
|
+
For example, the following fetches ALL transactions for `0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de` on Ethereum:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import { GoldRushClient } from "@covalenthq/client-sdk";
|
|
152
|
+
|
|
153
|
+
const ApiServices = async () => {
|
|
154
|
+
const client = new GoldRushClient("<YOUR_API_KEY>");
|
|
155
|
+
try {
|
|
156
|
+
for await (const tx of client.TransactionService.getAllTransactionsForAddress(
|
|
157
|
+
"eth-mainnet",
|
|
158
|
+
"0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de"
|
|
159
|
+
)) {
|
|
160
|
+
console.log("tx", tx);
|
|
161
|
+
}
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.log(error.message);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### 6. Executable pagination functions
|
|
169
|
+
|
|
170
|
+
Paginated methods have been enhanced with the introduction of `next()` and `prev()` support functions. These functions facilitate a smoother transition for developers navigating through our `links` object, which includes `prev` and `next` fields. Instead of requiring developers to manually extract values from these fields and create JavaScript API fetch calls for the URL values, the new `next()` and `prev()` functions provide a streamlined approach, allowing developers to simulate this behavior more efficiently.
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
import { GoldRushClient } from "@covalenthq/client-sdk";
|
|
174
|
+
|
|
175
|
+
const client = new GoldRushClient("<YOUR_API_KEY>");
|
|
176
|
+
const resp = await client.TransactionService.getAllTransactionsForAddressByPage(
|
|
177
|
+
"eth-mainnet",
|
|
178
|
+
"0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de"
|
|
179
|
+
); // assuming resp.data.current_page is 10
|
|
180
|
+
if (resp.data !== null) {
|
|
181
|
+
const prevPage = await resp.data.prev(); // will retrieve page 9
|
|
182
|
+
console.log(prevPage.data);
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### 7. Utility Functions
|
|
187
|
+
|
|
188
|
+
1. **bigIntParser**: Formats input as a `bigint` value. For example
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
bigIntParser("-123"); // -123n
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
You can explore more examples [here](./test/unit/bigint-parser.test.ts)
|
|
195
|
+
|
|
196
|
+
2. **calculatePrettyBalance**: Formats large and raw numbers and bigints to human friendly format. For example
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
calculatePrettyBalance(1.5, 3, true, 4); // "0.0015"
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
You can explore more examples [here](./test/unit/calculate-pretty-balance.test.ts)
|
|
203
|
+
|
|
204
|
+
3. **isValidApiKey**: Checks for the input as a valid GoldRush API Key. For example
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
isValidApiKey(cqt_wF123); // false
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
You can explore more examples [here](./test/unit/is-valid-api-key.test.ts)
|
|
211
|
+
|
|
212
|
+
4. **prettifyCurrency**: Formats large and raw numbers and bigints to human friendly currency format. For example
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
prettifyCurrency(89.0, 2, "CAD"); // "CA$89.00"
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
You can explore more examples [here](./test/unit/is-valid-api-key.test.ts)
|
|
219
|
+
|
|
220
|
+
5. **timestampParser**: Convert ISO timestamps to various human-readable formats
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
timestampParser("2024-10-16T12:39:23.000Z", "descriptive"); // "October 16 2024 at 18:09:23"
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
You can explore more examples [here](./test/unit/timestamp-parser.test.ts)
|
|
227
|
+
|
|
228
|
+
### 8. Real-time Streaming
|
|
229
|
+
|
|
230
|
+
The GoldRush SDK now supports real-time streaming of blockchain data via WebSocket connections. This allows you to subscribe to live data feeds for OHLCV (Open, High, Low, Close, Volume) data for trading pairs and tokens, new DEX pair creations, wallet activity, and more.
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
import {
|
|
234
|
+
GoldRushClient,
|
|
235
|
+
StreamingChain,
|
|
236
|
+
StreamingInterval,
|
|
237
|
+
StreamingTimeframe,
|
|
238
|
+
StreamingProtocol,
|
|
239
|
+
} from "@covalenthq/client-sdk";
|
|
240
|
+
|
|
241
|
+
const client = new GoldRushClient(
|
|
242
|
+
"<YOUR_API_KEY>",
|
|
243
|
+
{},
|
|
244
|
+
{
|
|
245
|
+
onConnecting: () => console.log("Connecting to streaming service..."),
|
|
246
|
+
onOpened: () => console.log("Connected to streaming service!"),
|
|
247
|
+
onClosed: () => console.log("Disconnected from streaming service"),
|
|
248
|
+
onError: (error) => console.error("Streaming error:", error),
|
|
249
|
+
}
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
// Subscribe to OHLCV data for trading pairs
|
|
253
|
+
const unsubscribePairs = client.StreamingService.subscribeToOHLCVPairs(
|
|
254
|
+
{
|
|
255
|
+
chain_name: StreamingChain.BASE_MAINNET,
|
|
256
|
+
pair_addresses: ["0x9c087Eb773291e50CF6c6a90ef0F4500e349B903"],
|
|
257
|
+
interval: StreamingInterval.ONE_MINUTE,
|
|
258
|
+
timeframe: StreamingTimeframe.ONE_HOUR,
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
next: (data) => {
|
|
262
|
+
console.log("Received OHLCV pair data:", data);
|
|
263
|
+
},
|
|
264
|
+
error: (error) => {
|
|
265
|
+
console.error("Streaming error:", error);
|
|
266
|
+
},
|
|
267
|
+
complete: () => {
|
|
268
|
+
console.log("Stream completed");
|
|
269
|
+
},
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
// Unsubscribe when done
|
|
274
|
+
// unsubscribePairs();
|
|
275
|
+
|
|
276
|
+
// Disconnect from streaming service when finished
|
|
277
|
+
// await client.StreamingService.disconnect();
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
#### Multiple Subscriptions
|
|
281
|
+
|
|
282
|
+
The SDK uses a singleton WebSocket client internally, allowing you to create multiple subscriptions through the same `GoldRushClient`.
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
// Create a single client
|
|
286
|
+
const client = new GoldRushClient("<YOUR_API_KEY>");
|
|
287
|
+
|
|
288
|
+
// Create multiple subscriptions through the same connection
|
|
289
|
+
const unsubscribePairs = client.StreamingService.subscribeToOHLCVPairs(
|
|
290
|
+
{
|
|
291
|
+
chain_name: StreamingChain.BASE_MAINNET,
|
|
292
|
+
pair_addresses: ["0x9c087Eb773291e50CF6c6a90ef0F4500e349B903"],
|
|
293
|
+
interval: StreamingInterval.ONE_MINUTE,
|
|
294
|
+
timeframe: StreamingTimeframe.ONE_HOUR,
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
next: (data) => console.log("OHLCV Pairs:", data),
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
const unsubscribeTokens = client.StreamingService.subscribeToOHLCVTokens(
|
|
302
|
+
{
|
|
303
|
+
chain_name: StreamingChain.BASE_MAINNET,
|
|
304
|
+
token_addresses: ["0x4B6104755AfB5Da4581B81C552DA3A25608c73B8"],
|
|
305
|
+
interval: StreamingInterval.ONE_MINUTE,
|
|
306
|
+
timeframe: StreamingTimeframe.ONE_HOUR,
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
next: (data) => console.log("OHLCV Tokens:", data),
|
|
310
|
+
}
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
const unsubscribeWallet = client.StreamingService.subscribeToWalletActivity(
|
|
314
|
+
{
|
|
315
|
+
chain_name: StreamingChain.BASE_MAINNET,
|
|
316
|
+
wallet_addresses: ["0xbaed383ede0e5d9d72430661f3285daa77e9439f"],
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
next: (data) => console.log("Wallet Activity:", data),
|
|
320
|
+
}
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
// Unsubscribe from individual streams when needed
|
|
324
|
+
// unsubscribePairs();
|
|
325
|
+
// unsubscribeTokens();
|
|
326
|
+
// unsubscribeWallet();
|
|
327
|
+
|
|
328
|
+
// Or disconnect from all streams at once
|
|
329
|
+
// await client.StreamingService.disconnect();
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
#### React Integration
|
|
333
|
+
|
|
334
|
+
For React applications, use the `useEffect` hook to properly manage subscription lifecycle:
|
|
335
|
+
|
|
336
|
+
```tsx
|
|
337
|
+
useEffect(() => {
|
|
338
|
+
const unsubscribe = client.StreamingService.rawQuery(
|
|
339
|
+
`subscription {
|
|
340
|
+
ohlcvCandlesForPair(
|
|
341
|
+
chain_name: BASE_MAINNET
|
|
342
|
+
pair_addresses: ["0x9c087Eb773291e50CF6c6a90ef0F4500e349B903"],
|
|
343
|
+
interval: StreamingInterval.ONE_MINUTE,
|
|
344
|
+
timeframe: StreamingTimeframe.ONE_HOUR,
|
|
345
|
+
) {
|
|
346
|
+
open
|
|
347
|
+
high
|
|
348
|
+
low
|
|
349
|
+
close
|
|
350
|
+
volume
|
|
351
|
+
price_usd
|
|
352
|
+
volume_usd
|
|
353
|
+
chain_name
|
|
354
|
+
pair_address
|
|
355
|
+
interval
|
|
356
|
+
timeframe
|
|
357
|
+
timestamp
|
|
358
|
+
}
|
|
359
|
+
}`,
|
|
360
|
+
{},
|
|
361
|
+
{
|
|
362
|
+
next: (data) => console.log("Received streaming data:", data),
|
|
363
|
+
error: (err) => console.error("Subscription error:", err),
|
|
364
|
+
complete: () => console.info("Subscription completed"),
|
|
365
|
+
}
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
// Cleanup function - unsubscribe when component unmounts
|
|
369
|
+
return () => {
|
|
370
|
+
unsubscribe();
|
|
371
|
+
};
|
|
372
|
+
}, []);
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
#### Raw Queries
|
|
376
|
+
|
|
377
|
+
You can also use raw GraphQL queries for more streamlined and selective data scenarios:
|
|
378
|
+
|
|
379
|
+
```ts
|
|
380
|
+
const unsubscribeNewPairs = client.StreamingService.rawQuery(
|
|
381
|
+
`subscription {
|
|
382
|
+
newPairs(
|
|
383
|
+
chain_name: BASE_MAINNET,
|
|
384
|
+
protocols: [UNISWAP_V2, UNISWAP_V3]
|
|
385
|
+
) {
|
|
386
|
+
chain_name
|
|
387
|
+
protocol
|
|
388
|
+
pair_address
|
|
389
|
+
tx_hash
|
|
390
|
+
liquidity
|
|
391
|
+
base_token_metadata {
|
|
392
|
+
contract_name
|
|
393
|
+
contract_ticker_symbol
|
|
394
|
+
}
|
|
395
|
+
quote_token_metadata {
|
|
396
|
+
contract_name
|
|
397
|
+
contract_ticker_symbol
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}`,
|
|
401
|
+
{},
|
|
402
|
+
{
|
|
403
|
+
next: (data) => console.log("Raw new pairs data:", data),
|
|
404
|
+
error: (error) => console.error("Error:", error),
|
|
405
|
+
}
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
// Raw query for token OHLCV data
|
|
409
|
+
const unsubscribeTokenOHLCV = client.StreamingService.rawQuery(
|
|
410
|
+
`subscription {
|
|
411
|
+
ohlcvCandlesForToken(
|
|
412
|
+
chain_name: BASE_MAINNET
|
|
413
|
+
token_addresses: ["0x4B6104755AfB5Da4581B81C552DA3A25608c73B8"]
|
|
414
|
+
interval: ONE_MINUTE
|
|
415
|
+
timeframe: ONE_HOUR
|
|
416
|
+
) {
|
|
417
|
+
open
|
|
418
|
+
high
|
|
419
|
+
low
|
|
420
|
+
close
|
|
421
|
+
volume
|
|
422
|
+
volume_usd
|
|
423
|
+
quote_rate
|
|
424
|
+
quote_rate_usd
|
|
425
|
+
timestamp
|
|
426
|
+
base_token {
|
|
427
|
+
contract_name
|
|
428
|
+
contract_ticker_symbol
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}`,
|
|
432
|
+
{},
|
|
433
|
+
{
|
|
434
|
+
next: (data) => console.log("Raw token OHLCV data:", data),
|
|
435
|
+
error: (error) => console.error("Error:", error),
|
|
436
|
+
}
|
|
437
|
+
);
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### 9. Standardized (Error) Responses
|
|
441
|
+
|
|
442
|
+
All the responses are of the same standardized format
|
|
443
|
+
|
|
444
|
+
```ts
|
|
445
|
+
❴
|
|
446
|
+
"data": <object>,
|
|
447
|
+
"error": <boolean>,
|
|
448
|
+
"error_message": <string>,
|
|
449
|
+
"error_code": <number>
|
|
450
|
+
❵
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
## Supported Endpoints
|
|
454
|
+
|
|
455
|
+
The Covalent SDK provides comprehensive support for all Class A, Class B, and Pricing endpoints that are grouped under the following _Service_ namespaces:
|
|
456
|
+
|
|
457
|
+
<details>
|
|
458
|
+
<summary>
|
|
459
|
+
1. <strong>All Chains Service</strong>: Access to the data across multiple chains and addresses.
|
|
460
|
+
</summary>
|
|
461
|
+
|
|
462
|
+
- `getAddressActivity()`: Locate chains where an address is active on with a single API call.
|
|
463
|
+
- `getMultiChainMultiAddressTransactions()`: Fetch and render the transactions across multiple chains and addresses
|
|
464
|
+
- `getMultiChainBalances()`: Fetch the token balances of an address for multiple chains. (limited to 10 chains at a time)
|
|
465
|
+
</details>
|
|
466
|
+
|
|
467
|
+
<details>
|
|
468
|
+
<summary>
|
|
469
|
+
2. <strong>Security Service</strong>: Access to the token approvals API endpoints
|
|
470
|
+
</summary>
|
|
471
|
+
|
|
472
|
+
- `getApprovals()`: Get a list of approvals across all ERC20 token contracts categorized by spenders for a wallet's assets.
|
|
473
|
+
- `getNftApprovals()`: Get a list of approvals across all NFT contracts categorized by spenders for a wallet's assets.
|
|
474
|
+
</details>
|
|
475
|
+
|
|
476
|
+
<details>
|
|
477
|
+
<summary>
|
|
478
|
+
3. <strong>Balance Service</strong>: Access to the balances endpoints
|
|
479
|
+
</summary>
|
|
480
|
+
|
|
481
|
+
- `getTokenBalancesForWalletAddress()`: Fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
|
|
482
|
+
- `getHistoricalTokenBalancesForWalletAddress()`: Fetch the historical native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address at a given block height or date. Response includes daily prices and other metadata.
|
|
483
|
+
- `getHistoricalPortfolioForWalletAddress()`: Render a daily portfolio balance for an address broken down by the token. The timeframe is user-configurable, defaults to 30 days.
|
|
484
|
+
- `getErc20TransfersForWalletAddress()`: Render the transfer-in and transfer-out of a token along with historical prices from an address. (Paginated)
|
|
485
|
+
- `getErc20TransfersForWalletAddressByPage()`: Render the transfer-in and transfer-out of a token along with historical prices from an address. (NonPaginated)
|
|
486
|
+
- `getTokenHoldersV2ForTokenAddress()`: Get a list of all the token holders for a specified ERC20 or ERC721 token. Returns historic token holders when block-height is set (defaults to latest). Useful for building pie charts of token holders. (Paginated)
|
|
487
|
+
- `getTokenHoldersV2ForTokenAddressByPage()`: Get a list of all the token holders for a specified ERC20 or ERC721 token. Returns historic token holders when block-height is set (defaults to latest). Useful for building pie charts of token holders. (Nonpaginated)
|
|
488
|
+
- `getNativeTokenBalance()`: Get the native token balance for an address. This endpoint is required because native tokens are usually not ERC20 tokens and sometimes you want something lightweight.
|
|
489
|
+
</details>
|
|
490
|
+
|
|
491
|
+
<details>
|
|
492
|
+
<summary>
|
|
493
|
+
4. <strong>Base Service</strong>: Access to the address activity, log events, chain status, and block retrieval endpoints
|
|
494
|
+
</summary>
|
|
495
|
+
|
|
496
|
+
- `getBlock()`: Fetch and render a single block for a block explorer.
|
|
497
|
+
- `getLogs()`: Get all the event logs of the latest block, or for a range of blocks. Includes sender contract metadata as well as decoded logs.
|
|
498
|
+
- `getResolvedAddress()`: Used to resolve ENS, RNS and Unstoppable Domains addresses.
|
|
499
|
+
- `getBlockHeights()`: Get all the block heights within a particular date range. Useful for rendering a display where you sort blocks by day. (Paginated)
|
|
500
|
+
- `getBlockHeightsByPage()`: Get all the block heights within a particular date range. Useful for rendering a display where you sort blocks by day. (Nonpaginated)
|
|
501
|
+
- `getLogEventsByAddress()`: Get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions. (Paginated)
|
|
502
|
+
- `getLogEventsByAddressByPage()`: Get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions. (Nonpaginated)
|
|
503
|
+
- `getLogEventsByTopicHash()`: Get all event logs of the same topic hash across all contracts within a particular chain. Useful for cross-sectional analysis of event logs that are emitted on-chain. (Paginated)
|
|
504
|
+
- `getLogEventsByTopicHashByPage()`: Get all event logs of the same topic hash across all contracts within a particular chain. Useful for cross-sectional analysis of event logs that are emitted on-chain. (Nonpaginated)
|
|
505
|
+
- `getAllChains()`: Used to build internal dashboards for all supported chains on Covalent.
|
|
506
|
+
- `getAllChainStatus()`: Used to build internal status dashboards of all supported chains.
|
|
507
|
+
- `getGasPrices()`: Get real-time gas estimates for different transaction speeds on a specific network, enabling users to optimize transaction costs and confirmation times.
|
|
508
|
+
</details>
|
|
509
|
+
|
|
510
|
+
<details>
|
|
511
|
+
<summary>
|
|
512
|
+
5. <strong>Bitcoin Service</strong>: Access to the Bitcoin wallet endpoints
|
|
513
|
+
</summary>
|
|
514
|
+
|
|
515
|
+
- `getBitcoinHdWalletBalances()`: Fetch balances for each active child address derived from a Bitcoin HD wallet.
|
|
516
|
+
- `getTokenBalancesForWalletAddress()`: Fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
|
|
517
|
+
- `getTransactionsForBtcAddress()`: Used to fetch the full transaction history of a Bitcoin wallet. Only supports non-HD bitcoin addresses.
|
|
518
|
+
</details>
|
|
519
|
+
|
|
520
|
+
<details>
|
|
521
|
+
<summary>
|
|
522
|
+
6. <strong>NFT Service</strong>: Access to the NFT endpoints
|
|
523
|
+
</summary>
|
|
524
|
+
|
|
525
|
+
- `getChainCollections()`: Used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files. (Paginated)
|
|
526
|
+
- `getChainCollectionsByPage()`: Used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files. (Nonpaginated)
|
|
527
|
+
- `getNftsForAddress()`: Used to render the NFTs (including ERC721 and ERC1155) held by an address.
|
|
528
|
+
- `getTokenIdsForContractWithMetadata()`: Get NFT token IDs with metadata from a collection. Useful for building NFT card displays. (Paginated)
|
|
529
|
+
- `getTokenIdsForContractWithMetadataByPage()`: Get NFT token IDs with metadata from a collection. Useful for building NFT card displays. (Nonpaginated)
|
|
530
|
+
- `getNftMetadataForGivenTokenIDForContract()`: Get a single NFT metadata by token ID from a collection. Useful for building NFT card displays.
|
|
531
|
+
- `getNftTransactionsForContractTokenId()`: Get all transactions of an NFT token. Useful for building a transaction history table or price chart.
|
|
532
|
+
- `getTraitsForCollection()`: Used to fetch and render the traits of a collection as seen in rarity calculators.
|
|
533
|
+
- `getAttributesForTraitInCollection()`: Used to get the count of unique values for traits within an NFT collection.
|
|
534
|
+
- `getCollectionTraitsSummary()`: Used to calculate rarity scores for a collection based on its traits.
|
|
535
|
+
- `getHistoricalFloorPricesForCollection()`: Commonly used to render a price floor chart for an NFT collection.
|
|
536
|
+
- `getHistoricalVolumeForCollection()`: Commonly used to build a time-series chart of the transaction volume of an NFT collection.
|
|
537
|
+
- `getHistoricalSalesCountForCollection()`: Commonly used to build a time-series chart of the sales count of an NFT collection.
|
|
538
|
+
- `checkOwnershipInNft()`: Used to verify ownership of NFTs (including ERC-721 and ERC-1155) within a collection.
|
|
539
|
+
- `checkOwnershipInNftForSpecificTokenId()`: Used to verify ownership of a specific token (ERC-721 or ERC-1155) within a collection.
|
|
540
|
+
</details>
|
|
541
|
+
|
|
542
|
+
<details>
|
|
543
|
+
<summary>
|
|
544
|
+
7. <strong>Pricing Service</strong>: Access to the historical token prices endpoint
|
|
545
|
+
</summary>
|
|
546
|
+
|
|
547
|
+
- `getTokenPrices()`: Get historic prices of a token between date ranges. Supports native tokens.
|
|
548
|
+
- `getPoolSpotPrices()`: Get the spot token pair prices for a specified pool contract address. Supports pools on Uniswap V2, V3 and their forks.
|
|
549
|
+
</details>
|
|
550
|
+
|
|
551
|
+
<details>
|
|
552
|
+
<summary>
|
|
553
|
+
8. <strong>Transaction Service</strong>: Access to the transactions endpoints
|
|
554
|
+
</summary>
|
|
555
|
+
|
|
556
|
+
- `getAllTransactionsForAddress()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Paginated)
|
|
557
|
+
- `getAllTransactionsForAddressByPage()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Nonpaginated)
|
|
558
|
+
- `getPaginatedTransactionsForAddress()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
|
|
559
|
+
- `getTransaction()`: Fetch and render a single transaction including its decoded log events. Additionally return semantically decoded information for DEX trades, lending and NFT sales.
|
|
560
|
+
- `getTransactionsForBlockByPage()`: Fetch all transactions including their decoded log events in a block by page number and further flag interesting wallets or transactions.
|
|
561
|
+
- `getTransactionsForBlock()`: Fetch all transactions including their decoded log events in a block by block hash and further flag interesting wallets or transactions.
|
|
562
|
+
- `getTransactionSummary()`: Fetch the earliest and latest transactions, and the transaction count for a wallet. Calculate the age of the wallet and the time it has been idle and quickly gain insights into their engagement with web3.
|
|
563
|
+
- `getTimeBucketTransactionsForAddress()`: Fetch all transactions including their decoded log events in a 15-minute time bucket interval.
|
|
564
|
+
- `getEarliestTransactionsForAddress()`: Fetch and render the earliest transactions involving an address. Frequently seen in wallet applications.
|
|
565
|
+
</details>
|
|
566
|
+
|
|
567
|
+
<details>
|
|
568
|
+
<summary>
|
|
569
|
+
9. <strong>Streaming Service</strong>: Real-time blockchain data streaming via WebSocket connections
|
|
570
|
+
</summary>
|
|
571
|
+
|
|
572
|
+
- `getClient()`: Get the underlying GraphQL WebSocket client for direct access.
|
|
573
|
+
- `isConnected`: Check the connection status of the streaming service.
|
|
574
|
+
- `subscribeToOHLCVPairs()`: Subscribe to real-time OHLCV (Open, High, Low, Close, Volume) data for specific trading pairs. Supports multiple chains and configurable intervals and timeframes.
|
|
575
|
+
- `subscribeToOHLCVTokens()`: Subscribe to real-time OHLCV (Open, High, Low, Close, Volume) data for specific tokens. Tracks token prices across their primary DEX pools with configurable intervals and timeframes.
|
|
576
|
+
- `subscribeToTokenBalances()`: Subscribe to real-time token balance updates for a specific wallet address. Tracks balance changes across native and ERC-20 tokens with USD valuations.
|
|
577
|
+
- `subscribeToWalletActivity()`: Subscribe to real-time wallet activity including transactions, token transfers, and smart contract interactions. Provides decoded transaction details for swaps, transfers, bridges, deposits, withdrawals, and approvals.
|
|
578
|
+
- `subscribeToNewPairs()`: Subscribe to real-time notifications when new liquidity pairs are created on supported decentralized exchanges (DEXes). Supports Uniswap V2/V3 across Base, Ethereum, and BSC networks.
|
|
579
|
+
- `subscribeToUpdatePairs()`: Subscribe to real-time updates for specific trading pairs including price, volume, liquidity data, price deltas, and swap counts.
|
|
580
|
+
- `rawQuery()`: Execute custom GraphQL subscription queries for advanced streaming scenarios and future extensibility.
|
|
581
|
+
- `disconnect()`: Properly disconnect from the streaming service.
|
|
582
|
+
|
|
583
|
+
</details>
|
|
584
|
+
|
|
585
|
+
## Contributing
|
|
586
|
+
|
|
587
|
+
Contributions, issues and feature requests are welcome!
|
|
588
|
+
Feel free to check [issues](https://github.com/covalenthq/covalent-api-sdk-ts/issues) page.
|
|
589
|
+
|
|
590
|
+
## Show your support
|
|
591
|
+
|
|
592
|
+
Give a ⭐️ if this project helped you!
|
|
593
|
+
|
|
594
|
+
## License
|
|
595
|
+
|
|
596
|
+
This project is [Apache-2.0](./LICENSE) licensed.
|