@covalenthq/client-sdk 1.0.2 → 2.0.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.
Files changed (147) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +223 -282
  3. package/package.json +25 -12
  4. package/dist/cjs/index.d.ts +0 -20
  5. package/dist/cjs/index.js +0 -8190
  6. package/dist/cjs/index.js.map +0 -1
  7. package/dist/cjs/services/BalanceService.d.ts +0 -638
  8. package/dist/cjs/services/BaseService.d.ts +0 -571
  9. package/dist/cjs/services/CovalentClient.d.ts +0 -57
  10. package/dist/cjs/services/NftService.d.ts +0 -686
  11. package/dist/cjs/services/PricingService.d.ts +0 -103
  12. package/dist/cjs/services/SecurityService.d.ts +0 -162
  13. package/dist/cjs/services/TransactionService.d.ts +0 -711
  14. package/dist/cjs/services/XykService.d.ts +0 -1018
  15. package/dist/cjs/util/ApiHelpers.d.ts +0 -6
  16. package/dist/cjs/util/ApiKeyValidator.d.ts +0 -8
  17. package/dist/cjs/util/CalculatePrettyBalance.d.ts +0 -1
  18. package/dist/cjs/util/Chains.d.ts +0 -223
  19. package/dist/cjs/util/backoff.d.ts +0 -12
  20. package/dist/cjs/util/prettifyCurrency.d.ts +0 -2
  21. package/dist/cjs/util/types/BalanceServiceTypes.d.ts +0 -378
  22. package/dist/cjs/util/types/BaseServiceTypes.d.ts +0 -276
  23. package/dist/cjs/util/types/GenericTypes.d.ts +0 -116
  24. package/dist/cjs/util/types/NftServiceTypes.d.ts +0 -303
  25. package/dist/cjs/util/types/PricingServiceTypes.d.ts +0 -33
  26. package/dist/cjs/util/types/SecurityServiceTypes.d.ts +0 -121
  27. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +0 -388
  28. package/dist/cjs/util/types/XykServiceTypes.d.ts +0 -687
  29. package/dist/es/index.d.ts +0 -20
  30. package/dist/es/index.js +0 -8176
  31. package/dist/es/index.js.map +0 -1
  32. package/dist/es/services/BalanceService.d.ts +0 -638
  33. package/dist/es/services/BaseService.d.ts +0 -571
  34. package/dist/es/services/CovalentClient.d.ts +0 -57
  35. package/dist/es/services/NftService.d.ts +0 -686
  36. package/dist/es/services/PricingService.d.ts +0 -103
  37. package/dist/es/services/SecurityService.d.ts +0 -162
  38. package/dist/es/services/TransactionService.d.ts +0 -711
  39. package/dist/es/services/XykService.d.ts +0 -1018
  40. package/dist/es/util/ApiHelpers.d.ts +0 -6
  41. package/dist/es/util/ApiKeyValidator.d.ts +0 -8
  42. package/dist/es/util/CalculatePrettyBalance.d.ts +0 -1
  43. package/dist/es/util/Chains.d.ts +0 -223
  44. package/dist/es/util/backoff.d.ts +0 -12
  45. package/dist/es/util/prettifyCurrency.d.ts +0 -2
  46. package/dist/es/util/types/BalanceServiceTypes.d.ts +0 -378
  47. package/dist/es/util/types/BaseServiceTypes.d.ts +0 -276
  48. package/dist/es/util/types/GenericTypes.d.ts +0 -116
  49. package/dist/es/util/types/NftServiceTypes.d.ts +0 -303
  50. package/dist/es/util/types/PricingServiceTypes.d.ts +0 -33
  51. package/dist/es/util/types/SecurityServiceTypes.d.ts +0 -121
  52. package/dist/es/util/types/TransactionServiceTypes.d.ts +0 -388
  53. package/dist/es/util/types/XykServiceTypes.d.ts +0 -687
  54. package/dist/esm/index.d.ts +0 -20
  55. package/dist/esm/index.js +0 -8176
  56. package/dist/esm/index.js.map +0 -1
  57. package/dist/esm/services/BalanceService.d.ts +0 -638
  58. package/dist/esm/services/BaseService.d.ts +0 -571
  59. package/dist/esm/services/CovalentClient.d.ts +0 -57
  60. package/dist/esm/services/NftService.d.ts +0 -686
  61. package/dist/esm/services/PricingService.d.ts +0 -103
  62. package/dist/esm/services/SecurityService.d.ts +0 -162
  63. package/dist/esm/services/TransactionService.d.ts +0 -711
  64. package/dist/esm/services/XykService.d.ts +0 -1018
  65. package/dist/esm/util/ApiHelpers.d.ts +0 -6
  66. package/dist/esm/util/ApiKeyValidator.d.ts +0 -8
  67. package/dist/esm/util/CalculatePrettyBalance.d.ts +0 -1
  68. package/dist/esm/util/Chains.d.ts +0 -223
  69. package/dist/esm/util/backoff.d.ts +0 -12
  70. package/dist/esm/util/prettifyCurrency.d.ts +0 -2
  71. package/dist/esm/util/types/BalanceServiceTypes.d.ts +0 -378
  72. package/dist/esm/util/types/BaseServiceTypes.d.ts +0 -276
  73. package/dist/esm/util/types/GenericTypes.d.ts +0 -116
  74. package/dist/esm/util/types/NftServiceTypes.d.ts +0 -303
  75. package/dist/esm/util/types/PricingServiceTypes.d.ts +0 -33
  76. package/dist/esm/util/types/SecurityServiceTypes.d.ts +0 -121
  77. package/dist/esm/util/types/TransactionServiceTypes.d.ts +0 -388
  78. package/dist/esm/util/types/XykServiceTypes.d.ts +0 -687
  79. package/dist/index.d.ts +0 -20
  80. package/dist/index.js +0 -21
  81. package/dist/index.js.map +0 -1
  82. package/dist/services/BalanceService.d.ts +0 -638
  83. package/dist/services/BalanceService.js +0 -959
  84. package/dist/services/BalanceService.js.map +0 -1
  85. package/dist/services/BaseService.d.ts +0 -571
  86. package/dist/services/BaseService.js +0 -1202
  87. package/dist/services/BaseService.js.map +0 -1
  88. package/dist/services/CovalentClient.d.ts +0 -57
  89. package/dist/services/CovalentClient.js +0 -49
  90. package/dist/services/CovalentClient.js.map +0 -1
  91. package/dist/services/NftService.d.ts +0 -686
  92. package/dist/services/NftService.js +0 -1490
  93. package/dist/services/NftService.js.map +0 -1
  94. package/dist/services/PricingService.d.ts +0 -103
  95. package/dist/services/PricingService.js +0 -155
  96. package/dist/services/PricingService.js.map +0 -1
  97. package/dist/services/SecurityService.d.ts +0 -162
  98. package/dist/services/SecurityService.js +0 -249
  99. package/dist/services/SecurityService.js.map +0 -1
  100. package/dist/services/TransactionService.d.ts +0 -711
  101. package/dist/services/TransactionService.js +0 -1687
  102. package/dist/services/TransactionService.js.map +0 -1
  103. package/dist/services/XykService.d.ts +0 -1018
  104. package/dist/services/XykService.js +0 -1827
  105. package/dist/services/XykService.js.map +0 -1
  106. package/dist/util/ApiHelpers.d.ts +0 -6
  107. package/dist/util/ApiHelpers.js +0 -87
  108. package/dist/util/ApiHelpers.js.map +0 -1
  109. package/dist/util/ApiKeyValidator.d.ts +0 -8
  110. package/dist/util/ApiKeyValidator.js +0 -13
  111. package/dist/util/ApiKeyValidator.js.map +0 -1
  112. package/dist/util/CalculatePrettyBalance.d.ts +0 -1
  113. package/dist/util/CalculatePrettyBalance.js +0 -32
  114. package/dist/util/CalculatePrettyBalance.js.map +0 -1
  115. package/dist/util/Chains.d.ts +0 -223
  116. package/dist/util/Chains.js +0 -225
  117. package/dist/util/Chains.js.map +0 -1
  118. package/dist/util/backoff.d.ts +0 -12
  119. package/dist/util/backoff.js +0 -47
  120. package/dist/util/backoff.js.map +0 -1
  121. package/dist/util/prettifyCurrency.d.ts +0 -2
  122. package/dist/util/prettifyCurrency.js +0 -69
  123. package/dist/util/prettifyCurrency.js.map +0 -1
  124. package/dist/util/types/BalanceServiceTypes.d.ts +0 -378
  125. package/dist/util/types/BalanceServiceTypes.js +0 -2
  126. package/dist/util/types/BalanceServiceTypes.js.map +0 -1
  127. package/dist/util/types/BaseServiceTypes.d.ts +0 -276
  128. package/dist/util/types/BaseServiceTypes.js +0 -2
  129. package/dist/util/types/BaseServiceTypes.js.map +0 -1
  130. package/dist/util/types/GenericTypes.d.ts +0 -116
  131. package/dist/util/types/GenericTypes.js +0 -2
  132. package/dist/util/types/GenericTypes.js.map +0 -1
  133. package/dist/util/types/NftServiceTypes.d.ts +0 -303
  134. package/dist/util/types/NftServiceTypes.js +0 -2
  135. package/dist/util/types/NftServiceTypes.js.map +0 -1
  136. package/dist/util/types/PricingServiceTypes.d.ts +0 -33
  137. package/dist/util/types/PricingServiceTypes.js +0 -2
  138. package/dist/util/types/PricingServiceTypes.js.map +0 -1
  139. package/dist/util/types/SecurityServiceTypes.d.ts +0 -121
  140. package/dist/util/types/SecurityServiceTypes.js +0 -2
  141. package/dist/util/types/SecurityServiceTypes.js.map +0 -1
  142. package/dist/util/types/TransactionServiceTypes.d.ts +0 -388
  143. package/dist/util/types/TransactionServiceTypes.js +0 -2
  144. package/dist/util/types/TransactionServiceTypes.js.map +0 -1
  145. package/dist/util/types/XykServiceTypes.d.ts +0 -687
  146. package/dist/util/types/XykServiceTypes.js +0 -2
  147. package/dist/util/types/XykServiceTypes.js.map +0 -1
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
+ <div align="center">
2
+ <a href="https://goldrush.dev/products/goldrush/" target="_blank" rel="noopener noreferrer">
3
+ <img alt="GoldRush Kit Logo" src="./assets/ts-sdk-banner.png" style="max-width: 100%;"/>
4
+ </a>
5
+ </div>
6
+
7
+ <br/>
8
+
1
9
  <p align="center">
2
10
  <a href="https://www.npmjs.com/package/@covalenthq/client-sdk">
3
11
  <img src="https://img.shields.io/npm/v/@covalenthq/client-sdk" alt="NPM">
@@ -5,128 +13,231 @@
5
13
  <a href="https://www.npmjs.com/package/@covalenthq/client-sdk">
6
14
  <img src="https://img.shields.io/npm/dm/@covalenthq/client-sdk" alt="npm downloads">
7
15
  </a>
8
- <a>
9
- <img src="https://img.shields.io/badge/node-20.x-green">
10
- <a>
16
+ <img src="https://img.shields.io/github/license/covalenthq/client-sdk" alt="Apache-2.0">
11
17
  </p>
12
18
 
19
+ # GoldRush SDK for TypeScript
13
20
 
14
- # Covalent SDK for TypeScript
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.
15
22
 
16
- The Covalent SDK is the fastest way to integrate the Covalent Unified API for working with blockchain data. The SDK works with all [supported chains](https://www.covalenthq.com/docs/networks/) including Mainnets and Testnets.
23
+ > Use with [`NodeJS v18`](https://nodejs.org/en) or above for best results.
17
24
 
18
- **Note - Require `Node v18` and above for best results.**
25
+ > The GoldRush API is required. You can register for a free key on [GoldRush's website](https://goldrush.dev/platform/apikey)
19
26
 
20
- > **Sign up for an API Key**
21
- >
22
- > To get your own Covalent API key, **[sign up here](https://www.covalenthq.com/platform/auth/register/)** and create your key from the *API Keys* tab.
27
+ ## Using the SDK
23
28
 
24
- ## Getting started
29
+ > You can also follow the [video tutorial](https://www.youtube.com/watch?v=XSpPJP2w62E&ab_channel=Covalent)
25
30
 
26
- ```
27
- npm install @covalenthq/client-sdk
28
- ```
29
- or
30
- ```
31
- yarn add @covalenthq/client-sdk
32
- ```
31
+ 1. Install the dependencies
33
32
 
34
- ## How to use the Covalent SDK
33
+ ```bash
34
+ npm install @covalenthq/client-sdk
35
+ ```
35
36
 
36
- **Video Tutorial**: https://www.youtube.com/watch?v=XSpPJP2w62E&ab_channel=Covalent
37
+ 2. Create a client using the `GoldRushClient`
37
38
 
38
- After installing, you can import and use the SDK with:
39
+ ```ts
40
+ import { GoldRushClient, Chains } from "@covalenthq/client-sdk";
39
41
 
40
- ```ts
41
- import { CovalentClient, Chains } from "@covalenthq/client-sdk";
42
+ const client = new GoldRushClient("<YOUR_API_KEY>");
42
43
 
43
- const ApiServices = async () => {
44
- const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
44
+ const ApiServices = async () => {
45
+ try {
46
+ const balanceResp =
47
+ await client.BalanceService.getTokenBalancesForWalletAddress(
48
+ "eth-mainnet",
49
+ "demo.eth"
50
+ );
45
51
 
46
- const balanceResp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
47
- if (!balanceResp.error) {
48
- console.log(balanceResp.data);
49
- } else {
50
- console.log(balanceResp.error_message);
51
- }
52
- }
53
- ```
54
- > **Name Resolution**
55
- >
56
- > The Covalent SDK natively supports ENS domains (e.g. `demo.eth`), Lens Handles (e.g. `@demo.lens`) and Unstoppable Domains (e.g. `demo.x`) which automatically resolve to the underlying user address (e.g. `0xfC43f5F9dd45258b3AFf31Bdbe6561D97e8B71de`)
57
-
58
- **ℹ️ BREAKING CHANGE**
59
- > If you have been importing with `Client`:
60
- ```ts
61
- import { Client } from "@covalenthq/client-sdk";
62
- ```
63
- >
64
- > Please change to `CovalentClient`:
65
- ```ts
66
- import { CovalentClient } from "@covalenthq/client-sdk";
67
- ```
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
68
64
 
69
- ### How to apply supported query parameters to endpoints
70
- Query parameters are handled using `typed objects`. To pass in query parameters, developers can define an object that follows the type listed in the provided `tsdocs` under `src/util/types/`. Additionally, developers can reference the `tsdocs` for autocomplete suggestions for the supported parameters. These supported parameters can be passed in any order.
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.
71
86
 
72
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
+
73
89
  ```ts
74
- const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS", {quoteCurrency: "CAD", nft: true});
90
+ const resp = await client.BalanceService.getTokenBalancesForWalletAddress(
91
+ "eth-mainnet",
92
+ "demo.eth",
93
+ {
94
+ quoteCurrency: "CAD",
95
+ nft: true,
96
+ }
97
+ );
75
98
  ```
76
- ### Assign Types
77
- You can import types for each endpoint, found here `src/util/types/`. Here is an example:
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
+
78
106
  ```ts
79
- import { CovalentClient, BalancesResponse, BalanceItem } from "@covalenthq/client-sdk";
80
- const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS", {quoteCurrency: "CAD", nft: true});
81
- const data: BalancesResponse = resp.data; // `resp.data` in this case is of type `BalancesResponse`
82
- const items: BalanceItem[] = resp.data.items; // `resp.data.items` is of type `BalanceItem[]`
107
+ import {
108
+ GoldRushClient,
109
+ BalancesResponse,
110
+ 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;
83
124
  ```
84
125
 
85
- ### Different ways to input chains in chain fields
86
- We offer users three options for specifying a chain in the designated field:
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`)
87
134
 
88
- 1. String literal - directly inputting the chain name, such as `eth-mainnet`, with auto-completion functionality as the user types.
89
- 2. Chain Enum - utilizing the Chain enum `Chains.ETH_MAINNET`, which provides auto-suggestions as the user types in the chain field.
90
- 3. Chain Id - entering the ChainId as a numerical value.
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:
91
140
 
92
- Example with string literal
93
141
  ```ts
94
- // Example call with string literal ("eth-mainnet")
95
- const respWithStringLiteral = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
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
+ };
96
157
  ```
97
- Example with Chain Enum
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
+
98
163
  ```ts
99
- // Example call with enum (Chains.ETH_MAINNET)
100
- const respWithEnum = await client.BalanceService.getTokenBalancesForWalletAddress(Chains.ETH_MAINNET, "WALLET_ADDRESS");
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
+ }
101
175
  ```
102
- Example with Chain Id
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
+ ### 8. Standardized (Error) Responses
212
+
213
+ All the responses are of the same standardized format
214
+
103
215
  ```ts
104
- // Example call with chain Id (1)
105
- const respWithChainId = await client.BalanceService.getTokenBalancesForWalletAddress(1, "WALLET_ADDRESS");
216
+
217
+ "data": <object>,
218
+ "error": <boolean>,
219
+ "error_message": <string>,
220
+ "error_code": <number>
221
+
106
222
  ```
107
223
 
108
224
  ## Supported Endpoints
109
225
 
110
- The Covalent SDK provides comprehensive support for all Class A, Class B, and Pricing endpoints that are grouped under the following *Service* namespaces:
226
+ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pricing endpoints that are grouped under the following _Service_ namespaces:
111
227
 
112
- - [`SecurityService`](#securityservice): Access to the token approvals endpoints
113
- - [`BalanceService`](#balanceservice): Access to the balances endpoints
114
- - [`BaseService`](#baseservice): Access to the address activity, log events, chain status, and block retrieval endpoints
115
- - [`NftService`](#nftservice): Access to the NFT endpoints
116
- - [`PricingService`](#pricingservice): Access to the historical token prices endpoint
117
- - [`TransactionService`](#transactionservice): Access to the transactions endpoints
118
- - [`XykService`](#xykservice): Access to the XY=K suite of endpoints
119
-
120
- ### SecurityService
121
-
122
- The `SecurityService` class refers to the [token approvals API endpoints](https://www.covalenthq.com/docs/api/security/get-token-approvals-for-address/):
228
+ <details>
229
+ <summary>
230
+ 1. <strong>Security Service</strong>: Access to the token approvals API endpoints
231
+ </summary>
123
232
 
124
233
  - `getApprovals()`: Get a list of approvals across all ERC20 token contracts categorized by spenders for a wallet’s assets.
125
234
  - `getNftApprovals()`: Get a list of approvals across all NFT contracts categorized by spenders for a wallet’s assets.
235
+ </details>
126
236
 
127
- ### BalanceService
128
-
129
- The `BalanceService` class refers to the [balances API endpoints](https://www.covalenthq.com/docs/api/balances/get-token-balances-for-address/):
237
+ <details>
238
+ <summary>
239
+ 2. <strong>Balance Service</strong>: Access to the balances endpoints
240
+ </summary>
130
241
 
131
242
  - `getTokenBalancesForWalletAddress()`: Fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
132
243
  - `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.
@@ -136,10 +247,12 @@ The `BalanceService` class refers to the [balances API endpoints](https://www.co
136
247
  - `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)
137
248
  - `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)
138
249
  - `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.
250
+ </details>
139
251
 
140
- ### BaseService
141
-
142
- The `BaseService` class refers to the [address activity, log events, chain status and block retrieval API endpoints](https://www.covalenthq.com/docs/api/base/get-address-activity/):
252
+ <details>
253
+ <summary>
254
+ 3. <strong>Balance Service</strong>: Access to the address activity, log events, chain status, and block retrieval endpoints
255
+ </summary>
143
256
 
144
257
  - `getBlock()`: Fetch and render a single block for a block explorer.
145
258
  - `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.
@@ -154,10 +267,12 @@ The `BaseService` class refers to the [address activity, log events, chain statu
154
267
  - `getAllChainStatus()`: Used to build internal status dashboards of all supported chains.
155
268
  - `getAddressActivity()`: Locate chains where an address is active on with a single API call.
156
269
  - `getGasPrices()`: Get real-time gas estimates for different transaction speeds on a specific network, enabling users to optimize transaction costs and confirmation times.
270
+ </details>
157
271
 
158
- ### NftService
159
-
160
- The `NftService` class refers to the [NFT API endpoints](https://www.covalenthq.com/docs/api/nft/get-nfts-for-address/):
272
+ <details>
273
+ <summary>
274
+ 4. <strong>NFT Service</strong>: Access to the NFT endpoints
275
+ </summary>
161
276
 
162
277
  - `getChainCollections()`: Used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files. (Paginated)
163
278
  - `getChainCollectionsByPage()`: Used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files. (Nonpaginated)
@@ -171,19 +286,20 @@ The `NftService` class refers to the [NFT API endpoints](https://www.covalenthq.
171
286
  - `getCollectionTraitsSummary()`: Used to calculate rarity scores for a collection based on its traits.
172
287
  - `checkOwnershipInNft()`: Used to verify ownership of NFTs (including ERC-721 and ERC-1155) within a collection.
173
288
  - `checkOwnershipInNftForSpecificTokenId()`: Used to verify ownership of a specific token (ERC-721 or ERC-1155) within a collection.
174
- - `getNftMarketSaleCount()`: Used to build a time-series chart of the sales count of an NFT collection.
175
- - `getNftMarketVolume()`: Used to build a time-series chart of the transaction volume of an NFT collection.
176
- - `getNftMarketFloorPrice()`: Used to render a price floor chart for an NFT collection.
177
-
178
- ### PricingService
289
+ </details>
179
290
 
180
- The `PricingService` class refers to the [historical token prices API endpoint](https://www.covalenthq.com/docs/api/pricing/get-historical-token-prices/):
291
+ <details>
292
+ <summary>
293
+ 5. <strong>Pricing Service</strong>: Access to the historical token prices endpoint
294
+ </summary>
181
295
 
182
296
  - `getTokenPrices()`: Get historic prices of a token between date ranges. Supports native tokens.
297
+ </details>
183
298
 
184
- ### TransactionService
185
-
186
- The `TransactionService` class refers to the [transactions API endpoints](https://www.covalenthq.com/docs/api/transactions/get-a-transaction/):
299
+ <details>
300
+ <summary>
301
+ 6. <strong>Transaction Service</strong>: Access to the transactions endpoints
302
+ </summary>
187
303
 
188
304
  - `getAllTransactionsForAddress()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Paginated)
189
305
  - `getAllTransactionsForAddressByPage()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Nonpaginated)
@@ -194,192 +310,17 @@ The `TransactionService` class refers to the [transactions API endpoints](https:
194
310
  - `getTimeBucketTransactionsForAddress()`: Fetch all transactions including their decoded log events in a 15-minute time bucket interval.
195
311
  - `getTransactionsForBlockHashByPage()`: Fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
196
312
  - `getTransactionsForBlockHash()`: Fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
313
+ </details>
197
314
 
315
+ ## Contributing
198
316
 
199
- The functions `getAllTransactionsForAddressByPage()`, `getTransactionsForAddressV3()`, and `getTimeBucketTransactionsForAddress()` 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.
200
-
201
- ```ts
202
- import { CovalentClient } from "@covalenthq/client-sdk";
203
-
204
- const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
205
- const resp = await client.TransactionService.getAllTransactionsForAddressByPage("eth-mainnet", "WALLET_ADDRESS");
206
- // assuming resp.data.current_page is 10
207
- if (resp.data !== null) {
208
- const prevPage = await resp.data.prev() // will retrieve page 9
209
- console.log(prevPage.data)
210
- }
211
- ```
212
-
213
- ### XykService
214
-
215
- The `XykService` refers to the [Xy=k API endpoints](https://www.covalenthq.com/docs/api/xyk/get-xyk-pools/):
216
-
217
- - `getPools()`: Get all the pools of a particular DEX. Supports most common DEXs (Uniswap, SushiSwap, etc), and returns detailed trading data (volume, liquidity, swap counts, fees, LP token prices).
218
- - `getPoolByAddress()`: Get the 7 day and 30 day time-series data (volume, liquidity, price) of a particular liquidity pool in a DEX. Useful for building time-series charts on DEX trading activity.
219
- - `getPoolsForTokenAddress()`: Get all pools and the supported DEX for a token. Useful for building a table of top pairs across all supported DEXes that the token is trading on.
220
- - `getPoolsForWalletAddress()`: Get all pools and supported DEX for a wallet. Useful for building a personal DEX UI showcasing pairs and supported DEXes associated to the wallet.
221
- - `getAddressExchangeBalances()`: Return balance of a wallet/contract address on a specific DEX.
222
- - `getNetworkExchangeTokens()`: Retrieve all network exchange tokens for a specific DEX. Useful for building a top tokens table by total liquidity within a particular DEX.
223
- - `getLpTokenView()`: Get a detailed view for a single liquidity pool token. Includes time series data.
224
- - `getSupportedDEXes()`: Get all the supported DEXs available for the xy=k endpoints, along with the swap fees and factory addresses.
225
- - `getDexForPoolAddress()`: Get the supported DEX given a pool address, along with the swap fees, DEX's logo url, and factory addresses. Useful to identifying the specific DEX to which a pair address is associated.
226
- - `getSingleNetworkExchangeToken()`: Get historical daily swap count for a single network exchange token.
227
- - `getTransactionsForAccountAddress()`: Get all the DEX transactions of a wallet. Useful for building tables of DEX activity segmented by wallet.
228
- - `getTransactionsForTokenAddress()`: Get all the transactions of a token within a particular DEX. Useful for getting a per-token view of DEX activity.
229
- - `getTransactionsForExchange()`: Get all the transactions of a particular DEX liquidity pool. Useful for building a transactions history table for an individual pool.
230
- - `getTransactionsForDex()`: Get all the the transactions for a given DEX. Useful for building DEX activity views.
231
- - `getEcosystemChartData()`: Get a 7d and 30d time-series chart of DEX activity. Includes volume and swap count.
232
- - `getHealthData()`: Ping the health of xy=k endpoints to get the synced block height per chain.
233
-
234
- ## Additional Helper Functions
235
- ### calculatePrettyBalance
236
- The `calculatePrettyBalance` function is designed to take up to 4 inputs: the `balance` field obtained from the `tokenBalance` endpoint and the `contract_decimals`. The function also includes two optional fields, `roundOff` and `precision`, to allow developers to round the unscaled balance to a certain decimal precision. The primary purpose of this function is to convert the scaled token balance (the balance parameter) into its unscaled, human-readable form. The scaled balance needs to be divided by 10^(contractDecimals) to remove the scaling factor.
237
-
238
- ```ts
239
- import { CovalentClient, calculatePrettyBalance } from "@covalenthq/client-sdk";
240
-
241
- const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
242
- const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
243
- const prettyBalance = calculatePrettyBalance(resp.data.items[0].balance, resp.data.items[0].contract_decimals);
244
- ```
245
- ### prettifyCurrency
246
- The `prettifyCurrency` function refines the presentation of a monetary value, accepting a numerical amount and a fiat currency code as parameters (with USD as the default currency). It simplifies currency formatting for developers, ensuring visually polished representations of financial information in user interfaces for an enhanced user experience.
247
-
248
- ```ts
249
- import { CovalentClient, prettifyCurrency } from "@covalenthq/client-sdk";
250
-
251
- const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
252
- const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
253
- const prettyCurrency = prettifyCurrency(resp.data.items[0].quote_rate);
254
- ```
255
-
256
- ## Built-in SDK Features
257
- ### Explaining Pagination Mechanism Within the SDK
258
-
259
- The following endpoints support pagination:
260
-
261
- - `getErc20TransfersForWalletAddress()`
262
- - `getTokenHoldersV2ForTokenAddress()`
263
- - `getBlockHeights()`
264
- - `getLogEventsByAddress()`
265
- - `getLogEventsByTopicHash()`
266
- - `getChainCollections()`
267
- - `getTokenIdsForContractWithMetadata()`
268
- - `getAllTransactionsForAddress()`
317
+ Contributions, issues and feature requests are welcome!
318
+ Feel free to check [issues](https://github.com/covalenthq/covalent-api-sdk-ts/issues) page.
269
319
 
270
- Using the Covalent API, paginated supported endpoints return only 100 items, such as transactions or log events, per page. However, the Covalent SDK leverages generators to *seamlessly fetch all items without the user having to deal with pagination*.
320
+ ## Show your support
271
321
 
272
- For example, the following fetches ALL transactions for `demo.eth` on Ethereum:
273
- ```ts
274
- import { CovalentClient } from "@covalenthq/client-sdk";
275
-
276
- const ApiServices = async () => {
277
- const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
278
- try {
279
- for await (const tx of client.TransactionService.getAllTransactionsForAddress("eth-mainnet", "demo.eth")) {
280
- console.log("tx", tx);
281
- }
282
- } catch (error) {
283
- console.log(error.message);
284
- }
285
- }
286
- ```
287
-
288
- ### Concurrency Mechanism
289
-
290
- Developers have the flexibility to specify the desired number of concurrent API calls they wish to execute using the `threadCount` settings parameter, with a default value of `3`. For example:
291
-
292
- ```ts
293
- import { CovalentClient, CovalentClientSettings } from "@covalenthq/client-sdk";
294
-
295
- const settings: CovalentClientSettings = {
296
- threadCount: 5
297
- }
298
-
299
- const ApiServices = async () => {
300
- const client = new CovalentClient("YOUR_API_KEY", settings); // Replace with your Covalent API key and add set debugger
301
- const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
302
- if (!resp.error) {
303
- console.log(resp.data);
304
- } else {
305
- console.log(resp.error_message);
306
- }
307
- }
308
- ```
309
-
310
- ### Debugger Mode
311
-
312
- Developers have the option to enable a debugger mode that provides response times, the URLs of called endpoints, and the HTTP statuses of those endpoints. This feature helps users identify which endpoints may have encountered failures. The default is `debug = false` if no input is provided.
313
-
314
- ```ts
315
- import { CovalentClient, CovalentClientSettings } from "@covalenthq/client-sdk";
316
-
317
- const settings: CovalentClientSettings = {
318
- debug: true
319
- }
320
-
321
- const ApiServices = async () => {
322
- const client = new CovalentClient("YOUR_API_KEY", settings); // Replace with your Covalent API key and add set debugger
323
- const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
324
- if (!resp.error) {
325
- console.log(resp.data);
326
- } else {
327
- console.log(resp.error_message);
328
- }
329
- }
330
- ```
331
-
332
- ![example result image](https://www.datocms-assets.com/86369/1697154621-sdk-debugger-output.png)
333
-
334
- ### Retry Mechanism
335
-
336
- Each endpoint is equipped with an exponential backoff algorithm that exponentially extends the wait time between retries, up to a `maximum of 5` retry attempts.
337
-
338
- Users have the ability to control the retry feature through the enableRetry configuration setting. By default, this feature is enabled `true`. However, users can deactivate it by setting `enableRetry` to `false`.
339
-
340
- ```ts
341
- import { CovalentClient, CovalentClientSettings } from "@covalenthq/client-sdk";
342
-
343
- const settings: CovalentClientSettings = {
344
- enableRetry: false
345
- }
346
- ```
347
-
348
- ### Error Handling
349
- The paginated endpoints throw an error message in this format: `An error occurred {error_code}: {error_message}`. The developer will need to `catch` these errors. Note - these endpoints do not follow the default response format which is:
350
- ```ts
351
-
352
- "data": ...,
353
- "error": false,
354
- "error_message": null,
355
- "error_code": null
356
-
357
- ```
358
-
359
- ### Error codes
360
- Covalent uses standard HTTP response codes to indicate the success or failure of an API request. In general: codes in the 2xx range indicate success. Codes in the 4xx range indicate an error that failed given the information provided (e.g., a required parameter was omitted, etc.). Codes in the 5xx range indicate an error with Covalent's servers (these are rare).
361
-
362
- | Code | Description |
363
- | ----------- | ----------- |
364
- | 200 | OK Everything worked as expected. |
365
- | 400 | Bad Request The request could not be accepted, usually due to a missing required parameter. |
366
- | 401 | Unauthorized No valid API key was provided. |
367
- | 404 | Not Found The request path does not exist. |
368
- | 429 | Too Many Requests You are being rate-limited. Please see the rate limiting section for more information. |
369
- | 500, 502, 503 | Server Errors Something went wrong on Covalent's servers. These are rare. |
370
-
371
- ## Tests
372
- to run all tests, you need to input your api key first shown below
373
- ```
374
- COVALENT_API_KEY=YOUR_KEY npm test
375
- ```
376
- OR
377
-
378
- you can run individual tests for each service, for example
379
- ```
380
- COVALENT_API_KEY=YOUR_KEY npm test -- security-service.test.ts
381
- ```
322
+ Give a ⭐️ if this project helped you!
382
323
 
383
- ## Documentation
324
+ ## License
384
325
 
385
- The Covalent API SDK documentation is integrated within the source code through `tsdoc` comments. When utilizing an Integrated Development Environment (IDE), the SDK provides generated types and accompanying documentation for seamless reference and usage.
326
+ This project is [Apache-2.0](./LICENSE) licensed.
package/package.json CHANGED
@@ -1,35 +1,48 @@
1
1
  {
2
2
  "name": "@covalenthq/client-sdk",
3
- "version": "1.0.2",
3
+ "version": "2.0.0",
4
4
  "types": "dist/index.d.ts",
5
5
  "files": [
6
6
  "/dist"
7
7
  ],
8
8
  "repository": "https://github.com/covalenthq/covalent-api-sdk-ts",
9
- "author": "Covalenthq",
10
- "license": "MIT",
9
+ "author": "@covalenthq",
10
+ "license": "Apache-2.0",
11
11
  "dependencies": {
12
- "@rollup/plugin-commonjs": "^25.0.4",
13
- "@rollup/plugin-node-resolve": "^15.2.1",
14
- "big.js": "^6.2.1",
15
- "date-fns": "^2.30.0",
16
- "rollup": "^3.29.1",
17
- "rollup-plugin-typescript2": "^0.35.0",
18
- "typescript": "^5.1.6"
12
+ "big.js": "^6.2.1"
19
13
  },
20
14
  "homepage": "https://github.com/covalenthq/covalent-api-sdk-ts#readme",
21
15
  "devDependencies": {
16
+ "@rollup/plugin-commonjs": "^25.0.4",
17
+ "@rollup/plugin-json": "^6.1.0",
18
+ "@rollup/plugin-node-resolve": "^15.2.1",
19
+ "@trivago/prettier-plugin-sort-imports": "^4.3.0",
22
20
  "@types/big.js": "^6.2.2",
23
21
  "@types/jest": "^29.5.5",
22
+ "@types/node": "^20",
23
+ "@typescript-eslint/eslint-plugin": "^7.7.1",
24
+ "@typescript-eslint/parser": "^7.7.1",
25
+ "dotenv": "^16.4.5",
26
+ "eslint": "^8",
27
+ "eslint-config-prettier": "^9.1.0",
28
+ "eslint-plugin-prettier": "^5.1.3",
24
29
  "jest": "^29.6.1",
25
30
  "p-limit": "^3.1.0",
26
- "ts-jest": "^29.1.1"
31
+ "prettier": "^3.3.2",
32
+ "rollup": "^3.29.1",
33
+ "rollup-plugin-typescript2": "^0.35.0",
34
+ "ts-jest": "^29.1.1",
35
+ "ts-node": "^10.9.2",
36
+ "typescript": "^5"
27
37
  },
28
38
  "scripts": {
29
39
  "test": "jest",
30
40
  "build": "rollup -c rollup.config.js",
31
41
  "clean": "rm -rf dist",
32
- "start": "rollup -c"
42
+ "start": "rollup -c",
43
+ "lint": "eslint .",
44
+ "pretty": "prettier . --write",
45
+ "prepublish": "npm run clean"
33
46
  },
34
47
  "main": "dist/cjs/index.js",
35
48
  "main-es": "dist/es/index.js",