@covalenthq/client-sdk 0.1.0 → 0.1.2
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 +158 -1
- package/dist/ApprovalService.d.ts +1 -1
- package/dist/ApprovalService.js +12 -5
- package/dist/ApprovalService.js.map +1 -1
- package/dist/BalancesService.d.ts +4 -4
- package/dist/BalancesService.js +48 -20
- package/dist/BalancesService.js.map +1 -1
- package/dist/BaseService.d.ts +1 -1
- package/dist/BaseService.js +67 -25
- package/dist/BaseService.js.map +1 -1
- package/dist/LogEventService.js +11 -4
- package/dist/LogEventService.js.map +1 -1
- package/dist/NameResolverService.d.ts +1 -1
- package/dist/NameResolverService.js +12 -5
- package/dist/NameResolverService.js.map +1 -1
- package/dist/NftService.d.ts +16 -14
- package/dist/NftService.js +143 -58
- package/dist/NftService.js.map +1 -1
- package/dist/PricingService.d.ts +1 -1
- package/dist/PricingService.js +12 -5
- package/dist/PricingService.js.map +1 -1
- package/dist/TransactionsService.d.ts +8 -8
- package/dist/TransactionsService.js +53 -25
- package/dist/TransactionsService.js.map +1 -1
- package/dist/XykService.d.ts +4 -4
- package/dist/XykService.js +125 -48
- package/dist/XykService.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1 +1,158 @@
|
|
|
1
|
-
# covalent-api-sdk-js
|
|
1
|
+
# covalent-api-sdk-js
|
|
2
|
+
|
|
3
|
+
The Covalent API SDK is currently supported for Javascript only.
|
|
4
|
+
|
|
5
|
+
The Covalent SDK supports all chains across Mainnets and Testnets. List of supported Networks can be found on our [Supported Networks page](https://www.covalenthq.com/docs/networks/)
|
|
6
|
+
|
|
7
|
+
> **Name Resolution**
|
|
8
|
+
>
|
|
9
|
+
> The Covalent SDK supports address resolution natively allowing an ENS, RNS, Lens Handle or Unstoppable Domains address to be passed in directly for all our endpoints.
|
|
10
|
+
|
|
11
|
+
## Getting started
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm install @covalenthq/client-sdk
|
|
15
|
+
```
|
|
16
|
+
or
|
|
17
|
+
```
|
|
18
|
+
yarn add @covalenthq/client-sdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
After installing the app, you can then import and use the SDK:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { Client } from "@covalenthq/client-sdk";
|
|
25
|
+
|
|
26
|
+
const ApiServices = async () => {
|
|
27
|
+
const client = new Client("YOUR_API_KEY"); // Replace with your Covalent API key.
|
|
28
|
+
const resp = await client.BalancesService.getTokenBalances("eth-mainnet", "WALLET_ADDRESS"); // Example call, refer to API Docs for required paramaters or click into the method `getTokenBalances` to see the accepted parameter arguments
|
|
29
|
+
console.log(resp.data);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
> **Creating a unique Covalent API Key**
|
|
34
|
+
>
|
|
35
|
+
> To create your own API key, **[sign up for an Covalent account here](https://www.covalenthq.com/platform/auth/register/)** and use the key created under the [API Keys](https://www.covalenthq.com/platform/apikey/) tab.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## How to use the Covalent SDK
|
|
39
|
+
|
|
40
|
+
The Covalent SDK provides comprehensive support for all Class A, Class B, and Pricing endpoints grouped under various Services, offering a wide range of functionalities and capabilities:
|
|
41
|
+
|
|
42
|
+
- `ApprovalService`: Access to the Covalent's getApprovals endpoint
|
|
43
|
+
- `BalancesService`: Access to the Covalent's balances endpoints
|
|
44
|
+
- `BaseServices`: Access to the Covalent's log events, chain, and block endpoints
|
|
45
|
+
- `LogEventService`: Access to the Covalent's get logs endpoint
|
|
46
|
+
- `NameResolverService`: Access to the Covalent's get resolved address for registered address endpoint
|
|
47
|
+
- `NftService`: Access to the Covalent's NFT endpoints
|
|
48
|
+
- `PricingService`: Access to the Covalent's get historical token prices endpoint
|
|
49
|
+
- `TransactionsService`: Access to the Covalent's transactions endpoints (with pagination)
|
|
50
|
+
- `XykService`: Access to the Covalent's Xy=k endpoints
|
|
51
|
+
|
|
52
|
+
### ApprovalService
|
|
53
|
+
|
|
54
|
+
The `ApprovalService` class contains the getApprovals() endpoint, refer to the [getApprovals endpoint on our API docs](https://www.covalenthq.com/docs/api/security/get-token-approvals-for-address/).
|
|
55
|
+
|
|
56
|
+
- `getApprovals()`: Get a list of approvals across all token contracts categorized by spenders for a wallet’s assets.
|
|
57
|
+
|
|
58
|
+
### BalancesService
|
|
59
|
+
|
|
60
|
+
The `BalancesService` class contains the balances endpoints. Listed below are the supported endpoints, also refer to our api docs under the Balances section in our class A endpoints.
|
|
61
|
+
|
|
62
|
+
- `getTokenBalances()`: Fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
|
|
63
|
+
- `getAddressPortfolio()`: Render a daily portfolio balance for an address broken down by the token. The timeframe is user-configurable, defaults to 30 days.
|
|
64
|
+
- `getErc20Transfers()`: Render the transfer-in and transfer-out of a token along with historical prices from an address.
|
|
65
|
+
- `getTokenHoldersV2()`: 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.
|
|
66
|
+
|
|
67
|
+
### BaseServices
|
|
68
|
+
|
|
69
|
+
The `BaseServices` class contains the log events, chain, and block endpoints. Listed below are the supported endpoints, also refer to our api docs under the Base section in our class A endpoints.
|
|
70
|
+
|
|
71
|
+
- `getBlock()`: Fetch and render a single block for a block explorer.
|
|
72
|
+
- `getBlockHeights()`: Get all the block heights within a particular date range. Useful for rendering a display where you sort blocks by day.
|
|
73
|
+
- `getLogEventsByAddress()`: Get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions.
|
|
74
|
+
- `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.
|
|
75
|
+
- `getAllChains()`: Used to build internal dashboards for all supported chains on Covalent.
|
|
76
|
+
- `getAllChainStatus()`: Used to build internal status dashboards of all supported chains.
|
|
77
|
+
|
|
78
|
+
### LogEventService
|
|
79
|
+
|
|
80
|
+
The `LogEventService` class contains the getLogs() endpoint. Refer to the [getLogs endpoint on our API docs](https://www.covalenthq.com/docs/api/base/get-logs/).
|
|
81
|
+
|
|
82
|
+
- `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.
|
|
83
|
+
|
|
84
|
+
### NameResolverService
|
|
85
|
+
|
|
86
|
+
The `NameResolverService` class contains the getResolvedAddress() endpoint. Refer to the [getResolvedAddress endpoint on our API docs](https://www.covalenthq.com/docs/api/base/get-resolved-address-for-registered-address/).
|
|
87
|
+
|
|
88
|
+
- `getResolvedAddress()`: Used to resolve ENS, RNS and Unstoppable Domains addresses.
|
|
89
|
+
|
|
90
|
+
### NftService
|
|
91
|
+
|
|
92
|
+
The `NftService` class contains the NFT endpoints. Listed below are the supported endpoints, also refer to our api docs under the NFT section in our class A endpoints.
|
|
93
|
+
|
|
94
|
+
- `getChainCollections()`: Used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files.
|
|
95
|
+
- `getNftsForAddress()`: Used to render the NFTs (including ERC721 and ERC1155) held by an address.
|
|
96
|
+
- `getTokenIdsForContractWithMetadata()`: Get NFT token IDs with metadata from a collection. Useful for building NFT card displays.
|
|
97
|
+
- `getNftMetadataForGivenTokenIDForContract()`: Get a single NFT metadata by token ID from a collection. Useful for building NFT card displays.
|
|
98
|
+
- `getNftTransactionsForContractTokenId()`: Get all transactions of an NFT token. Useful for building a transaction history table or price chart.
|
|
99
|
+
- `getTraitsForCollection()`: Used to fetch and render the traits of a collection as seen in rarity calculators.
|
|
100
|
+
- `getAttributesForTraitInCollection()`: Used to get the count of unique values for traits within an NFT collection.
|
|
101
|
+
- `getCollectionTraitsSummary()`: Used to calculate rarity scores for a collection based on its traits.
|
|
102
|
+
- `checkOwnershipInNft()`: Used to verify ownership of NFTs (including ERC-721 and ERC-1155) within a collection.
|
|
103
|
+
- `checkOwnershipInNftForSpecificTokenId()`: Used to verify ownership of a specific token (ERC-721 or ERC-1155) within a collection.
|
|
104
|
+
- `getNftExternalMetadataForContract()`: Get a single NFT with metadata by token ID from a collection. Useful for building NFT card displays.
|
|
105
|
+
|
|
106
|
+
### PricingService
|
|
107
|
+
|
|
108
|
+
The `PricingService` class contains the getTokenPrices() endpoint. Refer to the [getTokenPrices endpoint on our API docs](https://www.covalenthq.com/docs/api/pricing/get-historical-token-prices/).
|
|
109
|
+
|
|
110
|
+
- `getTokenPrices()`: Get historic prices of a token between date ranges. Supports native tokens.
|
|
111
|
+
|
|
112
|
+
### TransactionsService
|
|
113
|
+
|
|
114
|
+
The `TransactionsService` class contains the transactions endpoint. Listed below are the supported endpoints, also refer to our api docs under the Transactions section in our class A endpoints.
|
|
115
|
+
|
|
116
|
+
- `getRecentTransactionsForAddress()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
|
|
117
|
+
- `getTransaction()`: Fetch and render a single transaction including its decoded log events. Additionally return semantically decoded information for DEX trades, lending and NFT sales.
|
|
118
|
+
- `getTransactionsForBlock()`: Fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
|
|
119
|
+
- `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.
|
|
120
|
+
|
|
121
|
+
### XykService
|
|
122
|
+
|
|
123
|
+
The `XykService` class contains the Xy=k endpoints. Listed below are the supported endpoints, also refer to our api docs under the XY=K section in our class B endpoints.
|
|
124
|
+
|
|
125
|
+
- `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).
|
|
126
|
+
- `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.
|
|
127
|
+
- `getAddressExchangeBalances()`: Return balance of a wallet/contract address on a specific DEX.
|
|
128
|
+
- `getNetworkExchangeTokens()`: Get the balance of a wallet address in a DEX. Useful for finding out user balances locked up in DEX pools.
|
|
129
|
+
- `getSupportedDEXes()`: Get all the supported DEXs available for the xy=k endpoints, along with the swap fees and factory addresses.
|
|
130
|
+
- `getSingleNetworkExchangeToken()`: Get historical daily swap count for a single network exchange token.
|
|
131
|
+
- `getTransactionsForAccountAddress()`: Get all the DEX transactions of a wallet. Useful for building tables of DEX activity segmented by wallet.
|
|
132
|
+
- `getTransactionsForTokenAddress()`: Get all the transactions of a token within a particular DEX. Useful for getting a per-token view of DEX activity.
|
|
133
|
+
- `getTransactionsForExchange()`: Get all the transactions of a particular DEX liquidity pool. Useful for building a transactions history table for an individual pool.
|
|
134
|
+
- `getEcosystemChartData()`: Get a 7d and 30d time-series chart of DEX activity. Includes volume and swap count.
|
|
135
|
+
- `getHealthData()`: Ping the health of xy=k endpoints to get the synced block height per chain.
|
|
136
|
+
|
|
137
|
+
### How pagination works
|
|
138
|
+
|
|
139
|
+
The Covalent getRecentTransactionsForAddress() endpoint is currently the only endpoint that supports pagination which return 100 results per page. To get the next page, it uses a link url that is grabbed from the previous call. Here's an example of how to paginate through all recent transactions on the ethereum blockchain for the demo's ENS address:
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import { Client } from "@covalenthq/client-sdk";
|
|
143
|
+
|
|
144
|
+
const ApiServices = async () => {
|
|
145
|
+
const client = new Client("YOUR_API_KEY"); // Replace with your Covalent API key.
|
|
146
|
+
for await (const resp of client.TransactionsService.getRecentTransactionsForAddress("eth-mainnet", "demo.eth")) {
|
|
147
|
+
console.log("resp", resp);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Retry Mechanism
|
|
153
|
+
|
|
154
|
+
Each endpoint is equipped with an exponential backoff algorithm that exponentially extends the wait time between retries, making up to a `maximum of 5` retry attempts only.
|
|
155
|
+
|
|
156
|
+
## Documentation
|
|
157
|
+
|
|
158
|
+
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.
|
|
@@ -51,7 +51,7 @@ export declare class ApprovalService {
|
|
|
51
51
|
/**
|
|
52
52
|
*
|
|
53
53
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
54
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, or an `Unstoppable Domain` resolves automatically.
|
|
54
|
+
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
55
55
|
*
|
|
56
56
|
*/
|
|
57
57
|
getApprovals(chainName: "btc-mainnet" | "eth-mainnet" | "matic-mainnet" | "bsc-mainnet" | "avalanche-mainnet" | "fantom-mainnet" | "moonbeam-mainnet" | "moonbeam-moonriver" | "rsk-mainnet" | "arbitrum-mainnet" | "palm-mainnet" | "klaytn-mainnet" | "heco-mainnet" | "nervos-godwoken-mainnet" | "axie-mainnet" | "evmos-mainnet" | "astar-mainnet" | "iotex-mainnet" | "harmony-mainnet" | "cronos-mainnet" | "aurora-mainnet" | "emerald-paratime-mainnet" | "boba-mainnet" | "eth-goerli" | "matic-mumbai" | "avalanche-testnet" | "bsc-testnet" | "moonbeam-moonbase-alpha" | "rsk-testnet" | "arbitrum-goerli" | "fantom-testnet" | "palm-testnet" | "heco-testnet" | "nervos-godwoken-testnet" | "evmos-testnet" | "astar-shiden" | "iotex-testnet" | "harmony-testnet" | "aurora-testnet" | "scroll-l2-testnet" | "scroll-l1-testnet" | "covalent-internal-network-v1" | "defi-kingdoms-mainnet" | "swimmer-mainnet" | "boba-avalanche-mainnet" | "boba-bobabeam-mainnet" | "boba-bnb-mainnet" | "boba-rinkeby-testnet" | "boba-bobabase-testnet" | "boba-bnb-testnet" | "boba-avalanche-testnet" | "klaytn-testnet" | "gather-mainnet" | "gather-testnet" | "optimism-mainnet" | "skale-calypso" | "skale-mainnet" | "skale-razor" | "avalanche-dexalot-mainnet" | "skale-omnus" | "avalanche-dexalot-testnet" | "astar-shibuya" | "cronos-testnet" | "defi-kingdoms-testnet" | "metis-mainnet" | "metis-testnet" | "milkomeda-a1-mainnet" | "milkomeda-a1-devnet" | "milkomeda-c1-mainnet" | "milkomeda-c1-devnet" | "swimmer-testnet" | "solana-mainnet" | "skale-europa" | "meter-mainnet" | "meter-testnet" | "skale-exorde" | "boba-goerli" | "neon-testnet" | "skale-staging-uum" | "skale-staging-lcc" | "arbitrum-nova-mainnet" | "canto-mainnet" | "bittorrent-mainnet" | "bittorrent-testnet" | "flarenetworks-flare-mainnet" | "flarenetworks-flare-testnet" | "flarenetworks-canary-mainnet" | "flarenetworks-canary-testnet" | "kcc-mainnet" | "kcc-testnet" | "polygon-zkevm-testnet" | "linea-testnet" | "base-testnet" | "mantle-testnet" | "scroll-alpha-testnet" | "oasys-mainnet" | "oasys-testnet" | "findora-mainnet" | "findora-forge-testnet" | "sx-mainnet", walletAddress: string): Promise<Response<ApprovalsResponse>>;
|
package/dist/ApprovalService.js
CHANGED
|
@@ -9,12 +9,13 @@ class ApprovalService {
|
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
11
11
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
12
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, or an `Unstoppable Domain` resolves automatically.
|
|
12
|
+
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
13
13
|
*
|
|
14
14
|
*/
|
|
15
15
|
async getApprovals(chainName, walletAddress) {
|
|
16
|
-
let retryCount =
|
|
16
|
+
let retryCount = 1;
|
|
17
17
|
let success = false;
|
|
18
|
+
const maxRetries = 5;
|
|
18
19
|
while (!success) {
|
|
19
20
|
try {
|
|
20
21
|
const urlParams = new URLSearchParams();
|
|
@@ -25,9 +26,15 @@ class ApprovalService {
|
|
|
25
26
|
});
|
|
26
27
|
const data = await response.json();
|
|
27
28
|
if (data.error && data.error_code === 429) {
|
|
28
|
-
retryCount
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
if (retryCount < maxRetries) {
|
|
30
|
+
retryCount++;
|
|
31
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
32
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
success = true;
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
31
38
|
}
|
|
32
39
|
else {
|
|
33
40
|
success = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApprovalService.js","sourceRoot":"","sources":["../src/services/ApprovalService.ts"],"names":[],"mappings":";;;AAkDA,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,6BAA6B;
|
|
1
|
+
{"version":3,"file":"ApprovalService.js","sourceRoot":"","sources":["../src/services/ApprovalService.ts"],"names":[],"mappings":";;;AAkDA,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,6BAA6B;AAIvD,MAAa,eAAe;IACxB,YAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAClC,CAAC;IAGD;;;;;OAKG;IACI,KAAK,CAAC,YAAY,CAAC,SAAkjE,EAAE,aAAqB;QAC/lE,IAAI,UAAU,GAAG,CAAC,CAAC;QACnB,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,MAAM,UAAU,GAAG,CAAC,CAAC;QACrB,OAAO,CAAC,OAAO,EAAE;YACb,IAAI;gBACA,MAAM,SAAS,GAAG,IAAI,eAAe,EAAE,CAAC;gBAGxC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,iCAAiC,SAAS,cAAc,aAAa,KAAK,SAAS,EAAE,EAAE;oBAChH,OAAO,EAAE;wBACL,eAAe,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE;qBAC3C;iBACJ,CAAC,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACnC,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU,KAAK,GAAG,EAAE;oBACvC,IAAI,UAAU,GAAG,UAAU,EAAE;wBACzB,UAAU,EAAE,CAAC;wBACb,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,WAAW,CAAC,CAAC,gCAAgC;wBACvF,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;qBAChE;yBAAM;wBACH,OAAO,GAAG,IAAI,CAAC;wBACf,OAAO,IAAI,CAAC;qBACf;iBACJ;qBAAM;oBACH,OAAO,GAAG,IAAI,CAAC;oBACf,OAAO,IAAI,CAAC;iBACf;aACJ;YAAC,OAAO,KAAK,EAAE;gBACZ,OAAO,GAAG,IAAI,CAAC;gBACf,OAAO,KAAK,CAAC,OAAO,CAAC;aACxB;SACJ;IACL,CAAC;CAGJ;AA/CD,0CA+CC"}
|
|
@@ -146,7 +146,7 @@ export declare class BalancesService {
|
|
|
146
146
|
/**
|
|
147
147
|
*
|
|
148
148
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
149
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, or an `Unstoppable Domain` resolves automatically.
|
|
149
|
+
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
150
150
|
* @param {string} quoteCurrency - The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
151
151
|
* @param {boolean} nft - If `true`, NFTs will be included in the response.
|
|
152
152
|
* @param {boolean} noNftFetch - If `true`, only NFTs that have been cached will be included in the response. Helpful for faster response times.
|
|
@@ -158,7 +158,7 @@ export declare class BalancesService {
|
|
|
158
158
|
/**
|
|
159
159
|
*
|
|
160
160
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
161
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, or an `Unstoppable Domain` resolves automatically.
|
|
161
|
+
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
162
162
|
* @param {string} quoteCurrency - The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
163
163
|
* @param {number} days - The number of days to return data for. Defaults to 30 days.
|
|
164
164
|
*
|
|
@@ -167,7 +167,7 @@ export declare class BalancesService {
|
|
|
167
167
|
/**
|
|
168
168
|
*
|
|
169
169
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
170
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, or an `Unstoppable Domain` resolves automatically.
|
|
170
|
+
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
171
171
|
* @param {string} quoteCurrency - The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
172
172
|
* @param {string} contractAddress - The requested contract address.
|
|
173
173
|
* @param {number} startingBlock - The block height to start from, defaults to `0`.
|
|
@@ -178,7 +178,7 @@ export declare class BalancesService {
|
|
|
178
178
|
/**
|
|
179
179
|
*
|
|
180
180
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
181
|
-
* @param {string} tokenAddress - The requested address. Passing in an `ENS`, `RNS`, or an `Unstoppable Domain` resolves automatically.
|
|
181
|
+
* @param {string} tokenAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
182
182
|
* @param {number} blockHeight - Ending block to define a block range. Omitting this parameter defaults to the latest block height.
|
|
183
183
|
* @param {number} pageSize - Number of items per page. Note: Currently, only values of `100` and `1000` are supported. Omitting this parameter defaults to 100.
|
|
184
184
|
* @param {number} pageNumber - 0-indexed page number to begin pagination.
|
package/dist/BalancesService.js
CHANGED
|
@@ -9,7 +9,7 @@ class BalancesService {
|
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
11
11
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
12
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, or an `Unstoppable Domain` resolves automatically.
|
|
12
|
+
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
13
13
|
* @param {string} quoteCurrency - The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
14
14
|
* @param {boolean} nft - If `true`, NFTs will be included in the response.
|
|
15
15
|
* @param {boolean} noNftFetch - If `true`, only NFTs that have been cached will be included in the response. Helpful for faster response times.
|
|
@@ -18,8 +18,9 @@ class BalancesService {
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
async getTokenBalances(chainName, walletAddress, quoteCurrency, nft, noNftFetch, noSpam, noNftAssetMetadata) {
|
|
21
|
-
let retryCount =
|
|
21
|
+
let retryCount = 1;
|
|
22
22
|
let success = false;
|
|
23
|
+
const maxRetries = 5;
|
|
23
24
|
while (!success) {
|
|
24
25
|
try {
|
|
25
26
|
const urlParams = new URLSearchParams();
|
|
@@ -45,9 +46,15 @@ class BalancesService {
|
|
|
45
46
|
});
|
|
46
47
|
const data = await response.json();
|
|
47
48
|
if (data.error && data.error_code === 429) {
|
|
48
|
-
retryCount
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if (retryCount < maxRetries) {
|
|
50
|
+
retryCount++;
|
|
51
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
52
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
success = true;
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
51
58
|
}
|
|
52
59
|
else {
|
|
53
60
|
success = true;
|
|
@@ -63,14 +70,15 @@ class BalancesService {
|
|
|
63
70
|
/**
|
|
64
71
|
*
|
|
65
72
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
66
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, or an `Unstoppable Domain` resolves automatically.
|
|
73
|
+
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
67
74
|
* @param {string} quoteCurrency - The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
68
75
|
* @param {number} days - The number of days to return data for. Defaults to 30 days.
|
|
69
76
|
*
|
|
70
77
|
*/
|
|
71
78
|
async getAddressPortfolio(chainName, walletAddress, quoteCurrency, days) {
|
|
72
|
-
let retryCount =
|
|
79
|
+
let retryCount = 1;
|
|
73
80
|
let success = false;
|
|
81
|
+
const maxRetries = 5;
|
|
74
82
|
while (!success) {
|
|
75
83
|
try {
|
|
76
84
|
const urlParams = new URLSearchParams();
|
|
@@ -87,9 +95,15 @@ class BalancesService {
|
|
|
87
95
|
});
|
|
88
96
|
const data = await response.json();
|
|
89
97
|
if (data.error && data.error_code === 429) {
|
|
90
|
-
retryCount
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
if (retryCount < maxRetries) {
|
|
99
|
+
retryCount++;
|
|
100
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
101
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
success = true;
|
|
105
|
+
return data;
|
|
106
|
+
}
|
|
93
107
|
}
|
|
94
108
|
else {
|
|
95
109
|
success = true;
|
|
@@ -105,7 +119,7 @@ class BalancesService {
|
|
|
105
119
|
/**
|
|
106
120
|
*
|
|
107
121
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
108
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, or an `Unstoppable Domain` resolves automatically.
|
|
122
|
+
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
109
123
|
* @param {string} quoteCurrency - The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
110
124
|
* @param {string} contractAddress - The requested contract address.
|
|
111
125
|
* @param {number} startingBlock - The block height to start from, defaults to `0`.
|
|
@@ -113,8 +127,9 @@ class BalancesService {
|
|
|
113
127
|
*
|
|
114
128
|
*/
|
|
115
129
|
async getErc20Transfers(chainName, walletAddress, quoteCurrency, contractAddress, startingBlock, endingBlock) {
|
|
116
|
-
let retryCount =
|
|
130
|
+
let retryCount = 1;
|
|
117
131
|
let success = false;
|
|
132
|
+
const maxRetries = 5;
|
|
118
133
|
while (!success) {
|
|
119
134
|
try {
|
|
120
135
|
const urlParams = new URLSearchParams();
|
|
@@ -137,9 +152,15 @@ class BalancesService {
|
|
|
137
152
|
});
|
|
138
153
|
const data = await response.json();
|
|
139
154
|
if (data.error && data.error_code === 429) {
|
|
140
|
-
retryCount
|
|
141
|
-
|
|
142
|
-
|
|
155
|
+
if (retryCount < maxRetries) {
|
|
156
|
+
retryCount++;
|
|
157
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
158
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
success = true;
|
|
162
|
+
return data;
|
|
163
|
+
}
|
|
143
164
|
}
|
|
144
165
|
else {
|
|
145
166
|
success = true;
|
|
@@ -155,15 +176,16 @@ class BalancesService {
|
|
|
155
176
|
/**
|
|
156
177
|
*
|
|
157
178
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
158
|
-
* @param {string} tokenAddress - The requested address. Passing in an `ENS`, `RNS`, or an `Unstoppable Domain` resolves automatically.
|
|
179
|
+
* @param {string} tokenAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
159
180
|
* @param {number} blockHeight - Ending block to define a block range. Omitting this parameter defaults to the latest block height.
|
|
160
181
|
* @param {number} pageSize - Number of items per page. Note: Currently, only values of `100` and `1000` are supported. Omitting this parameter defaults to 100.
|
|
161
182
|
* @param {number} pageNumber - 0-indexed page number to begin pagination.
|
|
162
183
|
*
|
|
163
184
|
*/
|
|
164
185
|
async getTokenHoldersV2(chainName, tokenAddress, blockHeight, pageSize, pageNumber) {
|
|
165
|
-
let retryCount =
|
|
186
|
+
let retryCount = 1;
|
|
166
187
|
let success = false;
|
|
188
|
+
const maxRetries = 5;
|
|
167
189
|
while (!success) {
|
|
168
190
|
try {
|
|
169
191
|
const urlParams = new URLSearchParams();
|
|
@@ -183,9 +205,15 @@ class BalancesService {
|
|
|
183
205
|
});
|
|
184
206
|
const data = await response.json();
|
|
185
207
|
if (data.error && data.error_code === 429) {
|
|
186
|
-
retryCount
|
|
187
|
-
|
|
188
|
-
|
|
208
|
+
if (retryCount < maxRetries) {
|
|
209
|
+
retryCount++;
|
|
210
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
211
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
success = true;
|
|
215
|
+
return data;
|
|
216
|
+
}
|
|
189
217
|
}
|
|
190
218
|
else {
|
|
191
219
|
success = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BalancesService.js","sourceRoot":"","sources":["../src/services/BalancesService.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"BalancesService.js","sourceRoot":"","sources":["../src/services/BalancesService.ts"],"names":[],"mappings":";;;AAyJA,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,6BAA6B;AAIvD,MAAa,eAAe;IACxB,YAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAClC,CAAC;IAGD;;;;;;;;;;OAUG;IACI,KAAK,CAAC,gBAAgB,CAAC,SAAkjE,EAAE,aAAqB,EAAE,aAA6I,EAAE,GAAa,EAAE,UAAoB,EAAE,MAAgB,EAAE,kBAA4B;QACv0E,IAAI,UAAU,GAAG,CAAC,CAAC;QACnB,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,MAAM,UAAU,GAAG,CAAC,CAAC;QACrB,OAAO,CAAC,OAAO,EAAE;YACb,IAAI;gBACA,MAAM,SAAS,GAAG,IAAI,eAAe,EAAE,CAAC;gBAExC,IAAI,aAAa,KAAK,SAAS,EAAE;oBAC7B,SAAS,CAAC,MAAM,CAAC,gBAAgB,EAAE,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC;iBAChE;gBAED,IAAI,GAAG,KAAK,SAAS,EAAE;oBACnB,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;iBAC3C;gBAED,IAAI,UAAU,KAAK,SAAS,EAAE;oBAC1B,SAAS,CAAC,MAAM,CAAC,cAAc,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;iBAC3D;gBAED,IAAI,MAAM,KAAK,SAAS,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GD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,iCAAiC,SAAS,WAAW,YAAY,sBAAsB,SAAS,EAAE,EAAE;oBAC7H,OAAO,EAAE;wBACL,eAAe,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE;qBAC3C;iBACJ,CAAC,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACnC,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU,KAAK,GAAG,EAAE;oBACvC,IAAI,UAAU,GAAG,UAAU,EAAE;wBACzB,UAAU,EAAE,CAAC;wBACb,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,WAAW,CAAC,CAAC,gCAAgC;wBACvF,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;qBAChE;yBAAM;wBACH,OAAO,GAAG,IAAI,CAAC;wBACf,OAAO,IAAI,CAAC;qBACf;iBACJ;qBAAM;oBACH,OAAO,GAAG,IAAI,CAAC;oBACf,OAAO,IAAI,CAAC;iBACf;aACJ;YAAC,OAAO,KAAK,EAAE;gBACZ,OAAO,GAAG,IAAI,CAAC;gBACf,OAAO,KAAK,CAAC,OAAO,CAAC;aACxB;SACJ;IACL,CAAC;CAGJ;AAhPD,0CAgPC"}
|
package/dist/BaseService.d.ts
CHANGED
|
@@ -137,7 +137,7 @@ export declare class BaseService {
|
|
|
137
137
|
/**
|
|
138
138
|
*
|
|
139
139
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
140
|
-
* @param {string} contractAddress - The endpoint will return event logs emitted from this contract address. Passing in an `ENS`, `RNS`, or an `Unstoppable Domain` resolves automatically.
|
|
140
|
+
* @param {string} contractAddress - The endpoint will return event logs emitted from this contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
141
141
|
* @param {number} startingBlock - The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
142
142
|
* @param {string} endingBlock - The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
143
143
|
*
|
package/dist/BaseService.js
CHANGED
|
@@ -13,8 +13,9 @@ class BaseService {
|
|
|
13
13
|
*
|
|
14
14
|
*/
|
|
15
15
|
async getBlock(chainName, blockHeight) {
|
|
16
|
-
let retryCount =
|
|
16
|
+
let retryCount = 1;
|
|
17
17
|
let success = false;
|
|
18
|
+
const maxRetries = 5;
|
|
18
19
|
while (!success) {
|
|
19
20
|
try {
|
|
20
21
|
const urlParams = new URLSearchParams();
|
|
@@ -25,9 +26,15 @@ class BaseService {
|
|
|
25
26
|
});
|
|
26
27
|
const data = await response.json();
|
|
27
28
|
if (data.error && data.error_code === 429) {
|
|
28
|
-
retryCount
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
if (retryCount < maxRetries) {
|
|
30
|
+
retryCount++;
|
|
31
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
32
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
success = true;
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
31
38
|
}
|
|
32
39
|
else {
|
|
33
40
|
success = true;
|
|
@@ -48,8 +55,9 @@ class BaseService {
|
|
|
48
55
|
*
|
|
49
56
|
*/
|
|
50
57
|
async getBlockHeights(chainName, startDate, endDate) {
|
|
51
|
-
let retryCount =
|
|
58
|
+
let retryCount = 1;
|
|
52
59
|
let success = false;
|
|
60
|
+
const maxRetries = 5;
|
|
53
61
|
while (!success) {
|
|
54
62
|
try {
|
|
55
63
|
const urlParams = new URLSearchParams();
|
|
@@ -60,9 +68,15 @@ class BaseService {
|
|
|
60
68
|
});
|
|
61
69
|
const data = await response.json();
|
|
62
70
|
if (data.error && data.error_code === 429) {
|
|
63
|
-
retryCount
|
|
64
|
-
|
|
65
|
-
|
|
71
|
+
if (retryCount < maxRetries) {
|
|
72
|
+
retryCount++;
|
|
73
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
74
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
success = true;
|
|
78
|
+
return data;
|
|
79
|
+
}
|
|
66
80
|
}
|
|
67
81
|
else {
|
|
68
82
|
success = true;
|
|
@@ -78,14 +92,15 @@ class BaseService {
|
|
|
78
92
|
/**
|
|
79
93
|
*
|
|
80
94
|
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
81
|
-
* @param {string} contractAddress - The endpoint will return event logs emitted from this contract address. Passing in an `ENS`, `RNS`, or an `Unstoppable Domain` resolves automatically.
|
|
95
|
+
* @param {string} contractAddress - The endpoint will return event logs emitted from this contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
82
96
|
* @param {number} startingBlock - The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
83
97
|
* @param {string} endingBlock - The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
|
|
84
98
|
*
|
|
85
99
|
*/
|
|
86
100
|
async getLogEventsByAddress(chainName, contractAddress, startingBlock, endingBlock) {
|
|
87
|
-
let retryCount =
|
|
101
|
+
let retryCount = 1;
|
|
88
102
|
let success = false;
|
|
103
|
+
const maxRetries = 5;
|
|
89
104
|
while (!success) {
|
|
90
105
|
try {
|
|
91
106
|
const urlParams = new URLSearchParams();
|
|
@@ -102,9 +117,15 @@ class BaseService {
|
|
|
102
117
|
});
|
|
103
118
|
const data = await response.json();
|
|
104
119
|
if (data.error && data.error_code === 429) {
|
|
105
|
-
retryCount
|
|
106
|
-
|
|
107
|
-
|
|
120
|
+
if (retryCount < maxRetries) {
|
|
121
|
+
retryCount++;
|
|
122
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
123
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
success = true;
|
|
127
|
+
return data;
|
|
128
|
+
}
|
|
108
129
|
}
|
|
109
130
|
else {
|
|
110
131
|
success = true;
|
|
@@ -127,8 +148,9 @@ class BaseService {
|
|
|
127
148
|
*
|
|
128
149
|
*/
|
|
129
150
|
async getLogEventsByTopicHash(chainName, topicHash, startingBlock, endingBlock, secondaryTopics) {
|
|
130
|
-
let retryCount =
|
|
151
|
+
let retryCount = 1;
|
|
131
152
|
let success = false;
|
|
153
|
+
const maxRetries = 5;
|
|
132
154
|
while (!success) {
|
|
133
155
|
try {
|
|
134
156
|
const urlParams = new URLSearchParams();
|
|
@@ -148,9 +170,15 @@ class BaseService {
|
|
|
148
170
|
});
|
|
149
171
|
const data = await response.json();
|
|
150
172
|
if (data.error && data.error_code === 429) {
|
|
151
|
-
retryCount
|
|
152
|
-
|
|
153
|
-
|
|
173
|
+
if (retryCount < maxRetries) {
|
|
174
|
+
retryCount++;
|
|
175
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
176
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
success = true;
|
|
180
|
+
return data;
|
|
181
|
+
}
|
|
154
182
|
}
|
|
155
183
|
else {
|
|
156
184
|
success = true;
|
|
@@ -169,8 +197,9 @@ class BaseService {
|
|
|
169
197
|
*
|
|
170
198
|
*/
|
|
171
199
|
async getAllChains() {
|
|
172
|
-
let retryCount =
|
|
200
|
+
let retryCount = 1;
|
|
173
201
|
let success = false;
|
|
202
|
+
const maxRetries = 5;
|
|
174
203
|
while (!success) {
|
|
175
204
|
try {
|
|
176
205
|
const urlParams = new URLSearchParams();
|
|
@@ -181,9 +210,15 @@ class BaseService {
|
|
|
181
210
|
});
|
|
182
211
|
const data = await response.json();
|
|
183
212
|
if (data.error && data.error_code === 429) {
|
|
184
|
-
retryCount
|
|
185
|
-
|
|
186
|
-
|
|
213
|
+
if (retryCount < maxRetries) {
|
|
214
|
+
retryCount++;
|
|
215
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
216
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
success = true;
|
|
220
|
+
return data;
|
|
221
|
+
}
|
|
187
222
|
}
|
|
188
223
|
else {
|
|
189
224
|
success = true;
|
|
@@ -202,8 +237,9 @@ class BaseService {
|
|
|
202
237
|
*
|
|
203
238
|
*/
|
|
204
239
|
async getAllChainStatus() {
|
|
205
|
-
let retryCount =
|
|
240
|
+
let retryCount = 1;
|
|
206
241
|
let success = false;
|
|
242
|
+
const maxRetries = 5;
|
|
207
243
|
while (!success) {
|
|
208
244
|
try {
|
|
209
245
|
const urlParams = new URLSearchParams();
|
|
@@ -214,9 +250,15 @@ class BaseService {
|
|
|
214
250
|
});
|
|
215
251
|
const data = await response.json();
|
|
216
252
|
if (data.error && data.error_code === 429) {
|
|
217
|
-
retryCount
|
|
218
|
-
|
|
219
|
-
|
|
253
|
+
if (retryCount < maxRetries) {
|
|
254
|
+
retryCount++;
|
|
255
|
+
const delayMs = Math.pow(2, retryCount) * baseDelayMs; // Exponential delay calculation
|
|
256
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
success = true;
|
|
260
|
+
return data;
|
|
261
|
+
}
|
|
220
262
|
}
|
|
221
263
|
else {
|
|
222
264
|
success = true;
|