@covalenthq/client-sdk 0.9.2 → 0.9.4

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 (65) hide show
  1. package/README.md +76 -53
  2. package/dist/cjs/index.js +27 -83
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/services/BalanceService.d.ts +1 -1
  5. package/dist/cjs/services/BaseService.d.ts +4 -0
  6. package/dist/cjs/services/CovalentClient.d.ts +1 -1
  7. package/dist/cjs/services/NftService.d.ts +10 -1
  8. package/dist/cjs/services/PricingService.d.ts +11 -0
  9. package/dist/cjs/services/TransactionService.d.ts +2 -0
  10. package/dist/cjs/util/types/BalanceServiceTypes.d.ts +2 -10
  11. package/dist/cjs/util/types/BaseServiceTypes.d.ts +2 -0
  12. package/dist/cjs/util/types/GenericTypes.d.ts +10 -0
  13. package/dist/cjs/util/types/PricingServiceTypes.d.ts +3 -1
  14. package/dist/es/index.js +27 -83
  15. package/dist/es/index.js.map +1 -1
  16. package/dist/es/services/BalanceService.d.ts +1 -1
  17. package/dist/es/services/BaseService.d.ts +4 -0
  18. package/dist/es/services/CovalentClient.d.ts +1 -1
  19. package/dist/es/services/NftService.d.ts +10 -1
  20. package/dist/es/services/PricingService.d.ts +11 -0
  21. package/dist/es/services/TransactionService.d.ts +2 -0
  22. package/dist/es/util/types/BalanceServiceTypes.d.ts +2 -10
  23. package/dist/es/util/types/BaseServiceTypes.d.ts +2 -0
  24. package/dist/es/util/types/GenericTypes.d.ts +10 -0
  25. package/dist/es/util/types/PricingServiceTypes.d.ts +3 -1
  26. package/dist/esm/index.js +27 -83
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/services/BalanceService.d.ts +1 -1
  29. package/dist/esm/services/BaseService.d.ts +4 -0
  30. package/dist/esm/services/CovalentClient.d.ts +1 -1
  31. package/dist/esm/services/NftService.d.ts +10 -1
  32. package/dist/esm/services/PricingService.d.ts +11 -0
  33. package/dist/esm/services/TransactionService.d.ts +2 -0
  34. package/dist/esm/util/types/BalanceServiceTypes.d.ts +2 -10
  35. package/dist/esm/util/types/BaseServiceTypes.d.ts +2 -0
  36. package/dist/esm/util/types/GenericTypes.d.ts +10 -0
  37. package/dist/esm/util/types/PricingServiceTypes.d.ts +3 -1
  38. package/dist/services/BalanceService.d.ts +1 -1
  39. package/dist/services/BalanceService.js +1 -7
  40. package/dist/services/BalanceService.js.map +1 -1
  41. package/dist/services/BaseService.d.ts +4 -0
  42. package/dist/services/BaseService.js +3 -11
  43. package/dist/services/BaseService.js.map +1 -1
  44. package/dist/services/CovalentClient.d.ts +1 -1
  45. package/dist/services/CovalentClient.js +1 -1
  46. package/dist/services/NftService.d.ts +10 -1
  47. package/dist/services/NftService.js +11 -15
  48. package/dist/services/NftService.js.map +1 -1
  49. package/dist/services/PricingService.d.ts +11 -0
  50. package/dist/services/PricingService.js +9 -2
  51. package/dist/services/PricingService.js.map +1 -1
  52. package/dist/services/SecurityService.js +1 -3
  53. package/dist/services/SecurityService.js.map +1 -1
  54. package/dist/services/TransactionService.d.ts +2 -0
  55. package/dist/services/TransactionService.js +3 -19
  56. package/dist/services/TransactionService.js.map +1 -1
  57. package/dist/services/XykService.js +1 -17
  58. package/dist/services/XykService.js.map +1 -1
  59. package/dist/util/ApiHelpers.js +1 -2
  60. package/dist/util/ApiHelpers.js.map +1 -1
  61. package/dist/util/types/BalanceServiceTypes.d.ts +2 -10
  62. package/dist/util/types/BaseServiceTypes.d.ts +2 -0
  63. package/dist/util/types/GenericTypes.d.ts +10 -0
  64. package/dist/util/types/PricingServiceTypes.d.ts +3 -1
  65. package/package.json +1 -1
package/README.md CHANGED
@@ -5,6 +5,9 @@
5
5
  <a href="https://www.npmjs.com/package/@covalenthq/client-sdk">
6
6
  <img src="https://img.shields.io/npm/dm/@covalenthq/client-sdk" alt="npm downloads">
7
7
  </a>
8
+ <a>
9
+ <img src="https://img.shields.io/badge/node-20.x-green">
10
+ <a>
8
11
  </p>
9
12
 
10
13
 
@@ -12,12 +15,11 @@
12
15
 
13
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.
14
17
 
15
- Note - use `Node v18` and above for best results.
18
+ **Note - Require `Node v18` and above for best results.**
16
19
 
17
-
18
- > **Name Resolution**
20
+ > **Sign up for an API Key**
19
21
  >
20
- > 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`)
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.
21
23
 
22
24
  ## Getting started
23
25
 
@@ -29,6 +31,10 @@ or
29
31
  yarn add @covalenthq/client-sdk
30
32
  ```
31
33
 
34
+ ## How to use the Covalent SDK
35
+
36
+ **Video Tutorial**: https://www.youtube.com/watch?v=XSpPJP2w62E&ab_channel=Covalent
37
+
32
38
  After installing, you can import and use the SDK with:
33
39
 
34
40
  ```ts
@@ -37,47 +43,38 @@ import { CovalentClient, Chains } from "@covalenthq/client-sdk";
37
43
  const ApiServices = async () => {
38
44
  const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
39
45
 
40
- // Example call with string literal type
41
- const respWithStringLiteral = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
42
- if (!respWithStringLiteral.error) {
43
- console.log(respWithStringLiteral.data);
44
- } else {
45
- console.log(respWithStringLiteral.error_message);
46
- }
47
-
48
- // Example call with enum
49
- const respWithEnum = await client.BalanceService.getTokenBalancesForWalletAddress(Chains.ETH_MAINNET, "WALLET_ADDRESS");
50
- if (!respWithEnum.error) {
51
- console.log(respWithEnum.data);
46
+ const balanceResp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
47
+ if (!balanceResp.error) {
48
+ console.log(balanceResp.data);
52
49
  } else {
53
- console.log(respWithEnum.error_message);
50
+ console.log(balanceResp.error_message);
54
51
  }
55
52
  }
56
53
  ```
57
-
58
- > **Getting an API Key**
54
+ > **Name Resolution**
59
55
  >
60
- > 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.
61
-
62
- Note about a **ℹ️ BREAKING CHANGE**:
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`)
63
57
 
64
- > If you have been using:
65
- >
66
- > `import { Client } from "@covalenthq/client-sdk";`
67
- >
68
- > Please change to:
58
+ **ℹ️ BREAKING CHANGE**
59
+ > If you have been importing with `Client`:
60
+ ```ts
61
+ import { Client } from "@covalenthq/client-sdk";
62
+ ```
69
63
  >
70
- > `import { CovalentClient } from "@covalenthq/client-sdk";`
64
+ > Please change to `CovalentClient`:
65
+ ```ts
66
+ import { CovalentClient } from "@covalenthq/client-sdk";
67
+ ```
71
68
 
72
- ### Typed Objects
69
+ ### How to apply supported query parameters to endpoints
73
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.
74
71
 
75
72
  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:
76
73
  ```ts
77
74
  const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS", {quoteCurrency: "CAD", nft: true});
78
75
  ```
79
-
80
- You can import all the listed types. For example:
76
+ ### Assign Types
77
+ You can import types for each endpoint, found here `src/util/types/`. Here is an example:
81
78
  ```ts
82
79
  import { CovalentClient, BalancesResponse, BalanceItem } from "@covalenthq/client-sdk";
83
80
  const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS", {quoteCurrency: "CAD", nft: true});
@@ -85,7 +82,30 @@ const data: BalancesResponse = resp.data; // `resp.data` in this case is of type
85
82
  const items: BalanceItem[] = resp.data.items; // `resp.data.items` is of type `BalanceItem[]`
86
83
  ```
87
84
 
88
- ## How to use the Covalent SDK
85
+ ### Different ways to input chains in chain fields
86
+ We offer users three options for specifying a chain in the designated field:
87
+
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.
91
+
92
+ Example with string literal
93
+ ```ts
94
+ // Example call with string literal ("eth-mainnet")
95
+ const respWithStringLiteral = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
96
+ ```
97
+ Example with Chain Enum
98
+ ```ts
99
+ // Example call with enum (Chains.ETH_MAINNET)
100
+ const respWithEnum = await client.BalanceService.getTokenBalancesForWalletAddress(Chains.ETH_MAINNET, "WALLET_ADDRESS");
101
+ ```
102
+ Example with Chain Id
103
+ ```ts
104
+ // Example call with chain Id (1)
105
+ const respWithChainId = await client.BalanceService.getTokenBalancesForWalletAddress(1, "WALLET_ADDRESS");
106
+ ```
107
+
108
+ ## Supported Endpoints
89
109
 
90
110
  The Covalent SDK provides comprehensive support for all Class A, Class B, and Pricing endpoints that are grouped under the following *Service* namespaces:
91
111
 
@@ -117,26 +137,6 @@ The `BalanceService` class refers to the [balances API endpoints](https://www.co
117
137
  - `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)
118
138
  - `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.
119
139
 
120
- 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.
121
-
122
- ```ts
123
- import { CovalentClient, calculatePrettyBalance } from "@covalenthq/client-sdk";
124
-
125
- const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
126
- const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
127
- const prettyBalance = calculatePrettyBalance(resp.data.items[0].balance, resp.data.items[0].contract_decimals);
128
- ```
129
-
130
- 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.
131
-
132
- ```ts
133
- import { CovalentClient, prettifyCurrency } from "@covalenthq/client-sdk";
134
-
135
- const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
136
- const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
137
- const prettyCurrency = prettifyCurrency(resp.data.items[0].quote_rate);
138
- ```
139
-
140
140
  ### BaseService
141
141
 
142
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/):
@@ -231,7 +231,30 @@ The `XykService` refers to the [Xy=k API endpoints](https://www.covalenthq.com/d
231
231
  - `getEcosystemChartData()`: Get a 7d and 30d time-series chart of DEX activity. Includes volume and swap count.
232
232
  - `getHealthData()`: Ping the health of xy=k endpoints to get the synced block height per chain.
233
233
 
234
- ## How pagination works
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
235
258
 
236
259
  The following endpoints support pagination:
237
260