@covalenthq/client-sdk 2.2.2 → 2.2.3

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 CHANGED
@@ -1,353 +1,356 @@
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
- "demo.eth"
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`. 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
- ## Features
73
-
74
- ### 1. Name Resolution
75
-
76
- The GoldRush SDK natively resolves the underlying wallet address for the following
77
-
78
- 1. ENS Domains (e.g. `demo.eth`)
79
- 2. Lens Handles (e.g. `demo.lens`)
80
- 3. Unstoppable Domains (e.g. `demo.x`)
81
- 4. RNS Domains (e.g. `demo.ron`)
82
-
83
- ### 2. Query Parameters
84
-
85
- All the API call arguments have an option to pass `typed objects` as Query parameters.
86
-
87
- 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:
88
-
89
- ```ts
90
- const resp = await client.BalanceService.getTokenBalancesForWalletAddress(
91
- "eth-mainnet",
92
- "demo.eth",
93
- {
94
- quoteCurrency: "CAD",
95
- nft: true,
96
- }
97
- );
98
- ```
99
-
100
- ### 3. Exported Types
101
-
102
- All the `interface`s used, for arguments, query parameters and responses are also exported from the package which can be used for custom usage.
103
-
104
- For example, explicitly typecasting the response
105
-
106
- ```ts
107
- import {
108
- GoldRushClient,
109
- type BalancesResponse,
110
- type BalanceItem,
111
- } from "@covalenthq/client-sdk";
112
-
113
- const resp = await client.BalanceService.getTokenBalancesForWalletAddress(
114
- "eth-mainnet",
115
- "demo.eth",
116
- {
117
- quoteCurrency: "CAD",
118
- nft: true,
119
- }
120
- );
121
-
122
- const data: BalancesResponse = resp.data;
123
- const items: BalanceItem[] = resp.data.items;
124
- ```
125
-
126
- ### 4. Multiple Chain input formats
127
-
128
- The SDK supports the following formats for the chain input:
129
-
130
- 1. Chain Name (e.g. `eth-mainnet`)
131
- 2. Chain ID (e.g. `1`)
132
- 3. Chain Name Enum (e.g. `ChainName.ETH_MAINNET`)
133
- 4. Chain ID Enum (e.g. `ChainID.ETH_MAINNET`)
134
-
135
- ### 5. Additional Non-Paginated methods
136
-
137
- 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_.
138
-
139
- For example, the following fetches ALL transactions for `demo.eth` on Ethereum:
140
-
141
- ```ts
142
- import { GoldRushClient } from "@covalenthq/client-sdk";
143
-
144
- const ApiServices = async () => {
145
- const client = new GoldRushClient("<YOUR_API_KEY>");
146
- try {
147
- for await (const tx of client.TransactionService.getAllTransactionsForAddress(
148
- "eth-mainnet",
149
- "demo.eth"
150
- )) {
151
- console.log("tx", tx);
152
- }
153
- } catch (error) {
154
- console.log(error.message);
155
- }
156
- };
157
- ```
158
-
159
- ### 6. Executable pagination functions
160
-
161
- 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.
162
-
163
- ```ts
164
- import { GoldRushClient } from "@covalenthq/client-sdk";
165
-
166
- const client = new GoldRushClient("<YOUR_API_KEY>");
167
- const resp = await client.TransactionService.getAllTransactionsForAddressByPage(
168
- "eth-mainnet",
169
- "demo.eth"
170
- ); // assuming resp.data.current_page is 10
171
- if (resp.data !== null) {
172
- const prevPage = await resp.data.prev(); // will retrieve page 9
173
- console.log(prevPage.data);
174
- }
175
- ```
176
-
177
- ### 7. Utility Functions
178
-
179
- 1. **bigIntParser**: Formats input as a `bigint` value. For example
180
-
181
- ```ts
182
- bigIntParser("-123"); // -123n
183
- ```
184
-
185
- You can explore more examples [here](./test/unit/bigint-parser.test.ts)
186
-
187
- 2. **calculatePrettyBalance**: Formats large and raw numbers and bigints to human friendly format. For example
188
-
189
- ```ts
190
- calculatePrettyBalance(1.5, 3, true, 4); // "0.0015"
191
- ```
192
-
193
- You can explore more examples [here](./test/unit/calculate-pretty-balance.test.ts)
194
-
195
- 3. **isValidApiKey**: Checks for the input as a valid GoldRush API Key. For example
196
-
197
- ```ts
198
- isValidApiKey(cqt_wF123); // false
199
- ```
200
-
201
- You can explore more examples [here](./test/unit/is-valid-api-key.test.ts)
202
-
203
- 4. **prettifyCurrency**: Formats large and raw numbers and bigints to human friendly currency format. For example
204
-
205
- ```ts
206
- prettifyCurrency(89.0, 2, "CAD"); // "CA$89.00"
207
- ```
208
-
209
- You can explore more examples [here](./test/unit/is-valid-api-key.test.ts)
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
-
219
- ### 8. Standardized (Error) Responses
220
-
221
- All the responses are of the same standardized format
222
-
223
- ```ts
224
-
225
- "data": <object>,
226
- "error": <boolean>,
227
- "error_message": <string>,
228
- "error_code": <number>
229
-
230
- ```
231
-
232
- ## Supported Endpoints
233
-
234
- The Covalent SDK provides comprehensive support for all Class A, Class B, and Pricing endpoints that are grouped under the following _Service_ namespaces:
235
-
236
- <details>
237
- <summary>
238
- 1. <strong>All Chains Service</strong>: Access to the data across multiple chains and addresses.
239
- </summary>
240
-
241
- - `getAddressActivity()`: Locate chains where an address is active on with a single API call.
242
- - `getMultiChainMultiAddressTransactions()`: Fetch and render the transactions across multiple chains and addresses
243
- - `getMultiChainBalances()`: Fetch the token balances of an address for multiple chains. (limited to 10 chains at a time)
244
- </details>
245
-
246
- <details>
247
- <summary>
248
- 2. <strong>Security Service</strong>: Access to the token approvals API endpoints
249
- </summary>
250
-
251
- - `getApprovals()`: Get a list of approvals across all ERC20 token contracts categorized by spenders for a wallet’s assets.
252
- - `getNftApprovals()`: Get a list of approvals across all NFT contracts categorized by spenders for a wallet’s assets.
253
- </details>
254
-
255
- <details>
256
- <summary>
257
- 3. <strong>Balance Service</strong>: Access to the balances endpoints
258
- </summary>
259
-
260
- - `getTokenBalancesForWalletAddress()`: Fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
261
- - `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.
262
- - `getHistoricalPortfolioForWalletAddress()`: Render a daily portfolio balance for an address broken down by the token. The timeframe is user-configurable, defaults to 30 days.
263
- - `getErc20TransfersForWalletAddress()`: Render the transfer-in and transfer-out of a token along with historical prices from an address. (Paginated)
264
- - `getErc20TransfersForWalletAddressByPage()`: Render the transfer-in and transfer-out of a token along with historical prices from an address. (NonPaginated)
265
- - `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)
266
- - `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)
267
- - `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.
268
- </details>
269
-
270
- <details>
271
- <summary>
272
- 4. <strong>Base Service</strong>: Access to the address activity, log events, chain status, and block retrieval endpoints
273
- </summary>
274
-
275
- - `getBlock()`: Fetch and render a single block for a block explorer.
276
- - `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.
277
- - `getResolvedAddress()`: Used to resolve ENS, RNS and Unstoppable Domains addresses.
278
- - `getBlockHeights()`: Get all the block heights within a particular date range. Useful for rendering a display where you sort blocks by day. (Paginated)
279
- - `getBlockHeightsByPage()`: Get all the block heights within a particular date range. Useful for rendering a display where you sort blocks by day. (Nonpaginated)
280
- - `getLogEventsByAddress()`: Get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions. (Paginated)
281
- - `getLogEventsByAddressByPage()`: Get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions. (Nonpaginated)
282
- - `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)
283
- - `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)
284
- - `getAllChains()`: Used to build internal dashboards for all supported chains on Covalent.
285
- - `getAllChainStatus()`: Used to build internal status dashboards of all supported chains.
286
- - `getGasPrices()`: Get real-time gas estimates for different transaction speeds on a specific network, enabling users to optimize transaction costs and confirmation times.
287
- </details>
288
-
289
- <details>
290
- <summary>
291
- 5. <strong>Bitcoin Service</strong>: Access to the Bitcoin wallet endpoints
292
- </summary>
293
-
294
- - `getBitcoinHdWalletBalances()`: Fetch balances for each active child address derived from a Bitcoin HD wallet.
295
- - `getTokenBalancesForWalletAddress()`: Fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
296
- - `getTransactionsForBtcAddress()`: Used to fetch the full transaction history of a Bitcoin wallet. Only supports non-HD bitcoin addresses.
297
- </details>
298
-
299
- <details>
300
- <summary>
301
- 6. <strong>NFT Service</strong>: Access to the NFT endpoints
302
- </summary>
303
-
304
- - `getChainCollections()`: Used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files. (Paginated)
305
- - `getChainCollectionsByPage()`: Used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files. (Nonpaginated)
306
- - `getNftsForAddress()`: Used to render the NFTs (including ERC721 and ERC1155) held by an address.
307
- - `getTokenIdsForContractWithMetadata()`: Get NFT token IDs with metadata from a collection. Useful for building NFT card displays. (Paginated)
308
- - `getTokenIdsForContractWithMetadataByPage()`: Get NFT token IDs with metadata from a collection. Useful for building NFT card displays. (Nonpaginated)
309
- - `getNftMetadataForGivenTokenIDForContract()`: Get a single NFT metadata by token ID from a collection. Useful for building NFT card displays.
310
- - `getNftTransactionsForContractTokenId()`: Get all transactions of an NFT token. Useful for building a transaction history table or price chart.
311
- - `getTraitsForCollection()`: Used to fetch and render the traits of a collection as seen in rarity calculators.
312
- - `getAttributesForTraitInCollection()`: Used to get the count of unique values for traits within an NFT collection.
313
- - `getCollectionTraitsSummary()`: Used to calculate rarity scores for a collection based on its traits.
314
- - `checkOwnershipInNft()`: Used to verify ownership of NFTs (including ERC-721 and ERC-1155) within a collection.
315
- - `checkOwnershipInNftForSpecificTokenId()`: Used to verify ownership of a specific token (ERC-721 or ERC-1155) within a collection.
316
- </details>
317
-
318
- <details>
319
- <summary>
320
- 7. <strong>Pricing Service</strong>: Access to the historical token prices endpoint
321
- </summary>
322
-
323
- - `getTokenPrices()`: Get historic prices of a token between date ranges. Supports native tokens.
324
- </details>
325
-
326
- <details>
327
- <summary>
328
- 8. <strong>Transaction Service</strong>: Access to the transactions endpoints
329
- </summary>
330
-
331
- - `getAllTransactionsForAddress()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Paginated)
332
- - `getAllTransactionsForAddressByPage()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Nonpaginated)
333
- - `getTransactionsForAddressV3()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
334
- - `getTransaction()`: Fetch and render a single transaction including its decoded log events. Additionally return semantically decoded information for DEX trades, lending and NFT sales.
335
- - `getTransactionsForBlock()`: Fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
336
- - `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.
337
- - `getTimeBucketTransactionsForAddress()`: Fetch all transactions including their decoded log events in a 15-minute time bucket interval.
338
- - `getTransactionsForBlockHashByPage()`: Fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
339
- - `getTransactionsForBlockHash()`: Fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
340
- </details>
341
-
342
- ## Contributing
343
-
344
- Contributions, issues and feature requests are welcome!
345
- Feel free to check [issues](https://github.com/covalenthq/covalent-api-sdk-ts/issues) page.
346
-
347
- ## Show your support
348
-
349
- Give a ⭐️ if this project helped you!
350
-
351
- ## License
352
-
353
- 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
+ "demo.eth"
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`. 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
+ ## Features
73
+
74
+ ### 1. Name Resolution
75
+
76
+ The GoldRush SDK natively resolves the underlying wallet address for the following
77
+
78
+ 1. ENS Domains (e.g. `demo.eth`)
79
+ 2. Lens Handles (e.g. `demo.lens`)
80
+ 3. Unstoppable Domains (e.g. `demo.x`)
81
+ 4. RNS Domains (e.g. `demo.ron`)
82
+
83
+ ### 2. Query Parameters
84
+
85
+ All the API call arguments have an option to pass `typed objects` as Query parameters.
86
+
87
+ 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:
88
+
89
+ ```ts
90
+ const resp = await client.BalanceService.getTokenBalancesForWalletAddress(
91
+ "eth-mainnet",
92
+ "demo.eth",
93
+ {
94
+ quoteCurrency: "CAD",
95
+ nft: true,
96
+ }
97
+ );
98
+ ```
99
+
100
+ ### 3. Exported Types
101
+
102
+ All the `interface`s used, for arguments, query parameters and responses are also exported from the package which can be used for custom usage.
103
+
104
+ For example, explicitly typecasting the response
105
+
106
+ ```ts
107
+ import {
108
+ GoldRushClient,
109
+ type BalancesResponse,
110
+ type BalanceItem,
111
+ } from "@covalenthq/client-sdk";
112
+
113
+ const resp = await client.BalanceService.getTokenBalancesForWalletAddress(
114
+ "eth-mainnet",
115
+ "demo.eth",
116
+ {
117
+ quoteCurrency: "CAD",
118
+ nft: true,
119
+ }
120
+ );
121
+
122
+ const data: BalancesResponse = resp.data;
123
+ const items: BalanceItem[] = resp.data.items;
124
+ ```
125
+
126
+ ### 4. Multiple Chain input formats
127
+
128
+ The SDK supports the following formats for the chain input:
129
+
130
+ 1. Chain Name (e.g. `eth-mainnet`)
131
+ 2. Chain ID (e.g. `1`)
132
+ 3. Chain Name Enum (e.g. `ChainName.ETH_MAINNET`)
133
+ 4. Chain ID Enum (e.g. `ChainID.ETH_MAINNET`)
134
+
135
+ ### 5. Additional Non-Paginated methods
136
+
137
+ 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_.
138
+
139
+ For example, the following fetches ALL transactions for `demo.eth` on Ethereum:
140
+
141
+ ```ts
142
+ import { GoldRushClient } from "@covalenthq/client-sdk";
143
+
144
+ const ApiServices = async () => {
145
+ const client = new GoldRushClient("<YOUR_API_KEY>");
146
+ try {
147
+ for await (const tx of client.TransactionService.getAllTransactionsForAddress(
148
+ "eth-mainnet",
149
+ "demo.eth"
150
+ )) {
151
+ console.log("tx", tx);
152
+ }
153
+ } catch (error) {
154
+ console.log(error.message);
155
+ }
156
+ };
157
+ ```
158
+
159
+ ### 6. Executable pagination functions
160
+
161
+ 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.
162
+
163
+ ```ts
164
+ import { GoldRushClient } from "@covalenthq/client-sdk";
165
+
166
+ const client = new GoldRushClient("<YOUR_API_KEY>");
167
+ const resp = await client.TransactionService.getAllTransactionsForAddressByPage(
168
+ "eth-mainnet",
169
+ "demo.eth"
170
+ ); // assuming resp.data.current_page is 10
171
+ if (resp.data !== null) {
172
+ const prevPage = await resp.data.prev(); // will retrieve page 9
173
+ console.log(prevPage.data);
174
+ }
175
+ ```
176
+
177
+ ### 7. Utility Functions
178
+
179
+ 1. **bigIntParser**: Formats input as a `bigint` value. For example
180
+
181
+ ```ts
182
+ bigIntParser("-123"); // -123n
183
+ ```
184
+
185
+ You can explore more examples [here](./test/unit/bigint-parser.test.ts)
186
+
187
+ 2. **calculatePrettyBalance**: Formats large and raw numbers and bigints to human friendly format. For example
188
+
189
+ ```ts
190
+ calculatePrettyBalance(1.5, 3, true, 4); // "0.0015"
191
+ ```
192
+
193
+ You can explore more examples [here](./test/unit/calculate-pretty-balance.test.ts)
194
+
195
+ 3. **isValidApiKey**: Checks for the input as a valid GoldRush API Key. For example
196
+
197
+ ```ts
198
+ isValidApiKey(cqt_wF123); // false
199
+ ```
200
+
201
+ You can explore more examples [here](./test/unit/is-valid-api-key.test.ts)
202
+
203
+ 4. **prettifyCurrency**: Formats large and raw numbers and bigints to human friendly currency format. For example
204
+
205
+ ```ts
206
+ prettifyCurrency(89.0, 2, "CAD"); // "CA$89.00"
207
+ ```
208
+
209
+ You can explore more examples [here](./test/unit/is-valid-api-key.test.ts)
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
+
219
+ ### 8. Standardized (Error) Responses
220
+
221
+ All the responses are of the same standardized format
222
+
223
+ ```ts
224
+
225
+ "data": <object>,
226
+ "error": <boolean>,
227
+ "error_message": <string>,
228
+ "error_code": <number>
229
+
230
+ ```
231
+
232
+ ## Supported Endpoints
233
+
234
+ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pricing endpoints that are grouped under the following _Service_ namespaces:
235
+
236
+ <details>
237
+ <summary>
238
+ 1. <strong>All Chains Service</strong>: Access to the data across multiple chains and addresses.
239
+ </summary>
240
+
241
+ - `getAddressActivity()`: Locate chains where an address is active on with a single API call.
242
+ - `getMultiChainMultiAddressTransactions()`: Fetch and render the transactions across multiple chains and addresses
243
+ - `getMultiChainBalances()`: Fetch the token balances of an address for multiple chains. (limited to 10 chains at a time)
244
+ </details>
245
+
246
+ <details>
247
+ <summary>
248
+ 2. <strong>Security Service</strong>: Access to the token approvals API endpoints
249
+ </summary>
250
+
251
+ - `getApprovals()`: Get a list of approvals across all ERC20 token contracts categorized by spenders for a wallet’s assets.
252
+ - `getNftApprovals()`: Get a list of approvals across all NFT contracts categorized by spenders for a wallet’s assets.
253
+ </details>
254
+
255
+ <details>
256
+ <summary>
257
+ 3. <strong>Balance Service</strong>: Access to the balances endpoints
258
+ </summary>
259
+
260
+ - `getTokenBalancesForWalletAddress()`: Fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
261
+ - `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.
262
+ - `getHistoricalPortfolioForWalletAddress()`: Render a daily portfolio balance for an address broken down by the token. The timeframe is user-configurable, defaults to 30 days.
263
+ - `getErc20TransfersForWalletAddress()`: Render the transfer-in and transfer-out of a token along with historical prices from an address. (Paginated)
264
+ - `getErc20TransfersForWalletAddressByPage()`: Render the transfer-in and transfer-out of a token along with historical prices from an address. (NonPaginated)
265
+ - `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)
266
+ - `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)
267
+ - `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.
268
+ </details>
269
+
270
+ <details>
271
+ <summary>
272
+ 4. <strong>Base Service</strong>: Access to the address activity, log events, chain status, and block retrieval endpoints
273
+ </summary>
274
+
275
+ - `getBlock()`: Fetch and render a single block for a block explorer.
276
+ - `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.
277
+ - `getResolvedAddress()`: Used to resolve ENS, RNS and Unstoppable Domains addresses.
278
+ - `getBlockHeights()`: Get all the block heights within a particular date range. Useful for rendering a display where you sort blocks by day. (Paginated)
279
+ - `getBlockHeightsByPage()`: Get all the block heights within a particular date range. Useful for rendering a display where you sort blocks by day. (Nonpaginated)
280
+ - `getLogEventsByAddress()`: Get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions. (Paginated)
281
+ - `getLogEventsByAddressByPage()`: Get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions. (Nonpaginated)
282
+ - `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)
283
+ - `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)
284
+ - `getAllChains()`: Used to build internal dashboards for all supported chains on Covalent.
285
+ - `getAllChainStatus()`: Used to build internal status dashboards of all supported chains.
286
+ - `getGasPrices()`: Get real-time gas estimates for different transaction speeds on a specific network, enabling users to optimize transaction costs and confirmation times.
287
+ </details>
288
+
289
+ <details>
290
+ <summary>
291
+ 5. <strong>Bitcoin Service</strong>: Access to the Bitcoin wallet endpoints
292
+ </summary>
293
+
294
+ - `getBitcoinHdWalletBalances()`: Fetch balances for each active child address derived from a Bitcoin HD wallet.
295
+ - `getTokenBalancesForWalletAddress()`: Fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
296
+ - `getTransactionsForBtcAddress()`: Used to fetch the full transaction history of a Bitcoin wallet. Only supports non-HD bitcoin addresses.
297
+ </details>
298
+
299
+ <details>
300
+ <summary>
301
+ 6. <strong>NFT Service</strong>: Access to the NFT endpoints
302
+ </summary>
303
+
304
+ - `getChainCollections()`: Used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files. (Paginated)
305
+ - `getChainCollectionsByPage()`: Used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files. (Nonpaginated)
306
+ - `getNftsForAddress()`: Used to render the NFTs (including ERC721 and ERC1155) held by an address.
307
+ - `getTokenIdsForContractWithMetadata()`: Get NFT token IDs with metadata from a collection. Useful for building NFT card displays. (Paginated)
308
+ - `getTokenIdsForContractWithMetadataByPage()`: Get NFT token IDs with metadata from a collection. Useful for building NFT card displays. (Nonpaginated)
309
+ - `getNftMetadataForGivenTokenIDForContract()`: Get a single NFT metadata by token ID from a collection. Useful for building NFT card displays.
310
+ - `getNftTransactionsForContractTokenId()`: Get all transactions of an NFT token. Useful for building a transaction history table or price chart.
311
+ - `getTraitsForCollection()`: Used to fetch and render the traits of a collection as seen in rarity calculators.
312
+ - `getAttributesForTraitInCollection()`: Used to get the count of unique values for traits within an NFT collection.
313
+ - `getCollectionTraitsSummary()`: Used to calculate rarity scores for a collection based on its traits.
314
+ - `getHistoricalFloorPricesForCollection()`: Commonly used to render a price floor chart for an NFT collection.
315
+ - `getHistoricalVolumeForCollection()`: Commonly used to build a time-series chart of the transaction volume of an NFT collection.
316
+ - `getHistoricalSalesCountForCollection()`: Commonly used to build a time-series chart of the sales count of an NFT collection.
317
+ - `checkOwnershipInNft()`: Used to verify ownership of NFTs (including ERC-721 and ERC-1155) within a collection.
318
+ - `checkOwnershipInNftForSpecificTokenId()`: Used to verify ownership of a specific token (ERC-721 or ERC-1155) within a collection.
319
+ </details>
320
+
321
+ <details>
322
+ <summary>
323
+ 7. <strong>Pricing Service</strong>: Access to the historical token prices endpoint
324
+ </summary>
325
+
326
+ - `getTokenPrices()`: Get historic prices of a token between date ranges. Supports native tokens.
327
+ </details>
328
+
329
+ <details>
330
+ <summary>
331
+ 8. <strong>Transaction Service</strong>: Access to the transactions endpoints
332
+ </summary>
333
+
334
+ - `getAllTransactionsForAddress()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Paginated)
335
+ - `getAllTransactionsForAddressByPage()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Nonpaginated)
336
+ - `getTransactionsForAddressV3()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
337
+ - `getTransaction()`: Fetch and render a single transaction including its decoded log events. Additionally return semantically decoded information for DEX trades, lending and NFT sales.
338
+ - `getTransactionsForBlock()`: Fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
339
+ - `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.
340
+ - `getTimeBucketTransactionsForAddress()`: Fetch all transactions including their decoded log events in a 15-minute time bucket interval.
341
+ - `getTransactionsForBlockHashByPage()`: Fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
342
+ - `getTransactionsForBlockHash()`: Fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
343
+ </details>
344
+
345
+ ## Contributing
346
+
347
+ Contributions, issues and feature requests are welcome!
348
+ Feel free to check [issues](https://github.com/covalenthq/covalent-api-sdk-ts/issues) page.
349
+
350
+ ## Show your support
351
+
352
+ Give a ⭐️ if this project helped you!
353
+
354
+ ## License
355
+
356
+ This project is [Apache-2.0](./LICENSE) licensed.