@covalenthq/client-sdk 2.1.2 → 2.2.0
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 +22 -6
- package/dist/cjs/index.js +90 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/src/GoldRushClient.d.ts +3 -1
- package/dist/cjs/src/services/AllChainsService.d.ts +26 -0
- package/dist/cjs/src/utils/functions/endpointGenerator.d.ts +1 -1
- package/dist/cjs/src/utils/functions/timestamp-parser.d.ts +1 -1
- package/dist/cjs/src/utils/types/AllChainService.types.d.ts +32 -0
- package/dist/cjs/src/utils/types/BaseService.types.d.ts +2 -0
- package/dist/cjs/src/utils/types/Generic.types.d.ts +8 -0
- package/dist/cjs/src/utils/types/PricingService.types.d.ts +3 -2
- package/dist/cjs/src/utils/types/TransactionService.types.d.ts +1 -0
- package/dist/esm/index.js +90 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/src/GoldRushClient.d.ts +3 -1
- package/dist/esm/src/services/AllChainsService.d.ts +26 -0
- package/dist/esm/src/utils/functions/endpointGenerator.d.ts +1 -1
- package/dist/esm/src/utils/functions/timestamp-parser.d.ts +1 -1
- package/dist/esm/src/utils/types/AllChainService.types.d.ts +32 -0
- package/dist/esm/src/utils/types/BaseService.types.d.ts +2 -0
- package/dist/esm/src/utils/types/Generic.types.d.ts +8 -0
- package/dist/esm/src/utils/types/PricingService.types.d.ts +3 -2
- package/dist/esm/src/utils/types/TransactionService.types.d.ts +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -208,6 +208,14 @@ if (resp.data !== null) {
|
|
|
208
208
|
|
|
209
209
|
You can explore more examples [here](./test/unit/is-valid-api-key.test.ts)
|
|
210
210
|
|
|
211
|
+
5. **timestampParser**: Convert ISO timestamps to various human-readable formats
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
timestampParser("2024-10-16T12:39:23.000Z", "descriptive"); // "October 16 2024 at 18:09:23"
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
You can explore more examples [here](./test/unit/timestamp-parser.test.ts)
|
|
218
|
+
|
|
211
219
|
### 8. Standardized (Error) Responses
|
|
212
220
|
|
|
213
221
|
All the responses are of the same standardized format
|
|
@@ -227,7 +235,15 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
|
|
|
227
235
|
|
|
228
236
|
<details>
|
|
229
237
|
<summary>
|
|
230
|
-
|
|
238
|
+
1. <strong>All Chains Service</strong>: Access to the data across multiple chains and addresses.
|
|
239
|
+
</summary>
|
|
240
|
+
|
|
241
|
+
- `getMultiChainAndMultiAddressTransactions()`: Fetch and render the transactions across multiple chains and addresses
|
|
242
|
+
</details>
|
|
243
|
+
|
|
244
|
+
<details>
|
|
245
|
+
<summary>
|
|
246
|
+
2. <strong>Security Service</strong>: Access to the token approvals API endpoints
|
|
231
247
|
</summary>
|
|
232
248
|
|
|
233
249
|
- `getApprovals()`: Get a list of approvals across all ERC20 token contracts categorized by spenders for a wallet’s assets.
|
|
@@ -236,7 +252,7 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
|
|
|
236
252
|
|
|
237
253
|
<details>
|
|
238
254
|
<summary>
|
|
239
|
-
|
|
255
|
+
3. <strong>Balance Service</strong>: Access to the balances endpoints
|
|
240
256
|
</summary>
|
|
241
257
|
|
|
242
258
|
- `getTokenBalancesForWalletAddress()`: Fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
|
|
@@ -251,7 +267,7 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
|
|
|
251
267
|
|
|
252
268
|
<details>
|
|
253
269
|
<summary>
|
|
254
|
-
|
|
270
|
+
4. <strong>Base Service</strong>: Access to the address activity, log events, chain status, and block retrieval endpoints
|
|
255
271
|
</summary>
|
|
256
272
|
|
|
257
273
|
- `getBlock()`: Fetch and render a single block for a block explorer.
|
|
@@ -271,7 +287,7 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
|
|
|
271
287
|
|
|
272
288
|
<details>
|
|
273
289
|
<summary>
|
|
274
|
-
|
|
290
|
+
5. <strong>NFT Service</strong>: Access to the NFT endpoints
|
|
275
291
|
</summary>
|
|
276
292
|
|
|
277
293
|
- `getChainCollections()`: Used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files. (Paginated)
|
|
@@ -290,7 +306,7 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
|
|
|
290
306
|
|
|
291
307
|
<details>
|
|
292
308
|
<summary>
|
|
293
|
-
|
|
309
|
+
6. <strong>Pricing Service</strong>: Access to the historical token prices endpoint
|
|
294
310
|
</summary>
|
|
295
311
|
|
|
296
312
|
- `getTokenPrices()`: Get historic prices of a token between date ranges. Supports native tokens.
|
|
@@ -298,7 +314,7 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
|
|
|
298
314
|
|
|
299
315
|
<details>
|
|
300
316
|
<summary>
|
|
301
|
-
|
|
317
|
+
7. <strong>Transaction Service</strong>: Access to the transactions endpoints
|
|
302
318
|
</summary>
|
|
303
319
|
|
|
304
320
|
- `getAllTransactionsForAddress()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Paginated)
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var version = "2.
|
|
3
|
+
var version = "2.2.0";
|
|
4
4
|
|
|
5
5
|
const bigIntParser = (val) => {
|
|
6
6
|
if (val === null || val === undefined) {
|
|
@@ -27,6 +27,93 @@ const endpointGenerator = (extension = "", params = []) => {
|
|
|
27
27
|
return new URL(`${baseUrl}/${extension}?${urlParams}`);
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Cross Chain API
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
class AllChainsService {
|
|
35
|
+
constructor(execution) {
|
|
36
|
+
this.execution = execution;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* Commonly used to get transactions cross chains and addresses.
|
|
41
|
+
*
|
|
42
|
+
* @param {Chain[]} chains - An array of the chain names or IDs to retrieve transactions from. Defaults to all foundational chains.
|
|
43
|
+
* @param {string[]} addresses - An array of addresses for which transactions are fetched. Does not support name resolution.
|
|
44
|
+
* @param {number} limit - Number of transactions to return per page, up to the default max of 100 items.
|
|
45
|
+
* @param {string} before - Pagination cursor pointing to fetch transactions before a certain point.
|
|
46
|
+
* @param {string} after - Pagination cursor pointing to fetch transactions after a certain point.
|
|
47
|
+
* @param {boolean} withLogs - Whether to include raw logs in the response.
|
|
48
|
+
* @param {boolean} withDecodedLogs - Whether to include decoded logs in the response.
|
|
49
|
+
* @param {Quote | "BTC" | "ETH"} quoteCurrency - The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, `GBP`, "BTC" and "ETH".
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
async getMultiChainAndMultiAddressTransactions(queryParamOpts) {
|
|
53
|
+
const endpoint = endpointGenerator(`allchains/transactions`, [
|
|
54
|
+
{
|
|
55
|
+
key: "chains",
|
|
56
|
+
value: queryParamOpts?.chains,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
key: "addresses",
|
|
60
|
+
value: queryParamOpts?.addresses,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
key: "limit",
|
|
64
|
+
value: queryParamOpts?.limit,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
key: "before",
|
|
68
|
+
value: queryParamOpts?.before,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
key: "after",
|
|
72
|
+
value: queryParamOpts?.after,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
key: "with-logs",
|
|
76
|
+
value: queryParamOpts?.withLogs,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
key: "with-decoded-logs",
|
|
80
|
+
value: queryParamOpts?.withDecodedLogs,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
key: "quote-currency",
|
|
84
|
+
value: queryParamOpts?.quoteCurrency,
|
|
85
|
+
},
|
|
86
|
+
]);
|
|
87
|
+
const parseData = (data) => {
|
|
88
|
+
if (data.data) {
|
|
89
|
+
data.data.updated_at = data.data.updated_at
|
|
90
|
+
? new Date(data.data.updated_at)
|
|
91
|
+
: null;
|
|
92
|
+
data.data.items = data.data.items
|
|
93
|
+
? data.data.items.map((txItem) => ({
|
|
94
|
+
...txItem,
|
|
95
|
+
value: bigIntParser(txItem.value),
|
|
96
|
+
fees_paid: bigIntParser(txItem.fees_paid),
|
|
97
|
+
block_signed_at: txItem.block_signed_at
|
|
98
|
+
? new Date(txItem.block_signed_at)
|
|
99
|
+
: null,
|
|
100
|
+
log_events: txItem.log_events
|
|
101
|
+
? txItem.log_events.map((logItem) => ({
|
|
102
|
+
...logItem,
|
|
103
|
+
block_signed_at: logItem.block_signed_at
|
|
104
|
+
? new Date(logItem.block_signed_at)
|
|
105
|
+
: null,
|
|
106
|
+
}))
|
|
107
|
+
: null,
|
|
108
|
+
}))
|
|
109
|
+
: null;
|
|
110
|
+
}
|
|
111
|
+
return data;
|
|
112
|
+
};
|
|
113
|
+
return await this.execution.execute(endpoint, parseData);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
30
117
|
async function* paginateEndpoint(endpoint, execution, parseData, implementation) {
|
|
31
118
|
let _endpoint = new URL(endpoint);
|
|
32
119
|
let hasMore = true;
|
|
@@ -2518,6 +2605,7 @@ class GoldRushClient {
|
|
|
2518
2605
|
? `${settings.source} (${this.userAgent})`
|
|
2519
2606
|
: this.userAgent,
|
|
2520
2607
|
});
|
|
2608
|
+
this.AllChainsService = new AllChainsService(execution);
|
|
2521
2609
|
this.BalanceService = new BalanceService(execution);
|
|
2522
2610
|
this.BaseService = new BaseService(execution);
|
|
2523
2611
|
this.NftService = new NftService(execution);
|
|
@@ -3686,7 +3774,7 @@ const timestampParser = (timestamp, type) => {
|
|
|
3686
3774
|
return `just now`;
|
|
3687
3775
|
}
|
|
3688
3776
|
}
|
|
3689
|
-
case "YYYY
|
|
3777
|
+
case "YYYY-MM-DD": {
|
|
3690
3778
|
const offsetMinutes = _unix.getTimezoneOffset();
|
|
3691
3779
|
const offsetMilliseconds = offsetMinutes * 60 * 1000;
|
|
3692
3780
|
const utcTime = _unix.getTime() + offsetMilliseconds;
|