@covalenthq/client-sdk 0.6.2 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -1
- package/dist/cjs/index.js +392 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/services/BalanceService.d.ts +9 -0
- package/dist/cjs/services/CovalentClient.d.ts +1 -1
- package/dist/cjs/services/TransactionService.d.ts +54 -1
- package/dist/cjs/util/types/BalanceServiceTypes.d.ts +3 -1
- package/dist/cjs/util/types/GenericTypes.d.ts +6 -0
- package/dist/cjs/util/types/TransactionServiceTypes.d.ts +3 -1
- package/dist/es/index.js +392 -5
- package/dist/es/index.js.map +1 -1
- package/dist/es/services/BalanceService.d.ts +9 -0
- package/dist/es/services/CovalentClient.d.ts +1 -1
- package/dist/es/services/TransactionService.d.ts +54 -1
- package/dist/es/util/types/BalanceServiceTypes.d.ts +3 -1
- package/dist/es/util/types/GenericTypes.d.ts +6 -0
- package/dist/es/util/types/TransactionServiceTypes.d.ts +3 -1
- package/dist/esm/index.js +392 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/BalanceService.d.ts +9 -0
- package/dist/esm/services/CovalentClient.d.ts +1 -1
- package/dist/esm/services/TransactionService.d.ts +54 -1
- package/dist/esm/util/types/BalanceServiceTypes.d.ts +3 -1
- package/dist/esm/util/types/GenericTypes.d.ts +6 -0
- package/dist/esm/util/types/TransactionServiceTypes.d.ts +3 -1
- package/dist/services/BalanceService.d.ts +9 -0
- package/dist/services/BalanceService.js +7 -0
- package/dist/services/BalanceService.js.map +1 -1
- package/dist/services/CovalentClient.d.ts +1 -1
- package/dist/services/CovalentClient.js +1 -1
- package/dist/services/TransactionService.d.ts +54 -1
- package/dist/services/TransactionService.js +364 -3
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/util/CalculatePrettyBalance.js +9 -2
- package/dist/util/CalculatePrettyBalance.js.map +1 -1
- package/dist/util/types/BalanceServiceTypes.d.ts +3 -1
- package/dist/util/types/GenericTypes.d.ts +6 -0
- package/dist/util/types/TransactionServiceTypes.d.ts +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -155,11 +155,26 @@ The `PricingService` class refers to the [historical token prices API endpoint](
|
|
|
155
155
|
The `TransactionService` class refers to the [transactions API endpoints](https://www.covalenthq.com/docs/api/transactions/get-a-transaction/):
|
|
156
156
|
|
|
157
157
|
- `getAllTransactionsForAddress()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Paginated)
|
|
158
|
-
- `
|
|
158
|
+
- `getAllTransactionsForAddressByPage()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Nonpaginated)
|
|
159
|
+
- `getTransactionsForAddressV3()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
|
|
159
160
|
- `getTransaction()`: Fetch and render a single transaction including its decoded log events. Additionally return semantically decoded information for DEX trades, lending and NFT sales.
|
|
160
161
|
- `getTransactionsForBlock()`: Fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
|
|
161
162
|
- `getTransactionSummary()`: Fetch the earliest and latest transactions, and the transaction count for a wallet. Calculate the age of the wallet and the time it has been idle and quickly gain insights into their engagement with web3.
|
|
162
163
|
|
|
164
|
+
The functions `getAllTransactionsForAddressByPage()` and `getTransactionsForAddressV3()` have been enhanced with the introduction of `next()` and `prev()` support functions. These functions facilitate a smoother transition for developers navigating through our links object, which includes `prev` and `next` fields. Instead of requiring developers to manually extract values from these fields and create JavaScript API fetch calls for the URL values, the new `next()` and `prev()` functions provide a streamlined approach, allowing developers to simulate this behavior more efficiently.
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
import { CovalentClient } from "@covalenthq/client-sdk";
|
|
168
|
+
|
|
169
|
+
const client = new CovalentClient("YOUR_API_KEY"); // Replace with your Covalent API key.
|
|
170
|
+
const resp = await client.TransactionService.getAllTransactionsForAddressByPage("eth-mainnet", "WALLET_ADDRESS");
|
|
171
|
+
// assuming resp.data.current_page is 10
|
|
172
|
+
if (resp.data !== null) {
|
|
173
|
+
const prevPage = await resp.data.prev() // will retrieve page 9
|
|
174
|
+
console.log(prevPage.data)
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
163
178
|
### XykService
|
|
164
179
|
|
|
165
180
|
The `XykService` refers to the [Xy=k API endpoints](https://www.covalenthq.com/docs/api/xyk/get-xyk-pools/):
|
package/dist/cjs/index.js
CHANGED
|
@@ -659,6 +659,7 @@ class BlockTransactionWithContractTransfers {
|
|
|
659
659
|
this.gas_quote = data.gas_quote;
|
|
660
660
|
this.pretty_gas_quote = data.pretty_gas_quote;
|
|
661
661
|
this.gas_quote_rate = data.gas_quote_rate;
|
|
662
|
+
this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer$1(itemData)) : null;
|
|
662
663
|
this.transfers = data.transfers && data.transfers !== null ? data.transfers.map((itemData) => new TokenTransferItem(itemData)) : null;
|
|
663
664
|
}
|
|
664
665
|
}
|
|
@@ -670,6 +671,12 @@ let Pagination$3 = class Pagination {
|
|
|
670
671
|
this.total_count = data.total_count;
|
|
671
672
|
}
|
|
672
673
|
};
|
|
674
|
+
let Explorer$1 = class Explorer {
|
|
675
|
+
constructor(data) {
|
|
676
|
+
this.label = data.label;
|
|
677
|
+
this.url = data.url;
|
|
678
|
+
}
|
|
679
|
+
};
|
|
673
680
|
class TokenTransferItem {
|
|
674
681
|
constructor(data) {
|
|
675
682
|
this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? dateFns.parseISO(data.block_signed_at.toString()) : null;
|
|
@@ -3878,6 +3885,7 @@ class Transaction {
|
|
|
3878
3885
|
this.pretty_gas_quote = data.pretty_gas_quote;
|
|
3879
3886
|
this.gas_quote_rate = data.gas_quote_rate;
|
|
3880
3887
|
this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
|
|
3888
|
+
this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
|
|
3881
3889
|
this.dex_details = data.dex_details && data.dex_details !== null ? new DexReport(data.dex_details) : null;
|
|
3882
3890
|
this.nft_sale_details = data.nft_sale_details && data.nft_sale_details !== null ? new NftSalesReport(data.nft_sale_details) : null;
|
|
3883
3891
|
this.lending_details = data.lending_details && data.lending_details !== null ? new LendingReport(data.lending_details) : null;
|
|
@@ -3895,6 +3903,12 @@ class ContractMetadata {
|
|
|
3895
3903
|
this.logo_url = data.logo_url;
|
|
3896
3904
|
}
|
|
3897
3905
|
}
|
|
3906
|
+
class Explorer {
|
|
3907
|
+
constructor(data) {
|
|
3908
|
+
this.label = data.label;
|
|
3909
|
+
this.url = data.url;
|
|
3910
|
+
}
|
|
3911
|
+
}
|
|
3898
3912
|
class DexReport {
|
|
3899
3913
|
constructor(data) {
|
|
3900
3914
|
this.log_offset = data.log_offset;
|
|
@@ -4052,6 +4066,154 @@ class Param {
|
|
|
4052
4066
|
this.value = data.value;
|
|
4053
4067
|
}
|
|
4054
4068
|
}
|
|
4069
|
+
class RecentTransactionsResponse {
|
|
4070
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
|
|
4071
|
+
this._debug = _debug;
|
|
4072
|
+
this._apiKey = _apiKey;
|
|
4073
|
+
this._threadCount = _threadCount;
|
|
4074
|
+
this._urlParams = _urlParams;
|
|
4075
|
+
this.address = data.address;
|
|
4076
|
+
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
4077
|
+
this.quote_currency = data.quote_currency;
|
|
4078
|
+
this.chain_id = data.chain_id;
|
|
4079
|
+
this.chain_name = data.chain_name;
|
|
4080
|
+
this.current_page = data.current_page;
|
|
4081
|
+
this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
|
|
4082
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
|
|
4083
|
+
}
|
|
4084
|
+
async prev() {
|
|
4085
|
+
let success = false;
|
|
4086
|
+
let data;
|
|
4087
|
+
let response;
|
|
4088
|
+
const backoff = new ExponentialBackoff(this._apiKey, this._debug);
|
|
4089
|
+
const LIMIT = pLimit$1(this._threadCount);
|
|
4090
|
+
while (!success) {
|
|
4091
|
+
try {
|
|
4092
|
+
let startTime;
|
|
4093
|
+
if (this._debug) {
|
|
4094
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
4095
|
+
}
|
|
4096
|
+
if (this.links.prev === null) {
|
|
4097
|
+
success = true;
|
|
4098
|
+
return {
|
|
4099
|
+
data: null,
|
|
4100
|
+
error: true,
|
|
4101
|
+
error_code: 400,
|
|
4102
|
+
error_message: "Invalid URL: URL link cannot be null"
|
|
4103
|
+
};
|
|
4104
|
+
}
|
|
4105
|
+
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4106
|
+
headers: {
|
|
4107
|
+
"Authorization": `Bearer ${this._apiKey}`,
|
|
4108
|
+
"X-Requested-With": userAgent
|
|
4109
|
+
}
|
|
4110
|
+
}));
|
|
4111
|
+
debugOutput(response.url, response.status, startTime);
|
|
4112
|
+
if (response.status === 429) {
|
|
4113
|
+
try {
|
|
4114
|
+
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4115
|
+
}
|
|
4116
|
+
catch (error) {
|
|
4117
|
+
success = true;
|
|
4118
|
+
return {
|
|
4119
|
+
data: null,
|
|
4120
|
+
error: true,
|
|
4121
|
+
error_code: response.status,
|
|
4122
|
+
error_message: error.message
|
|
4123
|
+
};
|
|
4124
|
+
}
|
|
4125
|
+
}
|
|
4126
|
+
else {
|
|
4127
|
+
data = await response.json();
|
|
4128
|
+
}
|
|
4129
|
+
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4130
|
+
checkAndModifyResponse(dataClass);
|
|
4131
|
+
success = true;
|
|
4132
|
+
return {
|
|
4133
|
+
data: dataClass,
|
|
4134
|
+
error: data.error,
|
|
4135
|
+
error_code: data ? data.error_code : response.status,
|
|
4136
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4137
|
+
};
|
|
4138
|
+
}
|
|
4139
|
+
catch (error) {
|
|
4140
|
+
success = true;
|
|
4141
|
+
return {
|
|
4142
|
+
data: null,
|
|
4143
|
+
error: true,
|
|
4144
|
+
error_code: data ? data.error_code : response.status,
|
|
4145
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4146
|
+
};
|
|
4147
|
+
}
|
|
4148
|
+
}
|
|
4149
|
+
}
|
|
4150
|
+
async next() {
|
|
4151
|
+
let success = false;
|
|
4152
|
+
let data;
|
|
4153
|
+
let response;
|
|
4154
|
+
const backoff = new ExponentialBackoff(this._apiKey, this._debug);
|
|
4155
|
+
const LIMIT = pLimit$1(this._threadCount);
|
|
4156
|
+
while (!success) {
|
|
4157
|
+
try {
|
|
4158
|
+
let startTime;
|
|
4159
|
+
if (this._debug) {
|
|
4160
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
4161
|
+
}
|
|
4162
|
+
if (this.links.next === null) {
|
|
4163
|
+
success = true;
|
|
4164
|
+
return {
|
|
4165
|
+
data: null,
|
|
4166
|
+
error: true,
|
|
4167
|
+
error_code: 400,
|
|
4168
|
+
error_message: "Invalid URL: URL link cannot be null"
|
|
4169
|
+
};
|
|
4170
|
+
}
|
|
4171
|
+
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4172
|
+
headers: {
|
|
4173
|
+
"Authorization": `Bearer ${this._apiKey}`,
|
|
4174
|
+
"X-Requested-With": userAgent
|
|
4175
|
+
}
|
|
4176
|
+
}));
|
|
4177
|
+
debugOutput(response.url, response.status, startTime);
|
|
4178
|
+
if (response.status === 429) {
|
|
4179
|
+
try {
|
|
4180
|
+
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4181
|
+
}
|
|
4182
|
+
catch (error) {
|
|
4183
|
+
success = true;
|
|
4184
|
+
return {
|
|
4185
|
+
data: null,
|
|
4186
|
+
error: true,
|
|
4187
|
+
error_code: response.status,
|
|
4188
|
+
error_message: error.message
|
|
4189
|
+
};
|
|
4190
|
+
}
|
|
4191
|
+
}
|
|
4192
|
+
else {
|
|
4193
|
+
data = await response.json();
|
|
4194
|
+
}
|
|
4195
|
+
const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4196
|
+
checkAndModifyResponse(dataClass);
|
|
4197
|
+
success = true;
|
|
4198
|
+
return {
|
|
4199
|
+
data: dataClass,
|
|
4200
|
+
error: data.error,
|
|
4201
|
+
error_code: data ? data.error_code : response.status,
|
|
4202
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4203
|
+
};
|
|
4204
|
+
}
|
|
4205
|
+
catch (error) {
|
|
4206
|
+
success = true;
|
|
4207
|
+
return {
|
|
4208
|
+
data: null,
|
|
4209
|
+
error: true,
|
|
4210
|
+
error_code: data ? data.error_code : response.status,
|
|
4211
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4212
|
+
};
|
|
4213
|
+
}
|
|
4214
|
+
}
|
|
4215
|
+
}
|
|
4216
|
+
}
|
|
4055
4217
|
class PaginationLinks {
|
|
4056
4218
|
constructor(data) {
|
|
4057
4219
|
this.prev = data.prev;
|
|
@@ -4090,7 +4252,11 @@ class TransactionSummary {
|
|
|
4090
4252
|
}
|
|
4091
4253
|
}
|
|
4092
4254
|
class TransactionsResponse {
|
|
4093
|
-
constructor(data) {
|
|
4255
|
+
constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
|
|
4256
|
+
this._debug = _debug;
|
|
4257
|
+
this._apiKey = _apiKey;
|
|
4258
|
+
this._threadCount = _threadCount;
|
|
4259
|
+
this._urlParams = _urlParams;
|
|
4094
4260
|
this.address = data.address;
|
|
4095
4261
|
this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
|
|
4096
4262
|
this.quote_currency = data.quote_currency;
|
|
@@ -4100,6 +4266,138 @@ class TransactionsResponse {
|
|
|
4100
4266
|
this.links = data.links && data.links !== null ? new PaginationLinks(data.links) : null;
|
|
4101
4267
|
this.items = data.items && data.items !== null ? data.items.map((itemData) => new Transaction(itemData)) : null;
|
|
4102
4268
|
}
|
|
4269
|
+
async prev() {
|
|
4270
|
+
let success = false;
|
|
4271
|
+
let data;
|
|
4272
|
+
let response;
|
|
4273
|
+
const backoff = new ExponentialBackoff(this._apiKey, this._debug);
|
|
4274
|
+
const LIMIT = pLimit$1(this._threadCount);
|
|
4275
|
+
while (!success) {
|
|
4276
|
+
try {
|
|
4277
|
+
let startTime;
|
|
4278
|
+
if (this._debug) {
|
|
4279
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
4280
|
+
}
|
|
4281
|
+
if (this.links.prev === null) {
|
|
4282
|
+
success = true;
|
|
4283
|
+
return {
|
|
4284
|
+
data: null,
|
|
4285
|
+
error: true,
|
|
4286
|
+
error_code: 400,
|
|
4287
|
+
error_message: "Invalid URL: URL link cannot be null"
|
|
4288
|
+
};
|
|
4289
|
+
}
|
|
4290
|
+
response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
|
|
4291
|
+
headers: {
|
|
4292
|
+
"Authorization": `Bearer ${this._apiKey}`,
|
|
4293
|
+
"X-Requested-With": userAgent
|
|
4294
|
+
}
|
|
4295
|
+
}));
|
|
4296
|
+
debugOutput(response.url, response.status, startTime);
|
|
4297
|
+
if (response.status === 429) {
|
|
4298
|
+
try {
|
|
4299
|
+
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4300
|
+
}
|
|
4301
|
+
catch (error) {
|
|
4302
|
+
success = true;
|
|
4303
|
+
return {
|
|
4304
|
+
data: null,
|
|
4305
|
+
error: true,
|
|
4306
|
+
error_code: response.status,
|
|
4307
|
+
error_message: error.message
|
|
4308
|
+
};
|
|
4309
|
+
}
|
|
4310
|
+
}
|
|
4311
|
+
else {
|
|
4312
|
+
data = await response.json();
|
|
4313
|
+
}
|
|
4314
|
+
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4315
|
+
checkAndModifyResponse(dataClass);
|
|
4316
|
+
success = true;
|
|
4317
|
+
return {
|
|
4318
|
+
data: dataClass,
|
|
4319
|
+
error: data.error,
|
|
4320
|
+
error_code: data ? data.error_code : response.status,
|
|
4321
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4322
|
+
};
|
|
4323
|
+
}
|
|
4324
|
+
catch (error) {
|
|
4325
|
+
success = true;
|
|
4326
|
+
return {
|
|
4327
|
+
data: null,
|
|
4328
|
+
error: true,
|
|
4329
|
+
error_code: data ? data.error_code : response.status,
|
|
4330
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4331
|
+
};
|
|
4332
|
+
}
|
|
4333
|
+
}
|
|
4334
|
+
}
|
|
4335
|
+
async next() {
|
|
4336
|
+
let success = false;
|
|
4337
|
+
let data;
|
|
4338
|
+
let response;
|
|
4339
|
+
const backoff = new ExponentialBackoff(this._apiKey, this._debug);
|
|
4340
|
+
const LIMIT = pLimit$1(this._threadCount);
|
|
4341
|
+
while (!success) {
|
|
4342
|
+
try {
|
|
4343
|
+
let startTime;
|
|
4344
|
+
if (this._debug) {
|
|
4345
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
4346
|
+
}
|
|
4347
|
+
if (this.links.next === null) {
|
|
4348
|
+
success = true;
|
|
4349
|
+
return {
|
|
4350
|
+
data: null,
|
|
4351
|
+
error: true,
|
|
4352
|
+
error_code: 400,
|
|
4353
|
+
error_message: "Invalid URL: URL link cannot be null"
|
|
4354
|
+
};
|
|
4355
|
+
}
|
|
4356
|
+
response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
|
|
4357
|
+
headers: {
|
|
4358
|
+
"Authorization": `Bearer ${this._apiKey}`,
|
|
4359
|
+
"X-Requested-With": userAgent
|
|
4360
|
+
}
|
|
4361
|
+
}));
|
|
4362
|
+
debugOutput(response.url, response.status, startTime);
|
|
4363
|
+
if (response.status === 429) {
|
|
4364
|
+
try {
|
|
4365
|
+
data = await LIMIT(() => backoff.backOff(response.url));
|
|
4366
|
+
}
|
|
4367
|
+
catch (error) {
|
|
4368
|
+
success = true;
|
|
4369
|
+
return {
|
|
4370
|
+
data: null,
|
|
4371
|
+
error: true,
|
|
4372
|
+
error_code: response.status,
|
|
4373
|
+
error_message: error.message
|
|
4374
|
+
};
|
|
4375
|
+
}
|
|
4376
|
+
}
|
|
4377
|
+
else {
|
|
4378
|
+
data = await response.json();
|
|
4379
|
+
}
|
|
4380
|
+
const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
|
|
4381
|
+
checkAndModifyResponse(dataClass);
|
|
4382
|
+
success = true;
|
|
4383
|
+
return {
|
|
4384
|
+
data: dataClass,
|
|
4385
|
+
error: data.error,
|
|
4386
|
+
error_code: data ? data.error_code : response.status,
|
|
4387
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4388
|
+
};
|
|
4389
|
+
}
|
|
4390
|
+
catch (error) {
|
|
4391
|
+
success = true;
|
|
4392
|
+
return {
|
|
4393
|
+
data: null,
|
|
4394
|
+
error: true,
|
|
4395
|
+
error_code: data ? data.error_code : response.status,
|
|
4396
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4397
|
+
};
|
|
4398
|
+
}
|
|
4399
|
+
}
|
|
4400
|
+
}
|
|
4103
4401
|
}
|
|
4104
4402
|
/**
|
|
4105
4403
|
* Transactions APIs
|
|
@@ -4300,6 +4598,88 @@ class TransactionService {
|
|
|
4300
4598
|
}
|
|
4301
4599
|
}
|
|
4302
4600
|
}
|
|
4601
|
+
/**
|
|
4602
|
+
*
|
|
4603
|
+
* Commonly used to fetch and render the most recent transactions involving an address. Frequently seen in wallet applications.
|
|
4604
|
+
*
|
|
4605
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
4606
|
+
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
4607
|
+
* @param {GetAllTransactionsForAddressQueryParamOpts} queryParamOpts
|
|
4608
|
+
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
4609
|
+
* - `noLogs`: Omit log events.
|
|
4610
|
+
* - `blockSignedAtAsc`: Sort the transactions in ascending chronological order. By default, it's set to `false` and returns transactions in descending chronological order.
|
|
4611
|
+
* - `withSafe`: Include safe details.
|
|
4612
|
+
*
|
|
4613
|
+
*/
|
|
4614
|
+
async getAllTransactionsForAddressByPage(chainName, walletAddress, queryParamOpts) {
|
|
4615
|
+
let success = false;
|
|
4616
|
+
let data;
|
|
4617
|
+
let response;
|
|
4618
|
+
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
4619
|
+
while (!success) {
|
|
4620
|
+
try {
|
|
4621
|
+
const urlParams = new URLSearchParams();
|
|
4622
|
+
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
4623
|
+
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
4624
|
+
}
|
|
4625
|
+
if (queryParamOpts?.noLogs !== undefined) {
|
|
4626
|
+
urlParams.append("no-logs", queryParamOpts?.noLogs.toString());
|
|
4627
|
+
}
|
|
4628
|
+
if (queryParamOpts?.blockSignedAtAsc !== undefined) {
|
|
4629
|
+
urlParams.append("block-signed-at-asc", queryParamOpts?.blockSignedAtAsc.toString());
|
|
4630
|
+
}
|
|
4631
|
+
if (queryParamOpts?.withSafe !== undefined) {
|
|
4632
|
+
urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
|
|
4633
|
+
}
|
|
4634
|
+
let startTime;
|
|
4635
|
+
if (this.debug) {
|
|
4636
|
+
startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
|
|
4637
|
+
}
|
|
4638
|
+
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`, {
|
|
4639
|
+
headers: {
|
|
4640
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
4641
|
+
"X-Requested-With": userAgent
|
|
4642
|
+
}
|
|
4643
|
+
}));
|
|
4644
|
+
debugOutput(response.url, response.status, startTime);
|
|
4645
|
+
if (response.status === 429) {
|
|
4646
|
+
try {
|
|
4647
|
+
data = await this.LIMIT(() => backoff.backOff(response.url));
|
|
4648
|
+
}
|
|
4649
|
+
catch (error) {
|
|
4650
|
+
success = true;
|
|
4651
|
+
return {
|
|
4652
|
+
data: null,
|
|
4653
|
+
error: true,
|
|
4654
|
+
error_code: response.status,
|
|
4655
|
+
error_message: error.message
|
|
4656
|
+
};
|
|
4657
|
+
}
|
|
4658
|
+
}
|
|
4659
|
+
else {
|
|
4660
|
+
data = await response.json();
|
|
4661
|
+
}
|
|
4662
|
+
const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
|
|
4663
|
+
checkAndModifyResponse(dataClass);
|
|
4664
|
+
success = true;
|
|
4665
|
+
return {
|
|
4666
|
+
data: dataClass,
|
|
4667
|
+
error: data.error,
|
|
4668
|
+
error_code: data ? data.error_code : response.status,
|
|
4669
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4670
|
+
};
|
|
4671
|
+
}
|
|
4672
|
+
catch (error) {
|
|
4673
|
+
success = true;
|
|
4674
|
+
return {
|
|
4675
|
+
data: null,
|
|
4676
|
+
error: true,
|
|
4677
|
+
error_code: data ? data.error_code : response.status,
|
|
4678
|
+
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
|
|
4679
|
+
};
|
|
4680
|
+
}
|
|
4681
|
+
}
|
|
4682
|
+
}
|
|
4303
4683
|
/**
|
|
4304
4684
|
*
|
|
4305
4685
|
* Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.
|
|
@@ -4503,7 +4883,7 @@ class TransactionService {
|
|
|
4503
4883
|
else {
|
|
4504
4884
|
data = await response.json();
|
|
4505
4885
|
}
|
|
4506
|
-
const dataClass = new TransactionsResponse(data.data);
|
|
4886
|
+
const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
|
|
4507
4887
|
checkAndModifyResponse(dataClass);
|
|
4508
4888
|
success = true;
|
|
4509
4889
|
return {
|
|
@@ -5868,7 +6248,7 @@ class XykService {
|
|
|
5868
6248
|
}
|
|
5869
6249
|
}
|
|
5870
6250
|
|
|
5871
|
-
const userAgent = "com.covalenthq.sdk.typescript/0.6.
|
|
6251
|
+
const userAgent = "com.covalenthq.sdk.typescript/0.6.4";
|
|
5872
6252
|
/**
|
|
5873
6253
|
* CovalentClient Class
|
|
5874
6254
|
*/
|
|
@@ -5904,8 +6284,15 @@ class Client {
|
|
|
5904
6284
|
}
|
|
5905
6285
|
|
|
5906
6286
|
const calculatePrettyBalance = (value, decimals = 18, roundOff = true, precision = 0) => {
|
|
5907
|
-
|
|
5908
|
-
|
|
6287
|
+
let bigIntValue;
|
|
6288
|
+
let bigDecimalValue;
|
|
6289
|
+
try {
|
|
6290
|
+
bigIntValue = BigInt(value);
|
|
6291
|
+
bigDecimalValue = new Big(bigIntValue.toString());
|
|
6292
|
+
}
|
|
6293
|
+
catch (error) {
|
|
6294
|
+
bigDecimalValue = new Big(value.toString());
|
|
6295
|
+
}
|
|
5909
6296
|
const _decimals = decimals || 18;
|
|
5910
6297
|
const _expoValue = BigInt(Math.pow(10, _decimals));
|
|
5911
6298
|
const bigDecimalExpo = new Big(_expoValue.toString());
|