@covalenthq/client-sdk 1.0.1 → 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,1687 +0,0 @@
1
- import { userAgent } from "./CovalentClient";
2
- import { debugOutput } 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 TransactionResponse {
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 Transaction(itemData)) : null;
13
- }
14
- }
15
- class Transaction {
16
- constructor(data) {
17
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
18
- this.block_height = data.block_height;
19
- this.block_hash = data.block_hash;
20
- this.tx_hash = data.tx_hash;
21
- this.tx_offset = data.tx_offset;
22
- this.successful = data.successful;
23
- this.from_address = data.from_address;
24
- this.miner_address = data.miner_address;
25
- this.from_address_label = data.from_address_label;
26
- this.to_address = data.to_address;
27
- this.to_address_label = data.to_address_label;
28
- this.value = data.value && data.value !== null ? BigInt(data.value) : null;
29
- this.value_quote = data.value_quote;
30
- this.pretty_value_quote = data.pretty_value_quote;
31
- this.gas_offered = data.gas_offered;
32
- this.gas_spent = data.gas_spent;
33
- this.gas_price = data.gas_price;
34
- this.fees_paid = data.fees_paid && data.fees_paid !== null ? BigInt(data.fees_paid) : null;
35
- this.gas_quote = data.gas_quote;
36
- this.pretty_gas_quote = data.pretty_gas_quote;
37
- this.gas_quote_rate = data.gas_quote_rate;
38
- this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
39
- this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
40
- this.dex_details = data.dex_details && data.dex_details !== null ? data.dex_details.map((itemData) => new DexReport(itemData)) : null;
41
- this.nft_sale_details = data.nft_sale_details && data.nft_sale_details !== null ? data.nft_sale_details.map((itemData) => new NftSalesReport(itemData)) : null;
42
- this.lending_details = data.lending_details && data.lending_details !== null ? data.lending_details.map((itemData) => new LendingReport(itemData)) : null;
43
- this.log_events = data.log_events && data.log_events !== null ? data.log_events.map((itemData) => new LogEvent(itemData)) : null;
44
- this.safe_details = data.safe_details && data.safe_details !== null ? data.safe_details.map((itemData) => new SafeDetails(itemData)) : null;
45
- }
46
- }
47
- class ContractMetadata {
48
- constructor(data) {
49
- this.contract_decimals = data.contract_decimals;
50
- this.contract_name = data.contract_name;
51
- this.contract_ticker_symbol = data.contract_ticker_symbol;
52
- this.contract_address = data.contract_address;
53
- this.supports_erc = data.supports_erc;
54
- this.logo_url = data.logo_url;
55
- }
56
- }
57
- class Explorer {
58
- constructor(data) {
59
- this.label = data.label;
60
- this.url = data.url;
61
- }
62
- }
63
- class DexReport {
64
- constructor(data) {
65
- this.log_offset = data.log_offset;
66
- this.protocol_name = data.protocol_name;
67
- this.protocol_address = data.protocol_address;
68
- this.protocol_logo_url = data.protocol_logo_url;
69
- this.aggregator_name = data.aggregator_name;
70
- this.aggregator_address = data.aggregator_address;
71
- this.version = data.version;
72
- this.fork_version = data.fork_version;
73
- this.fork = data.fork;
74
- this.event = data.event;
75
- this.pair_address = data.pair_address;
76
- this.pair_lp_fee_bps = data.pair_lp_fee_bps;
77
- this.lp_token_address = data.lp_token_address;
78
- this.lp_token_ticker = data.lp_token_ticker;
79
- this.lp_token_num_decimals = data.lp_token_num_decimals;
80
- this.lp_token_name = data.lp_token_name;
81
- this.lp_token_value = data.lp_token_value;
82
- this.exchange_rate_usd = data.exchange_rate_usd;
83
- this.token_0_address = data.token_0_address;
84
- this.token_0_ticker = data.token_0_ticker;
85
- this.token_0_num_decimals = data.token_0_num_decimals;
86
- this.token_0_name = data.token_0_name;
87
- this.token_1_address = data.token_1_address;
88
- this.token_1_ticker = data.token_1_ticker;
89
- this.token_1_num_decimals = data.token_1_num_decimals;
90
- this.token_1_name = data.token_1_name;
91
- this.token_0_amount = data.token_0_amount;
92
- this.token_0_quote_rate = data.token_0_quote_rate;
93
- this.token_0_usd_quote = data.token_0_usd_quote;
94
- this.pretty_token_0_usd_quote = data.pretty_token_0_usd_quote;
95
- this.token_0_logo_url = data.token_0_logo_url;
96
- this.token_1_amount = data.token_1_amount;
97
- this.token_1_quote_rate = data.token_1_quote_rate;
98
- this.token_1_usd_quote = data.token_1_usd_quote;
99
- this.pretty_token_1_usd_quote = data.pretty_token_1_usd_quote;
100
- this.token_1_logo_url = data.token_1_logo_url;
101
- this.sender = data.sender;
102
- this.recipient = data.recipient;
103
- }
104
- }
105
- class NftSalesReport {
106
- constructor(data) {
107
- this.log_offset = data.log_offset;
108
- this.topic0 = data.topic0;
109
- this.protocol_contract_address = data.protocol_contract_address;
110
- this.protocol_name = data.protocol_name;
111
- this.protocol_logo_url = data.protocol_logo_url;
112
- this.to = data.to;
113
- this.from = data.from;
114
- this.maker = data.maker;
115
- this.taker = data.taker;
116
- this.token_id = data.token_id;
117
- this.collection_address = data.collection_address;
118
- this.collection_name = data.collection_name;
119
- this.token_address = data.token_address;
120
- this.token_name = data.token_name;
121
- this.ticker_symbol = data.ticker_symbol;
122
- this.num_decimals = data.num_decimals;
123
- this.contract_quote_rate = data.contract_quote_rate;
124
- this.nft_token_price = data.nft_token_price;
125
- this.nft_token_price_usd = data.nft_token_price_usd;
126
- this.pretty_nft_token_price_usd = data.pretty_nft_token_price_usd;
127
- this.nft_token_price_native = data.nft_token_price_native;
128
- this.pretty_nft_token_price_native = data.pretty_nft_token_price_native;
129
- this.token_count = data.token_count;
130
- this.num_token_ids_sold_per_sale = data.num_token_ids_sold_per_sale;
131
- this.num_token_ids_sold_per_tx = data.num_token_ids_sold_per_tx;
132
- this.num_collections_sold_per_sale = data.num_collections_sold_per_sale;
133
- this.num_collections_sold_per_tx = data.num_collections_sold_per_tx;
134
- this.trade_type = data.trade_type;
135
- this.trade_group_type = data.trade_group_type;
136
- }
137
- }
138
- class LendingReport {
139
- constructor(data) {
140
- this.log_offset = data.log_offset;
141
- this.protocol_name = data.protocol_name;
142
- this.protocol_address = data.protocol_address;
143
- this.protocol_logo_url = data.protocol_logo_url;
144
- this.version = data.version;
145
- this.fork = data.fork;
146
- this.fork_version = data.fork_version;
147
- this.event = data.event;
148
- this.lp_token_name = data.lp_token_name;
149
- this.lp_decimals = data.lp_decimals;
150
- this.lp_ticker_symbol = data.lp_ticker_symbol;
151
- this.lp_token_address = data.lp_token_address;
152
- this.lp_token_amount = data.lp_token_amount;
153
- this.lp_token_price = data.lp_token_price;
154
- this.exchange_rate = data.exchange_rate;
155
- this.exchange_rate_usd = data.exchange_rate_usd;
156
- this.token_name_in = data.token_name_in;
157
- this.token_decimal_in = data.token_decimal_in;
158
- this.token_address_in = data.token_address_in;
159
- this.token_ticker_in = data.token_ticker_in;
160
- this.token_logo_in = data.token_logo_in;
161
- this.token_amount_in = data.token_amount_in;
162
- this.amount_in_usd = data.amount_in_usd;
163
- this.pretty_amount_in_usd = data.pretty_amount_in_usd;
164
- this.token_name_out = data.token_name_out;
165
- this.token_decimals_out = data.token_decimals_out;
166
- this.token_address_out = data.token_address_out;
167
- this.token_ticker_out = data.token_ticker_out;
168
- this.token_logo_out = data.token_logo_out;
169
- this.token_amount_out = data.token_amount_out;
170
- this.amount_out_usd = data.amount_out_usd;
171
- this.pretty_amount_out_usd = data.pretty_amount_out_usd;
172
- this.borrow_rate_mode = data.borrow_rate_mode;
173
- this.borrow_rate = data.borrow_rate;
174
- this.on_behalf_of = data.on_behalf_of;
175
- this.liquidator = data.liquidator;
176
- this.user = data.user;
177
- }
178
- }
179
- class LogEvent {
180
- constructor(data) {
181
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
182
- this.block_height = data.block_height;
183
- this.tx_offset = data.tx_offset;
184
- this.log_offset = data.log_offset;
185
- this.tx_hash = data.tx_hash;
186
- this.raw_log_topics = data.raw_log_topics;
187
- this.sender_contract_decimals = data.sender_contract_decimals;
188
- this.sender_name = data.sender_name;
189
- this.sender_contract_ticker_symbol = data.sender_contract_ticker_symbol;
190
- this.sender_address = data.sender_address;
191
- this.sender_address_label = data.sender_address_label;
192
- this.sender_logo_url = data.sender_logo_url;
193
- this.supports_erc = data.supports_erc;
194
- this.sender_factory_address = data.sender_factory_address;
195
- this.raw_log_data = data.raw_log_data;
196
- this.decoded = data.decoded && data.decoded !== null ? new DecodedItem(data.decoded) : null;
197
- }
198
- }
199
- class SafeDetails {
200
- constructor(data) {
201
- this.owner_address = data.owner_address;
202
- this.signature = data.signature;
203
- this.signature_type = data.signature_type;
204
- }
205
- }
206
- class DecodedItem {
207
- constructor(data) {
208
- this.name = data.name;
209
- this.signature = data.signature;
210
- this.params = data.params && data.params !== null ? data.params.map((itemData) => new Param(itemData)) : null;
211
- }
212
- }
213
- class Param {
214
- constructor(data) {
215
- this.name = data.name;
216
- this.type = data.type;
217
- this.indexed = data.indexed;
218
- this.decoded = data.decoded;
219
- this.value = data.value;
220
- }
221
- }
222
- class RecentTransactionsResponse {
223
- constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
224
- this._debug = _debug;
225
- this._apiKey = _apiKey;
226
- this._threadCount = _threadCount;
227
- this._urlParams = _urlParams;
228
- this._enableRetry = _enableRetry;
229
- this._source = _source;
230
- this.address = data.address;
231
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
232
- this.quote_currency = data.quote_currency;
233
- this.chain_id = data.chain_id;
234
- this.chain_name = data.chain_name;
235
- this.current_page = data.current_page;
236
- this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
237
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
238
- }
239
- async prev() {
240
- let success = false;
241
- let data;
242
- let response;
243
- const backoff = new ExponentialBackoff(this._apiKey, this._debug);
244
- const LIMIT = pLimit(this._threadCount);
245
- while (!success) {
246
- try {
247
- let startTime;
248
- if (this._debug) {
249
- startTime = new Date();
250
- }
251
- if (this.links.prev === null) {
252
- success = true;
253
- return {
254
- data: null,
255
- error: true,
256
- error_code: 400,
257
- error_message: "Invalid URL: URL link cannot be null"
258
- };
259
- }
260
- const url = `${this.links.prev}?${this._urlParams}`;
261
- response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
262
- headers: {
263
- "Authorization": `Bearer ${this._apiKey}`,
264
- "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
265
- }
266
- }));
267
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
268
- if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
269
- try {
270
- data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
271
- }
272
- catch (error) {
273
- success = true;
274
- return {
275
- data: null,
276
- error: true,
277
- error_code: response.status ?? 429,
278
- error_message: error.message
279
- };
280
- }
281
- }
282
- else {
283
- data = await response.json();
284
- }
285
- const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
286
- success = true;
287
- return {
288
- data: dataClass,
289
- error: data ? data.error : true,
290
- error_code: data ? data.error_code : response.status,
291
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
292
- };
293
- }
294
- catch (error) {
295
- success = true;
296
- return {
297
- data: null,
298
- error: true,
299
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
300
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
301
- };
302
- }
303
- }
304
- }
305
- async next() {
306
- let success = false;
307
- let data;
308
- let response;
309
- const backoff = new ExponentialBackoff(this._apiKey, this._debug);
310
- const LIMIT = pLimit(this._threadCount);
311
- while (!success) {
312
- try {
313
- let startTime;
314
- if (this._debug) {
315
- startTime = new Date();
316
- }
317
- if (this.links.next === null) {
318
- success = true;
319
- return {
320
- data: null,
321
- error: true,
322
- error_code: 400,
323
- error_message: "Invalid URL: URL link cannot be null"
324
- };
325
- }
326
- const url = `${this.links.next}?${this._urlParams}`;
327
- response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
328
- headers: {
329
- "Authorization": `Bearer ${this._apiKey}`,
330
- "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
331
- }
332
- }));
333
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
334
- if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
335
- try {
336
- data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
337
- }
338
- catch (error) {
339
- success = true;
340
- return {
341
- data: null,
342
- error: true,
343
- error_code: response.status ?? 429,
344
- error_message: error.message
345
- };
346
- }
347
- }
348
- else {
349
- data = await response.json();
350
- }
351
- const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
352
- success = true;
353
- return {
354
- data: dataClass,
355
- error: data ? data.error : true,
356
- error_code: data ? data.error_code : response.status,
357
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
358
- };
359
- }
360
- catch (error) {
361
- success = true;
362
- return {
363
- data: null,
364
- error: true,
365
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
366
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
367
- };
368
- }
369
- }
370
- }
371
- }
372
- class PaginationLinks {
373
- constructor(data) {
374
- this.prev = data.prev;
375
- this.next = data.next;
376
- }
377
- }
378
- class TransactionsBlockPageResponse {
379
- constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
380
- this._debug = _debug;
381
- this._apiKey = _apiKey;
382
- this._threadCount = _threadCount;
383
- this._urlParams = _urlParams;
384
- this._enableRetry = _enableRetry;
385
- this._source = _source;
386
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
387
- this.chain_id = data.chain_id;
388
- this.chain_name = data.chain_name;
389
- this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
390
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
391
- }
392
- async prev() {
393
- let success = false;
394
- let data;
395
- let response;
396
- const backoff = new ExponentialBackoff(this._apiKey, this._debug);
397
- const LIMIT = pLimit(this._threadCount);
398
- while (!success) {
399
- try {
400
- let startTime;
401
- if (this._debug) {
402
- startTime = new Date();
403
- }
404
- if (this.links.prev === null) {
405
- success = true;
406
- return {
407
- data: null,
408
- error: true,
409
- error_code: 400,
410
- error_message: "Invalid URL: URL link cannot be null"
411
- };
412
- }
413
- const url = `${this.links.prev}?${this._urlParams}`;
414
- response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
415
- headers: {
416
- "Authorization": `Bearer ${this._apiKey}`,
417
- "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
418
- }
419
- }));
420
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
421
- if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
422
- try {
423
- data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
424
- }
425
- catch (error) {
426
- success = true;
427
- return {
428
- data: null,
429
- error: true,
430
- error_code: response.status ?? 429,
431
- error_message: error.message
432
- };
433
- }
434
- }
435
- else {
436
- data = await response.json();
437
- }
438
- const dataClass = new TransactionsBlockPageResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
439
- success = true;
440
- return {
441
- data: dataClass,
442
- error: data ? data.error : true,
443
- error_code: data ? data.error_code : response.status,
444
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
445
- };
446
- }
447
- catch (error) {
448
- success = true;
449
- return {
450
- data: null,
451
- error: true,
452
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
453
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
454
- };
455
- }
456
- }
457
- }
458
- async next() {
459
- let success = false;
460
- let data;
461
- let response;
462
- const backoff = new ExponentialBackoff(this._apiKey, this._debug);
463
- const LIMIT = pLimit(this._threadCount);
464
- while (!success) {
465
- try {
466
- let startTime;
467
- if (this._debug) {
468
- startTime = new Date();
469
- }
470
- if (this.links.next === null) {
471
- success = true;
472
- return {
473
- data: null,
474
- error: true,
475
- error_code: 400,
476
- error_message: "Invalid URL: URL link cannot be null"
477
- };
478
- }
479
- const url = `${this.links.next}?${this._urlParams}`;
480
- response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
481
- headers: {
482
- "Authorization": `Bearer ${this._apiKey}`,
483
- "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
484
- }
485
- }));
486
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
487
- if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
488
- try {
489
- data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
490
- }
491
- catch (error) {
492
- success = true;
493
- return {
494
- data: null,
495
- error: true,
496
- error_code: response.status ?? 429,
497
- error_message: error.message
498
- };
499
- }
500
- }
501
- else {
502
- data = await response.json();
503
- }
504
- const dataClass = new TransactionsBlockPageResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
505
- success = true;
506
- return {
507
- data: dataClass,
508
- error: data ? data.error : true,
509
- error_code: data ? data.error_code : response.status,
510
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
511
- };
512
- }
513
- catch (error) {
514
- success = true;
515
- return {
516
- data: null,
517
- error: true,
518
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
519
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
520
- };
521
- }
522
- }
523
- }
524
- }
525
- class TransactionsBlockResponse {
526
- constructor(data) {
527
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
528
- this.chain_id = data.chain_id;
529
- this.chain_name = data.chain_name;
530
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
531
- }
532
- }
533
- class TransactionsSummaryResponse {
534
- constructor(data) {
535
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
536
- this.address = data.address;
537
- this.chain_id = data.chain_id;
538
- this.chain_name = data.chain_name;
539
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new TransactionsSummary(itemData)) : null;
540
- }
541
- }
542
- class GasSummary {
543
- constructor(data) {
544
- this.total_sent_count = data.total_sent_count;
545
- this.total_fees_paid = data.total_fees_paid && data.total_fees_paid !== null ? BigInt(data.total_fees_paid) : null;
546
- this.total_gas_quote = data.total_gas_quote;
547
- this.pretty_total_gas_quote = data.pretty_total_gas_quote;
548
- this.average_gas_quote_per_tx = data.average_gas_quote_per_tx;
549
- this.pretty_average_gas_quote_per_tx = data.pretty_average_gas_quote_per_tx;
550
- this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
551
- }
552
- }
553
- class TransactionsSummary {
554
- constructor(data) {
555
- this.total_count = data.total_count;
556
- this.earliest_transaction = data.earliest_transaction && data.earliest_transaction !== null ? new TransactionSummary(data.earliest_transaction) : null;
557
- this.latest_transaction = data.latest_transaction && data.latest_transaction !== null ? new TransactionSummary(data.latest_transaction) : null;
558
- this.gas_summary = data.gas_summary && data.gas_summary !== null ? new GasSummary(data.gas_summary) : null;
559
- }
560
- }
561
- class TransactionSummary {
562
- constructor(data) {
563
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
564
- this.tx_hash = data.tx_hash;
565
- this.tx_detail_link = data.tx_detail_link;
566
- }
567
- }
568
- class TransactionsResponse {
569
- constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
570
- this._debug = _debug;
571
- this._apiKey = _apiKey;
572
- this._threadCount = _threadCount;
573
- this._urlParams = _urlParams;
574
- this._enableRetry = _enableRetry;
575
- this._source = _source;
576
- this.address = data.address;
577
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
578
- this.quote_currency = data.quote_currency;
579
- this.chain_id = data.chain_id;
580
- this.chain_name = data.chain_name;
581
- this.current_page = data.current_page;
582
- this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
583
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
584
- }
585
- async prev() {
586
- let success = false;
587
- let data;
588
- let response;
589
- const backoff = new ExponentialBackoff(this._apiKey, this._debug);
590
- const LIMIT = pLimit(this._threadCount);
591
- while (!success) {
592
- try {
593
- let startTime;
594
- if (this._debug) {
595
- startTime = new Date();
596
- }
597
- if (this.links.prev === null) {
598
- success = true;
599
- return {
600
- data: null,
601
- error: true,
602
- error_code: 400,
603
- error_message: "Invalid URL: URL link cannot be null"
604
- };
605
- }
606
- const url = `${this.links.prev}?${this._urlParams}`;
607
- response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
608
- headers: {
609
- "Authorization": `Bearer ${this._apiKey}`,
610
- "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
611
- }
612
- }));
613
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
614
- if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
615
- try {
616
- data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
617
- }
618
- catch (error) {
619
- success = true;
620
- return {
621
- data: null,
622
- error: true,
623
- error_code: response.status ?? 429,
624
- error_message: error.message
625
- };
626
- }
627
- }
628
- else {
629
- data = await response.json();
630
- }
631
- const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
632
- success = true;
633
- return {
634
- data: dataClass,
635
- error: data ? data.error : true,
636
- error_code: data ? data.error_code : response.status,
637
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
638
- };
639
- }
640
- catch (error) {
641
- success = true;
642
- return {
643
- data: null,
644
- error: true,
645
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
646
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
647
- };
648
- }
649
- }
650
- }
651
- async next() {
652
- let success = false;
653
- let data;
654
- let response;
655
- const backoff = new ExponentialBackoff(this._apiKey, this._debug);
656
- const LIMIT = pLimit(this._threadCount);
657
- while (!success) {
658
- try {
659
- let startTime;
660
- if (this._debug) {
661
- startTime = new Date();
662
- }
663
- if (this.links.next === null) {
664
- success = true;
665
- return {
666
- data: null,
667
- error: true,
668
- error_code: 400,
669
- error_message: "Invalid URL: URL link cannot be null"
670
- };
671
- }
672
- const url = `${this.links.next}?${this._urlParams}`;
673
- response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
674
- headers: {
675
- "Authorization": `Bearer ${this._apiKey}`,
676
- "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
677
- }
678
- }));
679
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
680
- if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
681
- try {
682
- data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
683
- }
684
- catch (error) {
685
- success = true;
686
- return {
687
- data: null,
688
- error: true,
689
- error_code: response.status ?? 429,
690
- error_message: error.message
691
- };
692
- }
693
- }
694
- else {
695
- data = await response.json();
696
- }
697
- const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
698
- success = true;
699
- return {
700
- data: dataClass,
701
- error: data ? data.error : true,
702
- error_code: data ? data.error_code : response.status,
703
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
704
- };
705
- }
706
- catch (error) {
707
- success = true;
708
- return {
709
- data: null,
710
- error: true,
711
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
712
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
713
- };
714
- }
715
- }
716
- }
717
- }
718
- class TransactionsTimeBucketResponse {
719
- constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry, _source) {
720
- this._debug = _debug;
721
- this._apiKey = _apiKey;
722
- this._threadCount = _threadCount;
723
- this._urlParams = _urlParams;
724
- this._enableRetry = _enableRetry;
725
- this._source = _source;
726
- this.address = data.address;
727
- this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
728
- this.quote_currency = data.quote_currency;
729
- this.chain_id = data.chain_id;
730
- this.chain_name = data.chain_name;
731
- this.complete = data.complete;
732
- this.current_bucket = data.current_bucket;
733
- this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
734
- this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
735
- }
736
- async prev() {
737
- let success = false;
738
- let data;
739
- let response;
740
- const backoff = new ExponentialBackoff(this._apiKey, this._debug);
741
- const LIMIT = pLimit(this._threadCount);
742
- while (!success) {
743
- try {
744
- let startTime;
745
- if (this._debug) {
746
- startTime = new Date();
747
- }
748
- if (this.links.prev === null) {
749
- success = true;
750
- return {
751
- data: null,
752
- error: true,
753
- error_code: 400,
754
- error_message: "Invalid URL: URL link cannot be null"
755
- };
756
- }
757
- const url = `${this.links.prev}?${this._urlParams}`;
758
- response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
759
- headers: {
760
- "Authorization": `Bearer ${this._apiKey}`,
761
- "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
762
- }
763
- }));
764
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
765
- if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
766
- try {
767
- data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
768
- }
769
- catch (error) {
770
- success = true;
771
- return {
772
- data: null,
773
- error: true,
774
- error_code: response.status ?? 429,
775
- error_message: error.message
776
- };
777
- }
778
- }
779
- else {
780
- data = await response.json();
781
- }
782
- const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
783
- success = true;
784
- return {
785
- data: dataClass,
786
- error: data ? data.error : true,
787
- error_code: data ? data.error_code : response.status,
788
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
789
- };
790
- }
791
- catch (error) {
792
- success = true;
793
- return {
794
- data: null,
795
- error: true,
796
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
797
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
798
- };
799
- }
800
- }
801
- }
802
- async next() {
803
- let success = false;
804
- let data;
805
- let response;
806
- const backoff = new ExponentialBackoff(this._apiKey, this._debug);
807
- const LIMIT = pLimit(this._threadCount);
808
- while (!success) {
809
- try {
810
- let startTime;
811
- if (this._debug) {
812
- startTime = new Date();
813
- }
814
- if (this.links.next === null) {
815
- success = true;
816
- return {
817
- data: null,
818
- error: true,
819
- error_code: 400,
820
- error_message: "Invalid URL: URL link cannot be null"
821
- };
822
- }
823
- const url = `${this.links.next}?${this._urlParams}`;
824
- response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
825
- headers: {
826
- "Authorization": `Bearer ${this._apiKey}`,
827
- "X-Requested-With": this._source ? this._source + " " + "(" + userAgent + ")" : userAgent
828
- }
829
- }));
830
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
831
- if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
832
- try {
833
- data = await LIMIT(() => backoff.backOff(response ? response.url : url, this._source));
834
- }
835
- catch (error) {
836
- success = true;
837
- return {
838
- data: null,
839
- error: true,
840
- error_code: response.status ?? 429,
841
- error_message: error.message
842
- };
843
- }
844
- }
845
- else {
846
- data = await response.json();
847
- }
848
- const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry, this._source);
849
- success = true;
850
- return {
851
- data: dataClass,
852
- error: data ? data.error : true,
853
- error_code: data ? data.error_code : response.status,
854
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
855
- };
856
- }
857
- catch (error) {
858
- success = true;
859
- return {
860
- data: null,
861
- error: true,
862
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
863
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
864
- };
865
- }
866
- }
867
- }
868
- }
869
- /**
870
- * Transactions APIs
871
- *
872
- */
873
- async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, enableRetry, source) {
874
- let hasNext = true;
875
- let response;
876
- let data;
877
- const backoff = new ExponentialBackoff(apiKey, debug);
878
- const LIMIT = pLimit(threadCount);
879
- while (hasNext) {
880
- try {
881
- let startTime;
882
- if (debug) {
883
- startTime = new Date();
884
- }
885
- response = await LIMIT(() => fetch(`${url}?${urlsParams}`, {
886
- headers: {
887
- "Authorization": `Bearer ${apiKey}`,
888
- "X-Requested-With": source ? source + " " + "(" + userAgent + ")" : userAgent
889
- }
890
- }));
891
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
892
- if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
893
- try {
894
- data = await LIMIT(() => backoff.backOff(response ? response.url : `${url}?${urlsParams}`, this.source));
895
- }
896
- catch (error) {
897
- hasNext = false;
898
- throw new Error(`An error occurred ${response ? response.status : 429}: ${error.message}`);
899
- }
900
- }
901
- else {
902
- data = await response.json();
903
- }
904
- for (const tx of data.data.items) {
905
- const dataClass = new Transaction(tx);
906
- yield dataClass;
907
- }
908
- backoff.setNumAttempts(1);
909
- if (!data.error) {
910
- if ((data.data !== null) && data.data.links.prev === null) {
911
- hasNext = false;
912
- }
913
- url = data.data !== null ? data.data.links.prev : "";
914
- }
915
- else {
916
- hasNext = false;
917
- }
918
- }
919
- catch (error) {
920
- hasNext = false;
921
- if (error.message.includes("An error occurred 429")) {
922
- throw new Error(error.message);
923
- }
924
- throw new Error(`An error occurred ${data ? data.error_code : response ? response.status : "Unknown Error Code"}: ${data ? data.error_message : response && response.status === 500 ? "Internal server error" : "Unknown Error"}`);
925
- }
926
- }
927
- }
928
- export class TransactionService {
929
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
930
- this.apiKey = apiKey;
931
- this.debug = debug;
932
- this.threadCount = threadCount;
933
- this.is_key_valid = is_key_valid;
934
- this.enableRetry = enableRetry;
935
- this.source = source;
936
- this.LIMIT = pLimit(this.threadCount);
937
- }
938
- /**
939
- *
940
- * Commonly used to fetch and render a single transaction including its decoded log events. Additionally return semantically decoded information for DEX trades, lending and NFT sales.
941
- *
942
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
943
- * @param {string} txHash - The transaction hash.
944
- * @param {GetTransactionQueryParamOpts} queryParamOpts
945
- * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
946
- * - `noLogs`: Omit log events.
947
- * - `withDex`: Decoded DEX details including protocol (e.g. Uniswap), event (e.g 'add_liquidity') and tokens involved with historical prices. Additional 0.05 credits charged if data available.
948
- * - `withNftSales`: Decoded NFT sales details including marketplace (e.g. Opensea) and cached media links. Additional 0.05 credits charged if data available.
949
- * - `withLending`: Decoded lending details including protocol (e.g. Aave), event (e.g. 'deposit') and tokens involved with prices. Additional 0.05 credits charged if data available.
950
- * - `withSafe`: Include safe details.
951
- *
952
- */
953
- async getTransaction(chainName, txHash, queryParamOpts) {
954
- let success = false;
955
- let data;
956
- let response;
957
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
958
- while (!success) {
959
- try {
960
- const urlParams = new URLSearchParams();
961
- if (!this.is_key_valid) {
962
- return {
963
- data: null,
964
- error: true,
965
- error_code: 401,
966
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
967
- };
968
- }
969
- if (queryParamOpts?.quoteCurrency !== undefined) {
970
- urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
971
- }
972
- if (queryParamOpts?.noLogs !== undefined) {
973
- urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
974
- }
975
- if (queryParamOpts?.withDex !== undefined) {
976
- urlParams.append("with-dex", queryParamOpts?.withDex.toString());
977
- }
978
- if (queryParamOpts?.withNftSales !== undefined) {
979
- urlParams.append("with-nft-sales", queryParamOpts?.withNftSales.toString());
980
- }
981
- if (queryParamOpts?.withLending !== undefined) {
982
- urlParams.append("with-lending", queryParamOpts?.withLending.toString());
983
- }
984
- if (queryParamOpts?.withSafe !== undefined) {
985
- urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
986
- }
987
- let startTime;
988
- if (this.debug) {
989
- startTime = new Date();
990
- }
991
- const url = `https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`;
992
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`, {
993
- headers: {
994
- "Authorization": `Bearer ${this.apiKey}`,
995
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
996
- }
997
- }));
998
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
999
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1000
- try {
1001
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1002
- }
1003
- catch (error) {
1004
- success = true;
1005
- return {
1006
- data: null,
1007
- error: true,
1008
- error_code: response.status ?? 429,
1009
- error_message: error.message
1010
- };
1011
- }
1012
- }
1013
- else {
1014
- data = await response.json();
1015
- }
1016
- const dataClass = new TransactionResponse(data.data);
1017
- success = true;
1018
- return {
1019
- data: dataClass,
1020
- error: data ? data.error : true,
1021
- error_code: data ? data.error_code : response.status,
1022
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1023
- };
1024
- }
1025
- catch (error) {
1026
- success = true;
1027
- return {
1028
- data: null,
1029
- error: true,
1030
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1031
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1032
- };
1033
- }
1034
- }
1035
- }
1036
- /**
1037
- *
1038
- * Commonly used to fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
1039
- *
1040
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1041
- * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1042
- * @param {GetAllTransactionsForAddressQueryParamOpts} queryParamOpts
1043
- * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1044
- * - `noLogs`: Omit log events.
1045
- * - `blockSignedAtAsc`: Sort the transactions in ascending chronological order. By default, it's set to `false` and returns transactions in descending chronological order.
1046
- * - `withSafe`: Include safe details.
1047
- *
1048
- */
1049
- async *getAllTransactionsForAddress(chainName, walletAddress, queryParamOpts) {
1050
- let success = false;
1051
- let tx;
1052
- while (!success) {
1053
- try {
1054
- const urlParams = new URLSearchParams();
1055
- if (!this.is_key_valid) {
1056
- throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
1057
- }
1058
- if (queryParamOpts?.quoteCurrency !== undefined) {
1059
- urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1060
- }
1061
- if (queryParamOpts?.noLogs !== undefined) {
1062
- urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
1063
- }
1064
- if (queryParamOpts?.blockSignedAtAsc !== undefined) {
1065
- urlParams.append("block-signed-at-asc", queryParamOpts?.blockSignedAtAsc.toString());
1066
- }
1067
- if (queryParamOpts?.withSafe !== undefined) {
1068
- urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
1069
- }
1070
- for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount, this.enableRetry, this.source)) {
1071
- yield tx;
1072
- }
1073
- success = true;
1074
- }
1075
- catch (error) {
1076
- success = true;
1077
- throw new Error(error.message);
1078
- }
1079
- }
1080
- }
1081
- /**
1082
- *
1083
- * Commonly used to fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
1084
- *
1085
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1086
- * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1087
- * @param {GetAllTransactionsForAddressQueryParamOpts} queryParamOpts
1088
- * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1089
- * - `noLogs`: Omit log events.
1090
- * - `blockSignedAtAsc`: Sort the transactions in ascending chronological order. By default, it's set to `false` and returns transactions in descending chronological order.
1091
- * - `withSafe`: Include safe details.
1092
- *
1093
- */
1094
- async getAllTransactionsForAddressByPage(chainName, walletAddress, queryParamOpts) {
1095
- let success = false;
1096
- let data;
1097
- let response;
1098
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1099
- while (!success) {
1100
- try {
1101
- const urlParams = new URLSearchParams();
1102
- if (!this.is_key_valid) {
1103
- return {
1104
- data: null,
1105
- error: true,
1106
- error_code: 401,
1107
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1108
- };
1109
- }
1110
- if (queryParamOpts?.quoteCurrency !== undefined) {
1111
- urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1112
- }
1113
- if (queryParamOpts?.noLogs !== undefined) {
1114
- urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
1115
- }
1116
- if (queryParamOpts?.blockSignedAtAsc !== undefined) {
1117
- urlParams.append("block-signed-at-asc", queryParamOpts?.blockSignedAtAsc.toString());
1118
- }
1119
- if (queryParamOpts?.withSafe !== undefined) {
1120
- urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
1121
- }
1122
- let startTime;
1123
- if (this.debug) {
1124
- startTime = new Date();
1125
- }
1126
- const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`;
1127
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`, {
1128
- headers: {
1129
- "Authorization": `Bearer ${this.apiKey}`,
1130
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1131
- }
1132
- }));
1133
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1134
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1135
- try {
1136
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1137
- }
1138
- catch (error) {
1139
- success = true;
1140
- return {
1141
- data: null,
1142
- error: true,
1143
- error_code: response.status ?? 429,
1144
- error_message: error.message
1145
- };
1146
- }
1147
- }
1148
- else {
1149
- data = await response.json();
1150
- }
1151
- const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
1152
- success = true;
1153
- return {
1154
- data: dataClass,
1155
- error: data ? data.error : true,
1156
- error_code: data ? data.error_code : response.status,
1157
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1158
- };
1159
- }
1160
- catch (error) {
1161
- success = true;
1162
- return {
1163
- data: null,
1164
- error: true,
1165
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1166
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1167
- };
1168
- }
1169
- }
1170
- }
1171
- /**
1172
- *
1173
- * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
1174
- *
1175
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1176
- * @param {number} blockHeight - The requested block height.
1177
- * @param {GetTransactionsForBlockQueryParamOpts} queryParamOpts
1178
- * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1179
- * - `noLogs`: Omit log events.
1180
- * - `withSafe`: Include safe details.
1181
- *
1182
- */
1183
- async getTransactionsForBlock(chainName, blockHeight, queryParamOpts) {
1184
- let success = false;
1185
- let data;
1186
- let response;
1187
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1188
- while (!success) {
1189
- try {
1190
- const urlParams = new URLSearchParams();
1191
- if (!this.is_key_valid) {
1192
- return {
1193
- data: null,
1194
- error: true,
1195
- error_code: 401,
1196
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1197
- };
1198
- }
1199
- if (queryParamOpts?.quoteCurrency !== undefined) {
1200
- urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1201
- }
1202
- if (queryParamOpts?.noLogs !== undefined) {
1203
- urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
1204
- }
1205
- if (queryParamOpts?.withSafe !== undefined) {
1206
- urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
1207
- }
1208
- let startTime;
1209
- if (this.debug) {
1210
- startTime = new Date();
1211
- }
1212
- const url = `https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`;
1213
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`, {
1214
- headers: {
1215
- "Authorization": `Bearer ${this.apiKey}`,
1216
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1217
- }
1218
- }));
1219
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1220
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1221
- try {
1222
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1223
- }
1224
- catch (error) {
1225
- success = true;
1226
- return {
1227
- data: null,
1228
- error: true,
1229
- error_code: response.status ?? 429,
1230
- error_message: error.message
1231
- };
1232
- }
1233
- }
1234
- else {
1235
- data = await response.json();
1236
- }
1237
- const dataClass = new TransactionsBlockResponse(data.data);
1238
- success = true;
1239
- return {
1240
- data: dataClass,
1241
- error: data ? data.error : true,
1242
- error_code: data ? data.error_code : response.status,
1243
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1244
- };
1245
- }
1246
- catch (error) {
1247
- success = true;
1248
- return {
1249
- data: null,
1250
- error: true,
1251
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1252
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1253
- };
1254
- }
1255
- }
1256
- }
1257
- /**
1258
- *
1259
- * Commonly used to 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.
1260
- *
1261
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1262
- * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1263
- * @param {GetTransactionSummaryQueryParamOpts} queryParamOpts
1264
- * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1265
- * - `withGas`: Include gas summary details. Additional charge of 1 credit when true. Response times may be impacted for wallets with millions of transactions.
1266
- *
1267
- */
1268
- async getTransactionSummary(chainName, walletAddress, queryParamOpts) {
1269
- let success = false;
1270
- let data;
1271
- let response;
1272
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1273
- while (!success) {
1274
- try {
1275
- const urlParams = new URLSearchParams();
1276
- if (!this.is_key_valid) {
1277
- return {
1278
- data: null,
1279
- error: true,
1280
- error_code: 401,
1281
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1282
- };
1283
- }
1284
- if (queryParamOpts?.quoteCurrency !== undefined) {
1285
- urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1286
- }
1287
- if (queryParamOpts?.withGas !== undefined) {
1288
- urlParams.append("with-gas", queryParamOpts?.withGas.toString());
1289
- }
1290
- let startTime;
1291
- if (this.debug) {
1292
- startTime = new Date();
1293
- }
1294
- const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`;
1295
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`, {
1296
- headers: {
1297
- "Authorization": `Bearer ${this.apiKey}`,
1298
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1299
- }
1300
- }));
1301
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1302
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1303
- try {
1304
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1305
- }
1306
- catch (error) {
1307
- success = true;
1308
- return {
1309
- data: null,
1310
- error: true,
1311
- error_code: response.status ?? 429,
1312
- error_message: error.message
1313
- };
1314
- }
1315
- }
1316
- else {
1317
- data = await response.json();
1318
- }
1319
- const dataClass = new TransactionsSummaryResponse(data.data);
1320
- success = true;
1321
- return {
1322
- data: dataClass,
1323
- error: data ? data.error : true,
1324
- error_code: data ? data.error_code : response.status,
1325
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1326
- };
1327
- }
1328
- catch (error) {
1329
- success = true;
1330
- return {
1331
- data: null,
1332
- error: true,
1333
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1334
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1335
- };
1336
- }
1337
- }
1338
- }
1339
- /**
1340
- *
1341
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1342
- * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1343
- * @param {number} page - The requested page, 0-indexed.
1344
- * @param {GetTransactionsForAddressV3QueryParamOpts} queryParamOpts
1345
- * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1346
- * - `noLogs`: Omit log events.
1347
- * - `blockSignedAtAsc`: Sort the transactions in ascending chronological order. By default, it's set to `false` and returns transactions in descending chronological order.
1348
- * - `withSafe`: Include safe details.
1349
- *
1350
- */
1351
- async getTransactionsForAddressV3(chainName, walletAddress, page, queryParamOpts) {
1352
- let success = false;
1353
- let data;
1354
- let response;
1355
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1356
- while (!success) {
1357
- try {
1358
- const urlParams = new URLSearchParams();
1359
- if (!this.is_key_valid) {
1360
- return {
1361
- data: null,
1362
- error: true,
1363
- error_code: 401,
1364
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1365
- };
1366
- }
1367
- if (queryParamOpts?.quoteCurrency !== undefined) {
1368
- urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1369
- }
1370
- if (queryParamOpts?.noLogs !== undefined) {
1371
- urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
1372
- }
1373
- if (queryParamOpts?.blockSignedAtAsc !== undefined) {
1374
- urlParams.append("block-signed-at-asc", queryParamOpts?.blockSignedAtAsc.toString());
1375
- }
1376
- if (queryParamOpts?.withSafe !== undefined) {
1377
- urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
1378
- }
1379
- let startTime;
1380
- if (this.debug) {
1381
- startTime = new Date();
1382
- }
1383
- const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`;
1384
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`, {
1385
- headers: {
1386
- "Authorization": `Bearer ${this.apiKey}`,
1387
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1388
- }
1389
- }));
1390
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1391
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1392
- try {
1393
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1394
- }
1395
- catch (error) {
1396
- success = true;
1397
- return {
1398
- data: null,
1399
- error: true,
1400
- error_code: response.status ?? 429,
1401
- error_message: error.message
1402
- };
1403
- }
1404
- }
1405
- else {
1406
- data = await response.json();
1407
- }
1408
- const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
1409
- success = true;
1410
- return {
1411
- data: dataClass,
1412
- error: data ? data.error : true,
1413
- error_code: data ? data.error_code : response.status,
1414
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1415
- };
1416
- }
1417
- catch (error) {
1418
- success = true;
1419
- return {
1420
- data: null,
1421
- error: true,
1422
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1423
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1424
- };
1425
- }
1426
- }
1427
- }
1428
- /**
1429
- *
1430
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1431
- * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1432
- * @param {number} timeBucket - The 0-indexed 15-minute time bucket. E.g. 27 Feb 2023 05:23 GMT = 1677475383 (Unix time). 1677475383/900=1863861 timeBucket.
1433
- * @param {GetTimeBucketTransactionsForAddressQueryParamOpts} queryParamOpts
1434
- * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1435
- * - `noLogs`: Omit log events.
1436
- * - `withSafe`: Include safe details.
1437
- *
1438
- */
1439
- async getTimeBucketTransactionsForAddress(chainName, walletAddress, timeBucket, queryParamOpts) {
1440
- let success = false;
1441
- let data;
1442
- let response;
1443
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1444
- while (!success) {
1445
- try {
1446
- const urlParams = new URLSearchParams();
1447
- if (!this.is_key_valid) {
1448
- return {
1449
- data: null,
1450
- error: true,
1451
- error_code: 401,
1452
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1453
- };
1454
- }
1455
- if (queryParamOpts?.quoteCurrency !== undefined) {
1456
- urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1457
- }
1458
- if (queryParamOpts?.noLogs !== undefined) {
1459
- urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
1460
- }
1461
- if (queryParamOpts?.withSafe !== undefined) {
1462
- urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
1463
- }
1464
- let startTime;
1465
- if (this.debug) {
1466
- startTime = new Date();
1467
- }
1468
- const url = `https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`;
1469
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`, {
1470
- headers: {
1471
- "Authorization": `Bearer ${this.apiKey}`,
1472
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1473
- }
1474
- }));
1475
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1476
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1477
- try {
1478
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1479
- }
1480
- catch (error) {
1481
- success = true;
1482
- return {
1483
- data: null,
1484
- error: true,
1485
- error_code: response.status ?? 429,
1486
- error_message: error.message
1487
- };
1488
- }
1489
- }
1490
- else {
1491
- data = await response.json();
1492
- }
1493
- const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
1494
- success = true;
1495
- return {
1496
- data: dataClass,
1497
- error: data ? data.error : true,
1498
- error_code: data ? data.error_code : response.status,
1499
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1500
- };
1501
- }
1502
- catch (error) {
1503
- success = true;
1504
- return {
1505
- data: null,
1506
- error: true,
1507
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1508
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1509
- };
1510
- }
1511
- }
1512
- }
1513
- /**
1514
- *
1515
- * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
1516
- *
1517
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1518
- * @param {string} blockHash - The requested block hash.
1519
- * @param {number} page - The requested 0-indexed page number.
1520
- * @param {GetTransactionsForBlockHashByPageQueryParamOpts} queryParamOpts
1521
- * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1522
- * - `noLogs`: Omit log events.
1523
- * - `withSafe`: Include safe details.
1524
- *
1525
- */
1526
- async getTransactionsForBlockHashByPage(chainName, blockHash, page, queryParamOpts) {
1527
- let success = false;
1528
- let data;
1529
- let response;
1530
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1531
- while (!success) {
1532
- try {
1533
- const urlParams = new URLSearchParams();
1534
- if (!this.is_key_valid) {
1535
- return {
1536
- data: null,
1537
- error: true,
1538
- error_code: 401,
1539
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1540
- };
1541
- }
1542
- if (queryParamOpts?.quoteCurrency !== undefined) {
1543
- urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1544
- }
1545
- if (queryParamOpts?.noLogs !== undefined) {
1546
- urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
1547
- }
1548
- if (queryParamOpts?.withSafe !== undefined) {
1549
- urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
1550
- }
1551
- const url = `https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/page/${page}/?${urlParams}`;
1552
- let startTime;
1553
- if (this.debug) {
1554
- startTime = new Date();
1555
- }
1556
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/page/${page}/?${urlParams}`, {
1557
- headers: {
1558
- "Authorization": `Bearer ${this.apiKey}`,
1559
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1560
- }
1561
- }));
1562
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1563
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1564
- try {
1565
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1566
- }
1567
- catch (error) {
1568
- success = true;
1569
- return {
1570
- data: null,
1571
- error: true,
1572
- error_code: response.status ?? 429,
1573
- error_message: error.message
1574
- };
1575
- }
1576
- }
1577
- else {
1578
- data = await response.json();
1579
- }
1580
- const dataClass = new TransactionsBlockPageResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry, this.source);
1581
- success = true;
1582
- return {
1583
- data: dataClass,
1584
- error: data ? data.error : true,
1585
- error_code: data ? data.error_code : response.status,
1586
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1587
- };
1588
- }
1589
- catch (error) {
1590
- success = true;
1591
- return {
1592
- data: null,
1593
- error: true,
1594
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1595
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1596
- };
1597
- }
1598
- }
1599
- }
1600
- /**
1601
- *
1602
- * Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
1603
- *
1604
- * @param {string} chainName - The chain name eg: `eth-mainnet`.
1605
- * @param {string} blockHash - The requested block hash.
1606
- * @param {GetTransactionsForBlockHashQueryParamOpts} queryParamOpts
1607
- * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1608
- * - `noLogs`: Omit log events.
1609
- * - `withSafe`: Include safe details.
1610
- *
1611
- */
1612
- async getTransactionsForBlockHash(chainName, blockHash, queryParamOpts) {
1613
- let success = false;
1614
- let data;
1615
- let response;
1616
- const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1617
- while (!success) {
1618
- try {
1619
- const urlParams = new URLSearchParams();
1620
- if (!this.is_key_valid) {
1621
- return {
1622
- data: null,
1623
- error: true,
1624
- error_code: 401,
1625
- error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1626
- };
1627
- }
1628
- if (queryParamOpts?.quoteCurrency !== undefined) {
1629
- urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1630
- }
1631
- if (queryParamOpts?.noLogs !== undefined) {
1632
- urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
1633
- }
1634
- if (queryParamOpts?.withSafe !== undefined) {
1635
- urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
1636
- }
1637
- const url = `https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/?${urlParams}`;
1638
- let startTime;
1639
- if (this.debug) {
1640
- startTime = new Date();
1641
- }
1642
- response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_hash/${blockHash}/transactions_v3/?${urlParams}`, {
1643
- headers: {
1644
- "Authorization": `Bearer ${this.apiKey}`,
1645
- "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1646
- }
1647
- }));
1648
- debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1649
- if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1650
- try {
1651
- data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1652
- }
1653
- catch (error) {
1654
- success = true;
1655
- return {
1656
- data: null,
1657
- error: true,
1658
- error_code: response.status ?? 429,
1659
- error_message: error.message
1660
- };
1661
- }
1662
- }
1663
- else {
1664
- data = await response.json();
1665
- }
1666
- const dataClass = new TransactionsBlockResponse(data.data);
1667
- success = true;
1668
- return {
1669
- data: dataClass,
1670
- error: data ? data.error : true,
1671
- error_code: data ? data.error_code : response.status,
1672
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
1673
- };
1674
- }
1675
- catch (error) {
1676
- success = true;
1677
- return {
1678
- data: null,
1679
- error: true,
1680
- error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1681
- error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1682
- };
1683
- }
1684
- }
1685
- }
1686
- }
1687
- //# sourceMappingURL=TransactionService.js.map