@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
@@ -1,1202 +0,0 @@
1
- import { userAgent } from "./CovalentClient";
2
- import { debugOutput, paginateEndpoint } from "../util/ApiHelpers";
3
- import { parseISO } from "date-fns";
4
- import { ExponentialBackoff } from "../util/backoff";
5
- import pLimit from "p-limit";
6
- import { ApiKeyValidator } from "../util/ApiKeyValidator";
7
- class BlockResponse {
8
- constructor(data) {
9
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
10
- this.chain_id = data.chain_id;
11
- this.chain_name = data.chain_name;
12
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new Block(itemData)) : null;
13
- }
14
- }
15
- class Block {
16
- constructor(data) {
17
- this.block_hash = data.block_hash;
18
- this.signed_at = data.signed_at && data.signed_at !== null ? parseISO(data.signed_at.toString()) : null;
19
- this.height = data.height;
20
- this.block_parent_hash = data.block_parent_hash;
21
- this.extra_data = data.extra_data;
22
- this.miner_address = data.miner_address;
23
- this.mining_cost = data.mining_cost;
24
- this.gas_used = data.gas_used;
25
- this.gas_limit = data.gas_limit;
26
- this.transactions_link = data.transactions_link;
27
- }
28
- }
29
- class ResolvedAddress {
30
- constructor(data) {
31
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
32
- this.chain_id = data.chain_id;
33
- this.chain_name = data.chain_name;
34
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new ResolvedAddressItem(itemData)) : null;
35
- }
36
- }
37
- class ResolvedAddressItem {
38
- constructor(data) {
39
- this.address = data.address;
40
- this.name = data.name;
41
- }
42
- }
43
- class BlockHeightsResponse {
44
- constructor(data) {
45
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
46
- this.chain_id = data.chain_id;
47
- this.chain_name = data.chain_name;
48
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new BlockHeights(itemData)) : null;
49
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
50
- }
51
- }
52
- class BlockHeights {
53
- constructor(data) {
54
- this.block_hash = data.block_hash;
55
- this.signed_at = data.signed_at && data.signed_at !== null ? parseISO(data.signed_at.toString()) : null;
56
- this.height = data.height;
57
- this.block_parent_hash = data.block_parent_hash;
58
- this.extra_data = data.extra_data;
59
- this.miner_address = data.miner_address;
60
- this.mining_cost = data.mining_cost;
61
- this.gas_used = data.gas_used;
62
- this.gas_limit = data.gas_limit;
63
- this.transactions_link = data.transactions_link;
64
- }
65
- }
66
- class Pagination {
67
- constructor(data) {
68
- this.has_more = data.has_more;
69
- this.page_number = data.page_number;
70
- this.page_size = data.page_size;
71
- this.total_count = data.total_count;
72
- }
73
- }
74
- class GetLogsResponse {
75
- constructor(data) {
76
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
77
- this.chain_id = data.chain_id;
78
- this.chain_name = data.chain_name;
79
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new GetLogsEvent(itemData)) : null;
80
- }
81
- }
82
- class GetLogsEvent {
83
- constructor(data) {
84
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
85
- this.block_height = data.block_height;
86
- this.block_hash = data.block_hash;
87
- this.tx_offset = data.tx_offset;
88
- this.log_offset = data.log_offset;
89
- this.tx_hash = data.tx_hash;
90
- this.raw_log_topics = data.raw_log_topics;
91
- this.sender_contract_decimals = data.sender_contract_decimals;
92
- this.sender_name = data.sender_name;
93
- this.sender_contract_ticker_symbol = data.sender_contract_ticker_symbol;
94
- this.sender_address = data.sender_address;
95
- this.sender_address_label = data.sender_address_label;
96
- this.supports_erc = data.supports_erc;
97
- this.sender_logo_url = data.sender_logo_url;
98
- this.sender_factory_address = data.sender_factory_address;
99
- this.raw_log_data = data.raw_log_data;
100
- this.decoded = data.decoded && data.decoded !== null ? new DecodedItem(data.decoded) : null;
101
- }
102
- }
103
- class DecodedItem {
104
- constructor(data) {
105
- this.name = data.name;
106
- this.signature = data.signature;
107
- this.params = data.params && data.params !== null ? data.params.map((itemData) => new Param(itemData)) : null;
108
- }
109
- }
110
- class Param {
111
- constructor(data) {
112
- this.name = data.name;
113
- this.type = data.type;
114
- this.indexed = data.indexed;
115
- this.decoded = data.decoded;
116
- this.value = data.value;
117
- }
118
- }
119
- class LogEventsByAddressResponse {
120
- constructor(data) {
121
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
122
- this.chain_id = data.chain_id;
123
- this.chain_name = data.chain_name;
124
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new LogEvent(itemData)) : null;
125
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
126
- }
127
- }
128
- class LogEvent {
129
- constructor(data) {
130
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
131
- this.block_height = data.block_height;
132
- this.tx_offset = data.tx_offset;
133
- this.log_offset = data.log_offset;
134
- this.tx_hash = data.tx_hash;
135
- this.raw_log_topics = data.raw_log_topics;
136
- this.sender_contract_decimals = data.sender_contract_decimals;
137
- this.sender_name = data.sender_name;
138
- this.sender_contract_ticker_symbol = data.sender_contract_ticker_symbol;
139
- this.sender_address = data.sender_address;
140
- this.sender_address_label = data.sender_address_label;
141
- this.sender_logo_url = data.sender_logo_url;
142
- this.supports_erc = data.supports_erc;
143
- this.sender_factory_address = data.sender_factory_address;
144
- this.raw_log_data = data.raw_log_data;
145
- this.decoded = data.decoded && data.decoded !== null ? new DecodedItem(data.decoded) : null;
146
- }
147
- }
148
- class LogEventsByTopicHashResponse {
149
- constructor(data) {
150
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
151
- this.chain_id = data.chain_id;
152
- this.chain_name = data.chain_name;
153
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new LogEvent(itemData)) : null;
154
- this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
155
- }
156
- }
157
- class AllChainsResponse {
158
- constructor(data) {
159
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
160
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new ChainItem(itemData)) : null;
161
- }
162
- }
163
- class ChainItem {
164
- constructor(data) {
165
- this.name = data.name;
166
- this.chain_id = data.chain_id;
167
- this.is_testnet = data.is_testnet;
168
- this.db_schema_name = data.db_schema_name;
169
- this.label = data.label;
170
- this.category_label = data.category_label;
171
- this.logo_url = data.logo_url;
172
- this.black_logo_url = data.black_logo_url;
173
- this.white_logo_url = data.white_logo_url;
174
- this.is_appchain = data.is_appchain;
175
- this.color_theme = data.color_theme && data.color_theme !== null ? new ColorTheme(data.color_theme) : null;
176
- this.appchain_of = data.appchain_of && data.appchain_of !== null ? new ChainItem(data.appchain_of) : null;
177
- }
178
- }
179
- class ColorTheme {
180
- constructor(data) {
181
- this.red = data.red;
182
- this.green = data.green;
183
- this.blue = data.blue;
184
- this.alpha = data.alpha;
185
- this.hex = data.hex;
186
- this.css_rgb = data.css_rgb;
187
- }
188
- }
189
- class AllChainsStatusResponse {
190
- constructor(data) {
191
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
192
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new ChainStatusItem(itemData)) : null;
193
- }
194
- }
195
- class ChainStatusItem {
196
- constructor(data) {
197
- this.name = data.name;
198
- this.chain_id = data.chain_id;
199
- this.is_testnet = data.is_testnet;
200
- this.logo_url = data.logo_url;
201
- this.black_logo_url = data.black_logo_url;
202
- this.white_logo_url = data.white_logo_url;
203
- this.is_appchain = data.is_appchain;
204
- this.synced_block_height = data.synced_block_height;
205
- this.synced_blocked_signed_at = data.synced_blocked_signed_at && data.synced_blocked_signed_at !== null ? parseISO(data.synced_blocked_signed_at.toString()) : null;
206
- this.has_data = data.has_data;
207
- }
208
- }
209
- class ChainActivityResponse {
210
- constructor(data) {
211
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
212
- this.address = data.address;
213
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new ChainActivityEvent(itemData)) : null;
214
- }
215
- }
216
- class ChainActivityEvent extends ChainItem {
217
- constructor(data) {
218
- super(data);
219
- this.last_seen_at = data.last_seen_at && data.last_seen_at !== null ? parseISO(data.last_seen_at.toString()) : null;
220
- }
221
- }
222
- class GasPricesResponse {
223
- constructor(data) {
224
- this.chain_id = data.chain_id;
225
- this.chain_name = data.chain_name;
226
- this.quote_currency = data.quote_currency;
227
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
228
- this.event_type = data.event_type;
229
- this.gas_quote_rate = data.gas_quote_rate;
230
- this.base_fee = data.base_fee && data.base_fee !== null ? BigInt(data.base_fee) : null;
231
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new PriceItem(itemData)) : null;
232
- }
233
- }
234
- class PriceItem {
235
- constructor(data) {
236
- this.gas_price = data.gas_price;
237
- this.gas_spent = data.gas_spent;
238
- this.gas_quote = data.gas_quote;
239
- this.total_gas_quote = data.total_gas_quote;
240
- this.pretty_total_gas_quote = data.pretty_total_gas_quote;
241
- this.interval = data.interval;
242
- this.other_fees = data.other_fees && data.other_fees !== null ? new OtherFees(data.other_fees) : null;
243
- }
244
- }
245
- class OtherFees {
246
- constructor(data) {
247
- this.l1_gas_quote = data.l1_gas_quote;
248
- }
249
- }
250
- /**
251
- * Class A - Base
252
- *
253
- */
254
- export class BaseService {
255
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
256
- this.apiKey = apiKey;
257
- this.debug = debug;
258
- this.threadCount = threadCount;
259
- this.is_key_valid = is_key_valid;
260
- this.enableRetry = enableRetry;
261
- this.source = source;
262
- this.LIMIT = pLimit(this.threadCount);
263
- }
264
- /**
265
- *
266
- * Commonly used to fetch and render a single block for a block explorer.
267
- *
268
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
269
- * @param {string} blockHeight - The block height or `latest` for the latest block available.
270
- *
271
- */
272
- async getBlock(chainName, blockHeight) {
273
- let success = false;
274
- let data;
275
- let response;
276
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
277
- while (!success) {
278
- try {
279
- const urlParams = new URLSearchParams();
280
- if (!this.is_key_valid) {
281
- return {
282
- data: null,
283
- error: true,
284
- error_code: 401,
285
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
286
- };
287
- }
288
- const url = `https://api.covalenthq.com/v1/${chainName}/block_v2/${blockHeight}/?${urlParams}`;
289
- let startTime;
290
- if (this.debug) {
291
- startTime = new Date();
292
- }
293
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_v2/${blockHeight}/?${urlParams}`, {
294
- headers: {
295
- "Authorization": `Bearer ${this.apiKey}`,
296
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
297
- }
298
- }));
299
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
300
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
301
- try {
302
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
303
- }
304
- catch (error) {
305
- success = true;
306
- return {
307
- data: null,
308
- error: true,
309
- error_code: response.status ?? 429,
310
- error_message: error.message
311
- };
312
- }
313
- }
314
- else {
315
- data = await response.json();
316
- }
317
- const dataClass = new BlockResponse(data.data);
318
- success = true;
319
- return {
320
- data: dataClass,
321
- error: data ? data.error : true,
322
- error_code: data ? data.error_code : response.status,
323
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
324
- };
325
- }
326
- catch (error) {
327
- success = true;
328
- return {
329
- data: null,
330
- error: true,
331
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
332
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
333
- };
334
- }
335
- }
336
- }
337
- /**
338
- *
339
- * Commonly used to resolve ENS, RNS and Unstoppable Domains addresses.
340
- *
341
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
342
- * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
343
- *
344
- */
345
- async getResolvedAddress(chainName, walletAddress) {
346
- let success = false;
347
- let data;
348
- let response;
349
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
350
- while (!success) {
351
- try {
352
- const urlParams = new URLSearchParams();
353
- if (!this.is_key_valid) {
354
- return {
355
- data: null,
356
- error: true,
357
- error_code: 401,
358
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
359
- };
360
- }
361
- const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/resolve_address/?${urlParams}`;
362
- let startTime;
363
- if (this.debug) {
364
- startTime = new Date();
365
- }
366
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/resolve_address/?${urlParams}`, {
367
- headers: {
368
- "Authorization": `Bearer ${this.apiKey}`,
369
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
370
- }
371
- }));
372
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
373
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
374
- try {
375
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
376
- }
377
- catch (error) {
378
- success = true;
379
- return {
380
- data: null,
381
- error: true,
382
- error_code: response.status ?? 429,
383
- error_message: error.message
384
- };
385
- }
386
- }
387
- else {
388
- data = await response.json();
389
- }
390
- const dataClass = new ResolvedAddress(data.data);
391
- success = true;
392
- return {
393
- data: dataClass,
394
- error: data ? data.error : true,
395
- error_code: data ? data.error_code : response.status,
396
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
397
- };
398
- }
399
- catch (error) {
400
- success = true;
401
- return {
402
- data: null,
403
- error: true,
404
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
405
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
406
- };
407
- }
408
- }
409
- }
410
- /**
411
- *
412
- * Commonly used to get all the block heights within a particular date range. Useful for rendering a display where you sort blocks by day.
413
- *
414
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
415
- * @param {string} startDate - The start date in YYYY-MM-DD format.
416
- * @param {string} endDate - The end date in YYYY-MM-DD format.
417
- * @param {GetBlockHeightsQueryParamOpts} queryParamOpts
418
- * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
419
- * - `pageNumber`: 0-indexed page number to begin pagination.
420
- *
421
- */
422
- async *getBlockHeights(chainName, startDate, endDate, queryParamOpts) {
423
- let success = false;
424
- let res;
425
- while (!success) {
426
- try {
427
- const urlParams = new URLSearchParams();
428
- if (!this.is_key_valid) {
429
- throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
430
- }
431
- if (queryParamOpts?.pageSize !== undefined) {
432
- urlParams.append("page-size", queryParamOpts?.pageSize.toString());
433
- }
434
- if (queryParamOpts?.pageNumber !== undefined) {
435
- urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
436
- }
437
- for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/`, this.apiKey, urlParams, Block, this.debug, this.threadCount, this.enableRetry, this.source)) {
438
- yield res;
439
- }
440
- success = true;
441
- }
442
- catch (error) {
443
- success = true;
444
- throw new Error(error.message);
445
- }
446
- }
447
- }
448
- /**
449
- *
450
- * Commonly used to get all the block heights within a particular date range. Useful for rendering a display where you sort blocks by day.
451
- *
452
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
453
- * @param {string} startDate - The start date in YYYY-MM-DD format.
454
- * @param {string} endDate - The end date in YYYY-MM-DD format.
455
- * @param {GetBlockHeightsQueryParamOpts} queryParamOpts
456
- * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
457
- * - `pageNumber`: 0-indexed page number to begin pagination.
458
- *
459
- */
460
- async getBlockHeightsByPage(chainName, startDate, endDate, queryParamOpts) {
461
- let success = false;
462
- let data;
463
- let response;
464
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
465
- while (!success) {
466
- try {
467
- const urlParams = new URLSearchParams();
468
- if (!this.is_key_valid) {
469
- return {
470
- data: null,
471
- error: true,
472
- error_code: 401,
473
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
474
- };
475
- }
476
- if (queryParamOpts?.pageSize !== undefined) {
477
- urlParams.append("page-size", queryParamOpts?.pageSize.toString());
478
- }
479
- if (queryParamOpts?.pageNumber !== undefined) {
480
- urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
481
- }
482
- const url = `https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/?${urlParams}`;
483
- let startTime;
484
- if (this.debug) {
485
- startTime = new Date();
486
- }
487
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/?${urlParams}`, {
488
- headers: {
489
- "Authorization": `Bearer ${this.apiKey}`,
490
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
491
- }
492
- }));
493
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
494
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
495
- try {
496
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
497
- }
498
- catch (error) {
499
- success = true;
500
- return {
501
- data: null,
502
- error: true,
503
- error_code: response.status ?? 429,
504
- error_message: error.message
505
- };
506
- }
507
- }
508
- else {
509
- data = await response.json();
510
- }
511
- const dataClass = new BlockHeightsResponse(data.data);
512
- success = true;
513
- return {
514
- data: dataClass,
515
- error: data ? data.error : true,
516
- error_code: data ? data.error_code : response.status,
517
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
518
- };
519
- }
520
- catch (error) {
521
- success = true;
522
- return {
523
- data: null,
524
- error: true,
525
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
526
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
527
- };
528
- }
529
- }
530
- }
531
- /**
532
- *
533
- * Commonly used to get all the event logs of the latest block, or for a range of blocks. Includes sender contract metadata as well as decoded logs.
534
- *
535
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
536
- * @param {GetLogsQueryParamOpts} queryParamOpts
537
- * - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
538
- * - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
539
- * - `address`: The address of the log events sender contract.
540
- * - `topics`: The topic hash(es) to retrieve logs with.
541
- * - `blockHash`: The block hash to retrieve logs for.
542
- * - `skipDecode`: Omit decoded log events.
543
- *
544
- */
545
- async getLogs(chainName, queryParamOpts) {
546
- let success = false;
547
- let data;
548
- let response;
549
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
550
- while (!success) {
551
- try {
552
- const urlParams = new URLSearchParams();
553
- if (!this.is_key_valid) {
554
- return {
555
- data: null,
556
- error: true,
557
- error_code: 401,
558
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
559
- };
560
- }
561
- if (queryParamOpts?.startingBlock !== undefined) {
562
- urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
563
- }
564
- if (queryParamOpts?.endingBlock !== undefined) {
565
- urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
566
- }
567
- if (queryParamOpts?.address !== undefined) {
568
- urlParams.append("address", queryParamOpts?.address.toString());
569
- }
570
- if (queryParamOpts?.topics !== undefined) {
571
- urlParams.append("topics", queryParamOpts?.topics.toString());
572
- }
573
- if (queryParamOpts?.blockHash !== undefined) {
574
- urlParams.append("block-hash", queryParamOpts?.blockHash.toString());
575
- }
576
- if (queryParamOpts?.skipDecode !== undefined) {
577
- urlParams.append("skip-decode", queryParamOpts?.skipDecode.toString());
578
- }
579
- const url = `https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`;
580
- let startTime;
581
- if (this.debug) {
582
- startTime = new Date();
583
- }
584
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`, {
585
- headers: {
586
- "Authorization": `Bearer ${this.apiKey}`,
587
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
588
- }
589
- }));
590
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
591
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
592
- try {
593
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
594
- }
595
- catch (error) {
596
- success = true;
597
- return {
598
- data: null,
599
- error: true,
600
- error_code: response.status ?? 429,
601
- error_message: error.message
602
- };
603
- }
604
- }
605
- else {
606
- data = await response.json();
607
- }
608
- const dataClass = new GetLogsResponse(data.data);
609
- success = true;
610
- return {
611
- data: dataClass,
612
- error: data ? data.error : true,
613
- error_code: data ? data.error_code : response.status,
614
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
615
- };
616
- }
617
- catch (error) {
618
- success = true;
619
- return {
620
- data: null,
621
- error: true,
622
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
623
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
624
- };
625
- }
626
- }
627
- }
628
- /**
629
- *
630
- * Commonly used to get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions.
631
- *
632
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
633
- * @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
634
- * @param {GetLogEventsByAddressQueryParamOpts} queryParamOpts
635
- * - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
636
- * - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
637
- * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
638
- * - `pageNumber`: 0-indexed page number to begin pagination.
639
- *
640
- */
641
- async *getLogEventsByAddress(chainName, contractAddress, queryParamOpts) {
642
- let success = false;
643
- let res;
644
- while (!success) {
645
- try {
646
- const urlParams = new URLSearchParams();
647
- if (!this.is_key_valid) {
648
- throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
649
- }
650
- if (queryParamOpts?.startingBlock !== undefined) {
651
- urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
652
- }
653
- if (queryParamOpts?.endingBlock !== undefined) {
654
- urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
655
- }
656
- if (queryParamOpts?.pageSize !== undefined) {
657
- urlParams.append("page-size", queryParamOpts?.pageSize.toString());
658
- }
659
- if (queryParamOpts?.pageNumber !== undefined) {
660
- urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
661
- }
662
- for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent, this.debug, this.threadCount, this.enableRetry, this.source)) {
663
- yield res;
664
- }
665
- success = true;
666
- }
667
- catch (error) {
668
- success = true;
669
- throw new Error(error.message);
670
- }
671
- }
672
- }
673
- /**
674
- *
675
- * Commonly used to get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions.
676
- *
677
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
678
- * @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
679
- * @param {GetLogEventsByAddressQueryParamOpts} queryParamOpts
680
- * - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
681
- * - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
682
- * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
683
- * - `pageNumber`: 0-indexed page number to begin pagination.
684
- *
685
- */
686
- async getLogEventsByAddressByPage(chainName, contractAddress, queryParamOpts) {
687
- let success = false;
688
- let data;
689
- let response;
690
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
691
- while (!success) {
692
- try {
693
- const urlParams = new URLSearchParams();
694
- if (!this.is_key_valid) {
695
- return {
696
- data: null,
697
- error: true,
698
- error_code: 401,
699
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
700
- };
701
- }
702
- if (queryParamOpts?.startingBlock !== undefined) {
703
- urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
704
- }
705
- if (queryParamOpts?.endingBlock !== undefined) {
706
- urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
707
- }
708
- if (queryParamOpts?.pageSize !== undefined) {
709
- urlParams.append("page-size", queryParamOpts?.pageSize.toString());
710
- }
711
- if (queryParamOpts?.pageNumber !== undefined) {
712
- urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
713
- }
714
- const url = `https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/?${urlParams}`;
715
- let startTime;
716
- if (this.debug) {
717
- startTime = new Date();
718
- }
719
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/?${urlParams}`, {
720
- headers: {
721
- "Authorization": `Bearer ${this.apiKey}`,
722
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
723
- }
724
- }));
725
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
726
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
727
- try {
728
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
729
- }
730
- catch (error) {
731
- success = true;
732
- return {
733
- data: null,
734
- error: true,
735
- error_code: response.status ?? 429,
736
- error_message: error.message
737
- };
738
- }
739
- }
740
- else {
741
- data = await response.json();
742
- }
743
- const dataClass = new LogEventsByAddressResponse(data.data);
744
- success = true;
745
- return {
746
- data: dataClass,
747
- error: data ? data.error : true,
748
- error_code: data ? data.error_code : response.status,
749
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
750
- };
751
- }
752
- catch (error) {
753
- success = true;
754
- return {
755
- data: null,
756
- error: true,
757
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
758
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
759
- };
760
- }
761
- }
762
- }
763
- /**
764
- *
765
- * Commonly used to 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.
766
- *
767
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
768
- * @param {string} topicHash - The endpoint will return event logs that contain this topic hash.
769
- * @param {GetLogEventsByTopicHashQueryParamOpts} queryParamOpts
770
- * - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
771
- * - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
772
- * - `secondaryTopics`: Additional topic hash(es) to filter on - padded & unpadded address fields are supported. Separate multiple topics with a comma.
773
- * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
774
- * - `pageNumber`: 0-indexed page number to begin pagination.
775
- *
776
- */
777
- async *getLogEventsByTopicHash(chainName, topicHash, queryParamOpts) {
778
- let success = false;
779
- let res;
780
- while (!success) {
781
- try {
782
- const urlParams = new URLSearchParams();
783
- if (!this.is_key_valid) {
784
- throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
785
- }
786
- if (queryParamOpts?.startingBlock !== undefined) {
787
- urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
788
- }
789
- if (queryParamOpts?.endingBlock !== undefined) {
790
- urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
791
- }
792
- if (queryParamOpts?.secondaryTopics !== undefined) {
793
- urlParams.append("secondary-topics", queryParamOpts?.secondaryTopics.toString());
794
- }
795
- if (queryParamOpts?.pageSize !== undefined) {
796
- urlParams.append("page-size", queryParamOpts?.pageSize.toString());
797
- }
798
- if (queryParamOpts?.pageNumber !== undefined) {
799
- urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
800
- }
801
- for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/`, this.apiKey, urlParams, LogEvent, this.debug, this.threadCount, this.enableRetry, this.source)) {
802
- yield res;
803
- }
804
- success = true;
805
- }
806
- catch (error) {
807
- success = true;
808
- throw new Error(error.message);
809
- }
810
- }
811
- }
812
- /**
813
- *
814
- * Commonly used to 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.
815
- *
816
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
817
- * @param {string} topicHash - The endpoint will return event logs that contain this topic hash.
818
- * @param {GetLogEventsByTopicHashQueryParamOpts} queryParamOpts
819
- * - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
820
- * - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
821
- * - `secondaryTopics`: Additional topic hash(es) to filter on - padded & unpadded address fields are supported. Separate multiple topics with a comma.
822
- * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
823
- * - `pageNumber`: 0-indexed page number to begin pagination.
824
- *
825
- */
826
- async getLogEventsByTopicHashByPage(chainName, topicHash, queryParamOpts) {
827
- let success = false;
828
- let data;
829
- let response;
830
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
831
- while (!success) {
832
- try {
833
- const urlParams = new URLSearchParams();
834
- if (!this.is_key_valid) {
835
- return {
836
- data: null,
837
- error: true,
838
- error_code: 401,
839
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
840
- };
841
- }
842
- if (queryParamOpts?.startingBlock !== undefined) {
843
- urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
844
- }
845
- if (queryParamOpts?.endingBlock !== undefined) {
846
- urlParams.append("ending-block", queryParamOpts?.endingBlock.toString());
847
- }
848
- if (queryParamOpts?.secondaryTopics !== undefined) {
849
- urlParams.append("secondary-topics", queryParamOpts?.secondaryTopics.toString());
850
- }
851
- if (queryParamOpts?.pageSize !== undefined) {
852
- urlParams.append("page-size", queryParamOpts?.pageSize.toString());
853
- }
854
- if (queryParamOpts?.pageNumber !== undefined) {
855
- urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
856
- }
857
- const url = `https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/?${urlParams}`;
858
- let startTime;
859
- if (this.debug) {
860
- startTime = new Date();
861
- }
862
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/?${urlParams}`, {
863
- headers: {
864
- "Authorization": `Bearer ${this.apiKey}`,
865
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
866
- }
867
- }));
868
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
869
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
870
- try {
871
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
872
- }
873
- catch (error) {
874
- success = true;
875
- return {
876
- data: null,
877
- error: true,
878
- error_code: response.status ?? 429,
879
- error_message: error.message
880
- };
881
- }
882
- }
883
- else {
884
- data = await response.json();
885
- }
886
- const dataClass = new LogEventsByTopicHashResponse(data.data);
887
- success = true;
888
- return {
889
- data: dataClass,
890
- error: data ? data.error : true,
891
- error_code: data ? data.error_code : response.status,
892
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
893
- };
894
- }
895
- catch (error) {
896
- success = true;
897
- return {
898
- data: null,
899
- error: true,
900
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
901
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
902
- };
903
- }
904
- }
905
- }
906
- /**
907
- *
908
- * Commonly used to build internal dashboards for all supported chains on Covalent.
909
- *
910
- *
911
- */
912
- async getAllChains() {
913
- let success = false;
914
- let data;
915
- let response;
916
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
917
- while (!success) {
918
- try {
919
- const urlParams = new URLSearchParams();
920
- if (!this.is_key_valid) {
921
- return {
922
- data: null,
923
- error: true,
924
- error_code: 401,
925
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
926
- };
927
- }
928
- let startTime;
929
- if (this.debug) {
930
- startTime = new Date();
931
- }
932
- const url = `https://api.covalenthq.com/v1/chains/?${urlParams}`;
933
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/chains/?${urlParams}`, {
934
- headers: {
935
- "Authorization": `Bearer ${this.apiKey}`,
936
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
937
- }
938
- }));
939
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
940
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
941
- try {
942
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
943
- }
944
- catch (error) {
945
- success = true;
946
- return {
947
- data: null,
948
- error: true,
949
- error_code: response.status ?? 429,
950
- error_message: error.message
951
- };
952
- }
953
- }
954
- else {
955
- data = await response.json();
956
- }
957
- const dataClass = new AllChainsResponse(data.data);
958
- success = true;
959
- return {
960
- data: dataClass,
961
- error: data ? data.error : true,
962
- error_code: data ? data.error_code : response.status,
963
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
964
- };
965
- }
966
- catch (error) {
967
- success = true;
968
- return {
969
- data: null,
970
- error: true,
971
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
972
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
973
- };
974
- }
975
- }
976
- }
977
- /**
978
- *
979
- * Commonly used to build internal status dashboards of all supported chains.
980
- *
981
- *
982
- */
983
- async getAllChainStatus() {
984
- let success = false;
985
- let data;
986
- let response;
987
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
988
- while (!success) {
989
- try {
990
- const urlParams = new URLSearchParams();
991
- if (!this.is_key_valid) {
992
- return {
993
- data: null,
994
- error: true,
995
- error_code: 401,
996
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
997
- };
998
- }
999
- const url = `https://api.covalenthq.com/v1/chains/status/?${urlParams}`;
1000
- let startTime;
1001
- if (this.debug) {
1002
- startTime = new Date();
1003
- }
1004
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/chains/status/?${urlParams}`, {
1005
- headers: {
1006
- "Authorization": `Bearer ${this.apiKey}`,
1007
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1008
- }
1009
- }));
1010
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1011
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1012
- try {
1013
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1014
- }
1015
- catch (error) {
1016
- success = true;
1017
- return {
1018
- data: null,
1019
- error: true,
1020
- error_code: response.status ?? 429,
1021
- error_message: error.message
1022
- };
1023
- }
1024
- }
1025
- else {
1026
- data = await response.json();
1027
- }
1028
- const dataClass = new AllChainsStatusResponse(data.data);
1029
- success = true;
1030
- return {
1031
- data: dataClass,
1032
- error: data ? data.error : true,
1033
- error_code: data ? data.error_code : response.status,
1034
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1035
- };
1036
- }
1037
- catch (error) {
1038
- success = true;
1039
- return {
1040
- data: null,
1041
- error: true,
1042
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1043
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1044
- };
1045
- }
1046
- }
1047
- }
1048
- /**
1049
- *
1050
- * Commonly used to locate chains which an address is active on with a single API call.
1051
- *
1052
- * @param {string} walletAddress - The requested wallet address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1053
- * @param {GetAddressActivityQueryParamOpts} queryParamOpts
1054
- * - `testnets`: Set to true to include testnets with activity in the response. By default, it's set to `false` and only returns mainnet activity.
1055
- *
1056
- */
1057
- async getAddressActivity(walletAddress, queryParamOpts) {
1058
- let success = false;
1059
- let data;
1060
- let response;
1061
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1062
- while (!success) {
1063
- try {
1064
- const urlParams = new URLSearchParams();
1065
- if (!this.is_key_valid) {
1066
- return {
1067
- data: null,
1068
- error: true,
1069
- error_code: 401,
1070
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1071
- };
1072
- }
1073
- if (queryParamOpts?.testnets !== undefined) {
1074
- urlParams.append("testnets", queryParamOpts?.testnets.toString());
1075
- }
1076
- const url = `https://api.covalenthq.com/v1/address/${walletAddress}/activity/?${urlParams}`;
1077
- let startTime;
1078
- if (this.debug) {
1079
- startTime = new Date();
1080
- }
1081
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/address/${walletAddress}/activity/?${urlParams}`, {
1082
- headers: {
1083
- "Authorization": `Bearer ${this.apiKey}`,
1084
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1085
- }
1086
- }));
1087
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1088
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1089
- try {
1090
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1091
- }
1092
- catch (error) {
1093
- success = true;
1094
- return {
1095
- data: null,
1096
- error: true,
1097
- error_code: response.status ?? 429,
1098
- error_message: error.message
1099
- };
1100
- }
1101
- }
1102
- else {
1103
- data = await response.json();
1104
- }
1105
- const dataClass = new ChainActivityResponse(data.data);
1106
- success = true;
1107
- return {
1108
- data: dataClass,
1109
- error: data ? data.error : true,
1110
- error_code: data ? data.error_code : response.status,
1111
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1112
- };
1113
- }
1114
- catch (error) {
1115
- success = true;
1116
- return {
1117
- data: null,
1118
- error: true,
1119
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1120
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1121
- };
1122
- }
1123
- }
1124
- }
1125
- /**
1126
- *
1127
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1128
- * @param {string} eventType - The desired event type to retrieve gas prices for. Supports `erc20` transfer events, `uniswapv3` swap events and `nativetokens` transfers.
1129
- * @param {GetGasPricesQueryParamOpts} queryParamOpts
1130
- * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1131
- *
1132
- */
1133
- async getGasPrices(chainName, eventType, queryParamOpts) {
1134
- let success = false;
1135
- let data;
1136
- let response;
1137
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1138
- while (!success) {
1139
- try {
1140
- const urlParams = new URLSearchParams();
1141
- if (!this.is_key_valid) {
1142
- return {
1143
- data: null,
1144
- error: true,
1145
- error_code: 401,
1146
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1147
- };
1148
- }
1149
- if (queryParamOpts?.quoteCurrency !== undefined) {
1150
- urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1151
- }
1152
- const url = `https://api.covalenthq.com/v1/${chainName}/event/${eventType}/gas_prices/?${urlParams}`;
1153
- let startTime;
1154
- if (this.debug) {
1155
- startTime = new Date();
1156
- }
1157
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/event/${eventType}/gas_prices/?${urlParams}`, {
1158
- headers: {
1159
- "Authorization": `Bearer ${this.apiKey}`,
1160
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1161
- }
1162
- }));
1163
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1164
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1165
- try {
1166
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1167
- }
1168
- catch (error) {
1169
- success = true;
1170
- return {
1171
- data: null,
1172
- error: true,
1173
- error_code: response.status ?? 429,
1174
- error_message: error.message
1175
- };
1176
- }
1177
- }
1178
- else {
1179
- data = await response.json();
1180
- }
1181
- const dataClass = new GasPricesResponse(data.data);
1182
- success = true;
1183
- return {
1184
- data: dataClass,
1185
- error: data ? data.error : true,
1186
- error_code: data ? data.error_code : response.status,
1187
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1188
- };
1189
- }
1190
- catch (error) {
1191
- success = true;
1192
- return {
1193
- data: null,
1194
- error: true,
1195
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1196
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1197
- };
1198
- }
1199
- }
1200
- }
1201
- }
1202
- //# sourceMappingURL=BaseService.js.map