@covalenthq/client-sdk 0.9.3 → 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.
- package/README.md +72 -51
- package/dist/cjs/index.js +15 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/services/BalanceService.d.ts +1 -1
- package/dist/cjs/services/BaseService.d.ts +4 -0
- package/dist/cjs/services/CovalentClient.d.ts +1 -1
- package/dist/cjs/services/PricingService.d.ts +11 -0
- package/dist/cjs/services/TransactionService.d.ts +2 -0
- package/dist/cjs/util/types/BalanceServiceTypes.d.ts +2 -10
- package/dist/cjs/util/types/BaseServiceTypes.d.ts +2 -0
- package/dist/cjs/util/types/GenericTypes.d.ts +10 -0
- package/dist/cjs/util/types/PricingServiceTypes.d.ts +3 -1
- package/dist/es/index.js +15 -4
- package/dist/es/index.js.map +1 -1
- package/dist/es/services/BalanceService.d.ts +1 -1
- package/dist/es/services/BaseService.d.ts +4 -0
- package/dist/es/services/CovalentClient.d.ts +1 -1
- package/dist/es/services/PricingService.d.ts +11 -0
- package/dist/es/services/TransactionService.d.ts +2 -0
- package/dist/es/util/types/BalanceServiceTypes.d.ts +2 -10
- package/dist/es/util/types/BaseServiceTypes.d.ts +2 -0
- package/dist/es/util/types/GenericTypes.d.ts +10 -0
- package/dist/es/util/types/PricingServiceTypes.d.ts +3 -1
- package/dist/esm/index.js +15 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/BalanceService.d.ts +1 -1
- package/dist/esm/services/BaseService.d.ts +4 -0
- package/dist/esm/services/CovalentClient.d.ts +1 -1
- package/dist/esm/services/PricingService.d.ts +11 -0
- package/dist/esm/services/TransactionService.d.ts +2 -0
- package/dist/esm/util/types/BalanceServiceTypes.d.ts +2 -10
- package/dist/esm/util/types/BaseServiceTypes.d.ts +2 -0
- package/dist/esm/util/types/GenericTypes.d.ts +10 -0
- package/dist/esm/util/types/PricingServiceTypes.d.ts +3 -1
- package/dist/services/BalanceService.d.ts +1 -1
- package/dist/services/BaseService.d.ts +4 -0
- package/dist/services/BaseService.js +2 -0
- package/dist/services/BaseService.js.map +1 -1
- package/dist/services/CovalentClient.d.ts +1 -1
- package/dist/services/CovalentClient.js +1 -1
- package/dist/services/PricingService.d.ts +11 -0
- package/dist/services/PricingService.js +8 -0
- package/dist/services/PricingService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +2 -0
- package/dist/services/TransactionService.js +1 -0
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/util/types/BalanceServiceTypes.d.ts +2 -10
- package/dist/util/types/BaseServiceTypes.d.ts +2 -0
- package/dist/util/types/GenericTypes.d.ts +10 -0
- package/dist/util/types/PricingServiceTypes.d.ts +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,9 +17,9 @@ The Covalent SDK is the fastest way to integrate the Covalent Unified API for wo
|
|
|
17
17
|
|
|
18
18
|
**Note - Require `Node v18` and above for best results.**
|
|
19
19
|
|
|
20
|
-
> **
|
|
20
|
+
> **Sign up for an API Key**
|
|
21
21
|
>
|
|
22
|
-
>
|
|
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.
|
|
23
23
|
|
|
24
24
|
## Getting started
|
|
25
25
|
|
|
@@ -31,6 +31,10 @@ or
|
|
|
31
31
|
yarn add @covalenthq/client-sdk
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
## How to use the Covalent SDK
|
|
35
|
+
|
|
36
|
+
**Video Tutorial**: https://www.youtube.com/watch?v=XSpPJP2w62E&ab_channel=Covalent
|
|
37
|
+
|
|
34
38
|
After installing, you can import and use the SDK with:
|
|
35
39
|
|
|
36
40
|
```ts
|
|
@@ -39,47 +43,38 @@ import { CovalentClient, Chains } from "@covalenthq/client-sdk";
|
|
|
39
43
|
const ApiServices = async () => {
|
|
40
44
|
const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
console.log(respWithStringLiteral.data);
|
|
46
|
-
} else {
|
|
47
|
-
console.log(respWithStringLiteral.error_message);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Example call with enum
|
|
51
|
-
const respWithEnum = await client.BalanceService.getTokenBalancesForWalletAddress(Chains.ETH_MAINNET, "WALLET_ADDRESS");
|
|
52
|
-
if (!respWithEnum.error) {
|
|
53
|
-
console.log(respWithEnum.data);
|
|
46
|
+
const balanceResp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
|
|
47
|
+
if (!balanceResp.error) {
|
|
48
|
+
console.log(balanceResp.data);
|
|
54
49
|
} else {
|
|
55
|
-
console.log(
|
|
50
|
+
console.log(balanceResp.error_message);
|
|
56
51
|
}
|
|
57
52
|
}
|
|
58
53
|
```
|
|
59
|
-
|
|
60
|
-
> **Getting an API Key**
|
|
54
|
+
> **Name Resolution**
|
|
61
55
|
>
|
|
62
|
-
>
|
|
63
|
-
|
|
64
|
-
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`)
|
|
65
57
|
|
|
66
|
-
|
|
67
|
-
>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
**ℹ️ BREAKING CHANGE**
|
|
59
|
+
> If you have been importing with `Client`:
|
|
60
|
+
```ts
|
|
61
|
+
import { Client } from "@covalenthq/client-sdk";
|
|
62
|
+
```
|
|
71
63
|
>
|
|
72
|
-
>
|
|
64
|
+
> Please change to `CovalentClient`:
|
|
65
|
+
```ts
|
|
66
|
+
import { CovalentClient } from "@covalenthq/client-sdk";
|
|
67
|
+
```
|
|
73
68
|
|
|
74
|
-
###
|
|
69
|
+
### How to apply supported query parameters to endpoints
|
|
75
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.
|
|
76
71
|
|
|
77
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:
|
|
78
73
|
```ts
|
|
79
74
|
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS", {quoteCurrency: "CAD", nft: true});
|
|
80
75
|
```
|
|
81
|
-
|
|
82
|
-
You can import
|
|
76
|
+
### Assign Types
|
|
77
|
+
You can import types for each endpoint, found here `src/util/types/`. Here is an example:
|
|
83
78
|
```ts
|
|
84
79
|
import { CovalentClient, BalancesResponse, BalanceItem } from "@covalenthq/client-sdk";
|
|
85
80
|
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS", {quoteCurrency: "CAD", nft: true});
|
|
@@ -87,7 +82,30 @@ const data: BalancesResponse = resp.data; // `resp.data` in this case is of type
|
|
|
87
82
|
const items: BalanceItem[] = resp.data.items; // `resp.data.items` is of type `BalanceItem[]`
|
|
88
83
|
```
|
|
89
84
|
|
|
90
|
-
|
|
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
|
|
91
109
|
|
|
92
110
|
The Covalent SDK provides comprehensive support for all Class A, Class B, and Pricing endpoints that are grouped under the following *Service* namespaces:
|
|
93
111
|
|
|
@@ -119,26 +137,6 @@ The `BalanceService` class refers to the [balances API endpoints](https://www.co
|
|
|
119
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)
|
|
120
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.
|
|
121
139
|
|
|
122
|
-
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.
|
|
123
|
-
|
|
124
|
-
```ts
|
|
125
|
-
import { CovalentClient, calculatePrettyBalance } from "@covalenthq/client-sdk";
|
|
126
|
-
|
|
127
|
-
const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
|
|
128
|
-
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
|
|
129
|
-
const prettyBalance = calculatePrettyBalance(resp.data.items[0].balance, resp.data.items[0].contract_decimals);
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
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.
|
|
133
|
-
|
|
134
|
-
```ts
|
|
135
|
-
import { CovalentClient, prettifyCurrency } from "@covalenthq/client-sdk";
|
|
136
|
-
|
|
137
|
-
const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
|
|
138
|
-
const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", "WALLET_ADDRESS");
|
|
139
|
-
const prettyCurrency = prettifyCurrency(resp.data.items[0].quote_rate);
|
|
140
|
-
```
|
|
141
|
-
|
|
142
140
|
### BaseService
|
|
143
141
|
|
|
144
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/):
|
|
@@ -233,7 +231,30 @@ The `XykService` refers to the [Xy=k API endpoints](https://www.covalenthq.com/d
|
|
|
233
231
|
- `getEcosystemChartData()`: Get a 7d and 30d time-series chart of DEX activity. Includes volume and swap count.
|
|
234
232
|
- `getHealthData()`: Ping the health of xy=k endpoints to get the synced block height per chain.
|
|
235
233
|
|
|
236
|
-
##
|
|
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
|
|
237
258
|
|
|
238
259
|
The following endpoints support pagination:
|
|
239
260
|
|
package/dist/cjs/index.js
CHANGED
|
@@ -555,18 +555,18 @@ class BalanceItem {
|
|
|
555
555
|
this.quote_24h = data.quote_24h;
|
|
556
556
|
this.pretty_quote = data.pretty_quote;
|
|
557
557
|
this.pretty_quote_24h = data.pretty_quote_24h;
|
|
558
|
-
this.logo_urls = data.logo_urls && data.logo_urls !== null ? new LogoUrls(data.logo_urls) : null;
|
|
558
|
+
this.logo_urls = data.logo_urls && data.logo_urls !== null ? new LogoUrls$1(data.logo_urls) : null;
|
|
559
559
|
this.protocol_metadata = data.protocol_metadata && data.protocol_metadata !== null ? new ProtocolMetadata(data.protocol_metadata) : null;
|
|
560
560
|
this.nft_data = data.nft_data && data.nft_data !== null ? data.nft_data.map((itemData) => new NftData$1(itemData)) : null;
|
|
561
561
|
}
|
|
562
562
|
}
|
|
563
|
-
class LogoUrls {
|
|
563
|
+
let LogoUrls$1 = class LogoUrls {
|
|
564
564
|
constructor(data) {
|
|
565
565
|
this.token_logo_url = data.token_logo_url;
|
|
566
566
|
this.protocol_logo_url = data.protocol_logo_url;
|
|
567
567
|
this.chain_logo_url = data.chain_logo_url;
|
|
568
568
|
}
|
|
569
|
-
}
|
|
569
|
+
};
|
|
570
570
|
class ProtocolMetadata {
|
|
571
571
|
constructor(data) {
|
|
572
572
|
this.protocol_name = data.protocol_name;
|
|
@@ -1549,6 +1549,7 @@ class GetLogsEvent {
|
|
|
1549
1549
|
this.sender_address = data.sender_address;
|
|
1550
1550
|
this.sender_address_label = data.sender_address_label;
|
|
1551
1551
|
this.sender_logo_url = data.sender_logo_url;
|
|
1552
|
+
this.sender_factory_address = data.sender_factory_address;
|
|
1552
1553
|
this.raw_log_data = data.raw_log_data;
|
|
1553
1554
|
this.decoded = data.decoded && data.decoded !== null ? new DecodedItem$2(data.decoded) : null;
|
|
1554
1555
|
}
|
|
@@ -1592,6 +1593,7 @@ let LogEvent$2 = class LogEvent {
|
|
|
1592
1593
|
this.sender_address = data.sender_address;
|
|
1593
1594
|
this.sender_address_label = data.sender_address_label;
|
|
1594
1595
|
this.sender_logo_url = data.sender_logo_url;
|
|
1596
|
+
this.sender_factory_address = data.sender_factory_address;
|
|
1595
1597
|
this.raw_log_data = data.raw_log_data;
|
|
1596
1598
|
this.decoded = data.decoded && data.decoded !== null ? new DecodedItem$2(data.decoded) : null;
|
|
1597
1599
|
}
|
|
@@ -4142,10 +4144,18 @@ class TokenPricesResponse {
|
|
|
4142
4144
|
this.logo_url = data.logo_url;
|
|
4143
4145
|
this.update_at = data.update_at && data.update_at !== null ? dateFns.parseISO(data.update_at.toString()) : null;
|
|
4144
4146
|
this.quote_currency = data.quote_currency;
|
|
4147
|
+
this.logo_urls = data.logo_urls && data.logo_urls !== null ? new LogoUrls(data.logo_urls) : null;
|
|
4145
4148
|
this.prices = data.prices && data.prices !== null ? data.prices.map((itemData) => new Price(itemData)) : null;
|
|
4146
4149
|
this.items = data.items && data.items !== null ? data.items.map((itemData) => new Price(itemData)) : null;
|
|
4147
4150
|
}
|
|
4148
4151
|
}
|
|
4152
|
+
class LogoUrls {
|
|
4153
|
+
constructor(data) {
|
|
4154
|
+
this.token_logo_url = data.token_logo_url;
|
|
4155
|
+
this.protocol_logo_url = data.protocol_logo_url;
|
|
4156
|
+
this.chain_logo_url = data.chain_logo_url;
|
|
4157
|
+
}
|
|
4158
|
+
}
|
|
4149
4159
|
class Price {
|
|
4150
4160
|
constructor(data) {
|
|
4151
4161
|
this.date = data.date && data.date !== null ? dateFns.parseISO(data.date.toString()) : null;
|
|
@@ -4459,6 +4469,7 @@ class LogEvent {
|
|
|
4459
4469
|
this.sender_address = data.sender_address;
|
|
4460
4470
|
this.sender_address_label = data.sender_address_label;
|
|
4461
4471
|
this.sender_logo_url = data.sender_logo_url;
|
|
4472
|
+
this.sender_factory_address = data.sender_factory_address;
|
|
4462
4473
|
this.raw_log_data = data.raw_log_data;
|
|
4463
4474
|
this.decoded = data.decoded && data.decoded !== null ? new DecodedItem(data.decoded) : null;
|
|
4464
4475
|
}
|
|
@@ -7773,7 +7784,7 @@ class XykService {
|
|
|
7773
7784
|
}
|
|
7774
7785
|
}
|
|
7775
7786
|
|
|
7776
|
-
const userAgent = "com.covalenthq.sdk.typescript/0.9.
|
|
7787
|
+
const userAgent = "com.covalenthq.sdk.typescript/0.9.4";
|
|
7777
7788
|
class Response {
|
|
7778
7789
|
}
|
|
7779
7790
|
/**
|