@covalenthq/client-sdk 0.1.2 → 0.1.3
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 +44 -31
- package/dist/services/BalanceService.d.ts +390 -0
- package/dist/services/BalanceService.js +618 -0
- package/dist/services/BalanceService.js.map +1 -0
- package/dist/services/BaseService.d.ts +303 -0
- package/dist/services/BaseService.js +691 -0
- package/dist/services/BaseService.js.map +1 -0
- package/dist/services/Client.d.ts +22 -0
- package/dist/services/Client.js +26 -0
- package/dist/services/Client.js.map +1 -0
- package/dist/services/NftService.d.ts +428 -0
- package/dist/services/NftService.js +981 -0
- package/dist/services/NftService.js.map +1 -0
- package/dist/services/PricingService.d.ts +75 -0
- package/dist/services/PricingService.js +126 -0
- package/dist/services/PricingService.js.map +1 -0
- package/dist/services/SecurityService.d.ts +96 -0
- package/dist/services/SecurityService.js +122 -0
- package/dist/services/SecurityService.js.map +1 -0
- package/dist/services/TransactionService.d.ts +222 -0
- package/dist/services/TransactionService.js +433 -0
- package/dist/services/TransactionService.js.map +1 -0
- package/dist/services/XykService.d.ts +529 -0
- package/dist/services/XykService.js +1000 -0
- package/dist/services/XykService.js.map +1 -0
- package/dist/services/index.js.map +1 -0
- package/dist/util/ApiHelpers.d.ts +1 -0
- package/dist/util/ApiHelpers.js +15 -0
- package/dist/util/ApiHelpers.js.map +1 -0
- package/dist/util/backoff.d.ts +9 -0
- package/dist/util/backoff.js +25 -0
- package/dist/util/backoff.js.map +1 -0
- package/package.json +9 -1
- package/dist/ApprovalService.d.ts +0 -59
- package/dist/ApprovalService.js +0 -52
- package/dist/ApprovalService.js.map +0 -1
- package/dist/BalancesService.d.ts +0 -189
- package/dist/BalancesService.js +0 -231
- package/dist/BalancesService.js.map +0 -1
- package/dist/BaseService.d.ts +0 -169
- package/dist/BaseService.js +0 -276
- package/dist/BaseService.js.map +0 -1
- package/dist/Client.d.ts +0 -24
- package/dist/Client.js +0 -30
- package/dist/Client.js.map +0 -1
- package/dist/LogEventService.d.ts +0 -62
- package/dist/LogEventService.js +0 -75
- package/dist/LogEventService.js.map +0 -1
- package/dist/NameResolverService.d.ts +0 -33
- package/dist/NameResolverService.js +0 -52
- package/dist/NameResolverService.js.map +0 -1
- package/dist/NftService.d.ts +0 -271
- package/dist/NftService.js +0 -528
- package/dist/NftService.js.map +0 -1
- package/dist/PricingService.d.ts +0 -52
- package/dist/PricingService.js +0 -65
- package/dist/PricingService.js.map +0 -1
- package/dist/TransactionsService.d.ts +0 -126
- package/dist/TransactionsService.js +0 -230
- package/dist/TransactionsService.js.map +0 -1
- package/dist/XykService.d.ts +0 -383
- package/dist/XykService.js +0 -467
- package/dist/XykService.js.map +0 -1
- package/dist/index.js.map +0 -1
- /package/dist/{index.d.ts → services/index.d.ts} +0 -0
- /package/dist/{index.js → services/index.js} +0 -0
|
@@ -0,0 +1,981 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NftService = exports.Response = void 0;
|
|
4
|
+
const backoff_1 = require("../util/backoff");
|
|
5
|
+
const ApiHelpers_1 = require("../util/ApiHelpers");
|
|
6
|
+
class ChainCollectionResponse {
|
|
7
|
+
constructor(data) {
|
|
8
|
+
this.updated_at = data.updated_at;
|
|
9
|
+
this.chain_id = data.chain_id;
|
|
10
|
+
this.chain_name = data.chain_name;
|
|
11
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new ChainCollectionItem(itemData)) : null;
|
|
12
|
+
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
class ChainCollectionItem {
|
|
16
|
+
constructor(data) {
|
|
17
|
+
this.contract_address = data.contract_address;
|
|
18
|
+
this.contract_name = data.contract_name;
|
|
19
|
+
this.is_spam = data.is_spam;
|
|
20
|
+
this.token_total_supply = data.token_total_supply;
|
|
21
|
+
this.cached_metadata_count = data.cached_metadata_count;
|
|
22
|
+
this.cached_asset_count = data.cached_asset_count;
|
|
23
|
+
this.last_scraped_at = data.last_scraped_at;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
class Pagination {
|
|
27
|
+
constructor(data) {
|
|
28
|
+
this.has_more = data.has_more;
|
|
29
|
+
this.page_number = data.page_number;
|
|
30
|
+
this.page_size = data.page_size;
|
|
31
|
+
this.total_count = data.total_count;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class NftAddressBalanceNftResponse {
|
|
35
|
+
constructor(data) {
|
|
36
|
+
this.address = data.address;
|
|
37
|
+
this.updated_at = data.updated_at;
|
|
38
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTokenContractBalanceItem(itemData)) : null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class NftTokenContractBalanceItem {
|
|
42
|
+
constructor(data) {
|
|
43
|
+
this.contract_name = data.contract_name;
|
|
44
|
+
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
45
|
+
this.contract_address = data.contract_address;
|
|
46
|
+
this.supports_erc = data.supports_erc;
|
|
47
|
+
this.is_spam = data.is_spam;
|
|
48
|
+
this.last_transfered_at = data.last_transfered_at;
|
|
49
|
+
this.balance = data.balance !== null ? BigInt(data.balance) : null;
|
|
50
|
+
this.balance24h = data.balance24h;
|
|
51
|
+
this.type = data.type;
|
|
52
|
+
this.nft_data = data.nft_data && data.nft_data !== null ? data.nft_data.map((itemData) => new NftData(itemData)) : null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
class NftData {
|
|
56
|
+
constructor(data) {
|
|
57
|
+
this.token_id = data.token_id !== null ? BigInt(data.token_id) : null;
|
|
58
|
+
this.token_url = data.token_url;
|
|
59
|
+
this.original_owner = data.original_owner;
|
|
60
|
+
this.asset_cached = data.asset_cached;
|
|
61
|
+
this.image_cached = data.image_cached;
|
|
62
|
+
this.external_data = data.external_data && data.external_data !== null ? new NftExternalData(data.external_data) : null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
class NftExternalData {
|
|
66
|
+
constructor(data) {
|
|
67
|
+
this.name = data.name;
|
|
68
|
+
this.description = data.description;
|
|
69
|
+
this.asset_url = data.asset_url;
|
|
70
|
+
this.asset_file_extension = data.asset_file_extension;
|
|
71
|
+
this.asset_mime_type = data.asset_mime_type;
|
|
72
|
+
this.asset_size_bytes = data.asset_size_bytes;
|
|
73
|
+
this.image = data.image;
|
|
74
|
+
this.image_256 = data.image_256;
|
|
75
|
+
this.image_512 = data.image_512;
|
|
76
|
+
this.image_1024 = data.image_1024;
|
|
77
|
+
this.animation_url = data.animation_url;
|
|
78
|
+
this.external_url = data.external_url;
|
|
79
|
+
this.attributes = data.attributes && data.attributes !== null ? data.attributes.map((itemData) => new NftCollectionAttribute(itemData)) : null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
class NftCollectionAttribute {
|
|
83
|
+
constructor(data) {
|
|
84
|
+
this.trait_type = data.trait_type;
|
|
85
|
+
this.value = data.value;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
class NftMetadataResponse {
|
|
89
|
+
constructor(data) {
|
|
90
|
+
this.updated_at = data.updated_at;
|
|
91
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTokenContract(itemData)) : null;
|
|
92
|
+
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
class NftTokenContract {
|
|
96
|
+
constructor(data) {
|
|
97
|
+
this.contract_name = data.contract_name;
|
|
98
|
+
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
99
|
+
this.contract_address = data.contract_address;
|
|
100
|
+
this.is_spam = data.is_spam;
|
|
101
|
+
this.type = data.type;
|
|
102
|
+
this.nft_data = data.nft_data && data.nft_data !== null ? new NftData(data.nft_data) : null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
class NftTransactionsResponse {
|
|
106
|
+
constructor(data) {
|
|
107
|
+
this.updated_at = data.updated_at;
|
|
108
|
+
this.chain_id = data.chain_id;
|
|
109
|
+
this.chain_name = data.chain_name;
|
|
110
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTransaction(itemData)) : null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
class NftTransaction {
|
|
114
|
+
constructor(data) {
|
|
115
|
+
this.contract_decimals = data.contract_decimals;
|
|
116
|
+
this.contract_name = data.contract_name;
|
|
117
|
+
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
118
|
+
this.logo_url = data.logo_url;
|
|
119
|
+
this.contract_address = data.contract_address;
|
|
120
|
+
this.supports_erc = data.supports_erc;
|
|
121
|
+
this.is_spam = data.is_spam;
|
|
122
|
+
this.nft_transactions = data.nft_transactions && data.nft_transactions !== null ? data.nft_transactions.map((itemData) => new NftTransactionItem(itemData)) : null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
class NftTransactionItem {
|
|
126
|
+
constructor(data) {
|
|
127
|
+
this.block_signed_at = data.block_signed_at;
|
|
128
|
+
this.block_height = data.block_height;
|
|
129
|
+
this.tx_hash = data.tx_hash;
|
|
130
|
+
this.tx_offset = data.tx_offset;
|
|
131
|
+
this.successful = data.successful;
|
|
132
|
+
this.from_address = data.from_address;
|
|
133
|
+
this.from_address_label = data.from_address_label;
|
|
134
|
+
this.to_address = data.to_address;
|
|
135
|
+
this.to_address_label = data.to_address_label;
|
|
136
|
+
this.value = data.value !== null ? BigInt(data.value) : null;
|
|
137
|
+
this.value_quote = data.value_quote;
|
|
138
|
+
this.pretty_value_quote = data.pretty_value_quote;
|
|
139
|
+
this.gas_offered = data.gas_offered;
|
|
140
|
+
this.gas_spent = data.gas_spent;
|
|
141
|
+
this.gas_price = data.gas_price;
|
|
142
|
+
this.fees_paid = data.fees_paid !== null ? BigInt(data.fees_paid) : null;
|
|
143
|
+
this.gas_quote = data.gas_quote;
|
|
144
|
+
this.pretty_gas_quote = data.pretty_gas_quote;
|
|
145
|
+
this.gas_quote_rate = data.gas_quote_rate;
|
|
146
|
+
this.log_events = data.log_events && data.log_events !== null ? data.log_events.map((itemData) => new LogEvent(itemData)) : null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
class LogEvent {
|
|
150
|
+
constructor(data) {
|
|
151
|
+
this.block_signed_at = data.block_signed_at;
|
|
152
|
+
this.block_height = data.block_height;
|
|
153
|
+
this.tx_offset = data.tx_offset;
|
|
154
|
+
this.log_offset = data.log_offset;
|
|
155
|
+
this.tx_hash = data.tx_hash;
|
|
156
|
+
this.raw_log_topics = data.raw_log_topics;
|
|
157
|
+
this.sender_contract_decimals = data.sender_contract_decimals;
|
|
158
|
+
this.sender_name = data.sender_name;
|
|
159
|
+
this.sender_contract_ticker_symbol = data.sender_contract_ticker_symbol;
|
|
160
|
+
this.sender_address = data.sender_address;
|
|
161
|
+
this.sender_address_label = data.sender_address_label;
|
|
162
|
+
this.sender_logo_url = data.sender_logo_url;
|
|
163
|
+
this.raw_log_data = data.raw_log_data;
|
|
164
|
+
this.decoded = data.decoded && data.decoded !== null ? new DecodedItem(data.decoded) : null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
class DecodedItem {
|
|
168
|
+
constructor(data) {
|
|
169
|
+
this.name = data.name;
|
|
170
|
+
this.signature = data.signature;
|
|
171
|
+
this.params = data.params && data.params !== null ? data.params.map((itemData) => new Param(itemData)) : null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
class Param {
|
|
175
|
+
constructor(data) {
|
|
176
|
+
this.name = data.name;
|
|
177
|
+
this.type = data.type;
|
|
178
|
+
this.indexed = data.indexed;
|
|
179
|
+
this.decoded = data.decoded;
|
|
180
|
+
this.value = data.value;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
class NftCollectionTraitsResponse {
|
|
184
|
+
constructor(data) {
|
|
185
|
+
this.updated_at = data.updated_at;
|
|
186
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTrait(itemData)) : null;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
class NftTrait {
|
|
190
|
+
constructor(data) {
|
|
191
|
+
this.name = data.name;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
class NftCollectionAttributesForTraitResponse {
|
|
195
|
+
constructor(data) {
|
|
196
|
+
this.updated_at = data.updated_at;
|
|
197
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftSummaryAttribute(itemData)) : null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
class NftSummaryAttribute {
|
|
201
|
+
constructor(data) {
|
|
202
|
+
this.trait_type = data.trait_type;
|
|
203
|
+
this.unique_values = data.unique_values;
|
|
204
|
+
this.values = data.values && data.values !== null ? data.values.map((itemData) => new NftAttribute(itemData)) : null;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
class NftAttribute {
|
|
208
|
+
constructor(data) {
|
|
209
|
+
this.value = data.value;
|
|
210
|
+
this.count = data.count;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
class NftCollectionTraitSummaryResponse {
|
|
214
|
+
constructor(data) {
|
|
215
|
+
this.updated_at = data.updated_at;
|
|
216
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTraitSummary(itemData)) : null;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
class NftTraitSummary {
|
|
220
|
+
constructor(data) {
|
|
221
|
+
this.name = data.name;
|
|
222
|
+
this.value_type = data.value_type;
|
|
223
|
+
this.value_numeric = data.value_numeric && data.value_numeric !== null ? new NftTraitNumeric(data.value_numeric) : null;
|
|
224
|
+
this.value_string = data.value_string && data.value_string !== null ? new NftTraitString(data.value_string) : null;
|
|
225
|
+
this.attributes = data.attributes && data.attributes !== null ? data.attributes.map((itemData) => new NftSummaryAttribute(itemData)) : null;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
class NftTraitNumeric {
|
|
229
|
+
constructor(data) {
|
|
230
|
+
this.min = data.min;
|
|
231
|
+
this.max = data.max;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
class NftTraitString {
|
|
235
|
+
constructor(data) {
|
|
236
|
+
this.value = data.value;
|
|
237
|
+
this.token_count = data.token_count;
|
|
238
|
+
this.trait_percentage = data.trait_percentage;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
class NftOwnershipForCollectionResponse {
|
|
242
|
+
constructor(data) {
|
|
243
|
+
this.updated_at = data.updated_at;
|
|
244
|
+
this.address = data.address;
|
|
245
|
+
this.collection = data.collection;
|
|
246
|
+
this.is_spam = data.is_spam;
|
|
247
|
+
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftOwnershipForCollectionItem(itemData)) : null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
class NftOwnershipForCollectionItem {
|
|
251
|
+
constructor(data) {
|
|
252
|
+
this.contract_name = data.contract_name;
|
|
253
|
+
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
254
|
+
this.contract_address = data.contract_address;
|
|
255
|
+
this.token_id = data.token_id !== null ? BigInt(data.token_id) : null;
|
|
256
|
+
this.supports_erc = data.supports_erc;
|
|
257
|
+
this.last_transfered_at = data.last_transfered_at;
|
|
258
|
+
this.balance = data.balance !== null ? BigInt(data.balance) : null;
|
|
259
|
+
this.balance24h = data.balance24h;
|
|
260
|
+
this.type = data.type;
|
|
261
|
+
this.nft_data = data.nft_data && data.nft_data !== null ? new NftData(data.nft_data) : null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* NFT APIs
|
|
266
|
+
*
|
|
267
|
+
*/
|
|
268
|
+
class Response {
|
|
269
|
+
}
|
|
270
|
+
exports.Response = Response;
|
|
271
|
+
class NftService {
|
|
272
|
+
constructor(apiKey) {
|
|
273
|
+
this.apiKey = apiKey;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
*
|
|
277
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
278
|
+
* @param {number} pageSize - Number of items on a page.
|
|
279
|
+
* @param {number} pageNumber - 0-indexed page number to begin pagination.
|
|
280
|
+
* @param {boolean} noSpam - If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`.
|
|
281
|
+
*
|
|
282
|
+
*/
|
|
283
|
+
async getChainCollections(chainName, pageSize, pageNumber, noSpam) {
|
|
284
|
+
let success = false;
|
|
285
|
+
let data;
|
|
286
|
+
let response;
|
|
287
|
+
const backoff = new backoff_1.ExponentialBackoff();
|
|
288
|
+
while (!success) {
|
|
289
|
+
try {
|
|
290
|
+
const urlParams = new URLSearchParams();
|
|
291
|
+
if (pageSize !== undefined) {
|
|
292
|
+
urlParams.append("page-size", pageSize.toString());
|
|
293
|
+
}
|
|
294
|
+
if (pageNumber !== undefined) {
|
|
295
|
+
urlParams.append("page-number", pageNumber.toString());
|
|
296
|
+
}
|
|
297
|
+
if (noSpam !== undefined) {
|
|
298
|
+
urlParams.append("no-spam", noSpam.toString());
|
|
299
|
+
}
|
|
300
|
+
response = await fetch(`https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`, {
|
|
301
|
+
headers: {
|
|
302
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
data = await response.json();
|
|
306
|
+
if (data.error && data.error_code === 429) {
|
|
307
|
+
try {
|
|
308
|
+
await backoff.backOff();
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(data);
|
|
312
|
+
success = true;
|
|
313
|
+
return {
|
|
314
|
+
data: null,
|
|
315
|
+
error: data.error,
|
|
316
|
+
error_code: data ? data.error_code : response.status,
|
|
317
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
const dataClass = new ChainCollectionResponse(data.data);
|
|
323
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
324
|
+
success = true;
|
|
325
|
+
return {
|
|
326
|
+
data: dataClass,
|
|
327
|
+
error: data.error,
|
|
328
|
+
error_code: data ? data.error_code : response.status,
|
|
329
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
success = true;
|
|
335
|
+
return {
|
|
336
|
+
data: null,
|
|
337
|
+
error: true,
|
|
338
|
+
error_code: data ? data.error_code : response.status,
|
|
339
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
*
|
|
346
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
347
|
+
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
348
|
+
* @param {boolean} noSpam - If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`.
|
|
349
|
+
* @param {boolean} noNftAssetMetadata - If `true`, the response shape is limited to a list of collections and token ids, omitting metadata and asset information. Helpful for faster response times and wallets holding a large number of NFTs.
|
|
350
|
+
* @param {boolean} withUncached - By defaut, this endpoint only works on chains where we've cached the assets and the metadata. When set to `true`, the API will fetch metadata from upstream servers even if it's not cached - the downside being that the upstream server can block or rate limit the call and therefore resulting in time outs or slow response times on the Covalent side.
|
|
351
|
+
*
|
|
352
|
+
*/
|
|
353
|
+
async getNftsForAddress(chainName, walletAddress, noSpam, noNftAssetMetadata, withUncached) {
|
|
354
|
+
let success = false;
|
|
355
|
+
let data;
|
|
356
|
+
let response;
|
|
357
|
+
const backoff = new backoff_1.ExponentialBackoff();
|
|
358
|
+
while (!success) {
|
|
359
|
+
try {
|
|
360
|
+
const urlParams = new URLSearchParams();
|
|
361
|
+
if (noSpam !== undefined) {
|
|
362
|
+
urlParams.append("no-spam", noSpam.toString());
|
|
363
|
+
}
|
|
364
|
+
if (noNftAssetMetadata !== undefined) {
|
|
365
|
+
urlParams.append("no-nft-asset-metadata", noNftAssetMetadata.toString());
|
|
366
|
+
}
|
|
367
|
+
if (withUncached !== undefined) {
|
|
368
|
+
urlParams.append("with-uncached", withUncached.toString());
|
|
369
|
+
}
|
|
370
|
+
response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`, {
|
|
371
|
+
headers: {
|
|
372
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
data = await response.json();
|
|
376
|
+
if (data.error && data.error_code === 429) {
|
|
377
|
+
try {
|
|
378
|
+
await backoff.backOff();
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(data);
|
|
382
|
+
success = true;
|
|
383
|
+
return {
|
|
384
|
+
data: null,
|
|
385
|
+
error: data.error,
|
|
386
|
+
error_code: data ? data.error_code : response.status,
|
|
387
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
const dataClass = new NftAddressBalanceNftResponse(data.data);
|
|
393
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
394
|
+
success = true;
|
|
395
|
+
return {
|
|
396
|
+
data: dataClass,
|
|
397
|
+
error: data.error,
|
|
398
|
+
error_code: data ? data.error_code : response.status,
|
|
399
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
catch (error) {
|
|
404
|
+
success = true;
|
|
405
|
+
return {
|
|
406
|
+
data: null,
|
|
407
|
+
error: true,
|
|
408
|
+
error_code: data ? data.error_code : response.status,
|
|
409
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
*
|
|
416
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
417
|
+
* @param {string} contractAddress - The requested NFT contract. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
418
|
+
* @param {boolean} noMetadata - Omit metadata.
|
|
419
|
+
* @param {number} pageSize - Number of items on a page.
|
|
420
|
+
* @param {number} pageNumber - 0-indexed page number to begin pagination.
|
|
421
|
+
* @param {string} traitsFilter - Filters NFTs based on a specific trait. If this filter is used, the API will return all NFTs with the specified trait. Accepts comma-separated values, is case-sensitive, and requires proper URL encoding.
|
|
422
|
+
* @param {string} valuesFilter - Filters NFTs based on a specific trait value. If this filter is used, the API will return all NFTs with the specified trait value. If used with "traits-filter", only NFTs matching both filters will be returned. Accepts comma-separated values, is case-sensitive, and requires proper URL encoding.
|
|
423
|
+
* @param {boolean} withUncached - By defaut, this endpoint only works on chains where we've cached the assets and the metadata. When set to `true`, the API will fetch metadata from upstream servers even if it's not cached - the downside being that the upstream server can block or rate limit the call and therefore resulting in time outs or slow response times on the Covalent side.
|
|
424
|
+
*
|
|
425
|
+
*/
|
|
426
|
+
async getTokenIdsForContractWithMetadata(chainName, contractAddress, noMetadata, pageSize, pageNumber, traitsFilter, valuesFilter, withUncached) {
|
|
427
|
+
let success = false;
|
|
428
|
+
let data;
|
|
429
|
+
let response;
|
|
430
|
+
const backoff = new backoff_1.ExponentialBackoff();
|
|
431
|
+
while (!success) {
|
|
432
|
+
try {
|
|
433
|
+
const urlParams = new URLSearchParams();
|
|
434
|
+
if (noMetadata !== undefined) {
|
|
435
|
+
urlParams.append("no-metadata", noMetadata.toString());
|
|
436
|
+
}
|
|
437
|
+
if (pageSize !== undefined) {
|
|
438
|
+
urlParams.append("page-size", pageSize.toString());
|
|
439
|
+
}
|
|
440
|
+
if (pageNumber !== undefined) {
|
|
441
|
+
urlParams.append("page-number", pageNumber.toString());
|
|
442
|
+
}
|
|
443
|
+
if (traitsFilter !== undefined) {
|
|
444
|
+
urlParams.append("traits-filter", traitsFilter.toString());
|
|
445
|
+
}
|
|
446
|
+
if (valuesFilter !== undefined) {
|
|
447
|
+
urlParams.append("values-filter", valuesFilter.toString());
|
|
448
|
+
}
|
|
449
|
+
if (withUncached !== undefined) {
|
|
450
|
+
urlParams.append("with-uncached", withUncached.toString());
|
|
451
|
+
}
|
|
452
|
+
response = await fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`, {
|
|
453
|
+
headers: {
|
|
454
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
data = await response.json();
|
|
458
|
+
if (data.error && data.error_code === 429) {
|
|
459
|
+
try {
|
|
460
|
+
await backoff.backOff();
|
|
461
|
+
}
|
|
462
|
+
catch (error) {
|
|
463
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(data);
|
|
464
|
+
success = true;
|
|
465
|
+
return {
|
|
466
|
+
data: null,
|
|
467
|
+
error: data.error,
|
|
468
|
+
error_code: data ? data.error_code : response.status,
|
|
469
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
const dataClass = new NftMetadataResponse(data.data);
|
|
475
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
476
|
+
success = true;
|
|
477
|
+
return {
|
|
478
|
+
data: dataClass,
|
|
479
|
+
error: data.error,
|
|
480
|
+
error_code: data ? data.error_code : response.status,
|
|
481
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
catch (error) {
|
|
486
|
+
success = true;
|
|
487
|
+
return {
|
|
488
|
+
data: null,
|
|
489
|
+
error: true,
|
|
490
|
+
error_code: data ? data.error_code : response.status,
|
|
491
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
*
|
|
498
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
499
|
+
* @param {string} contractAddress - The requested NFT contract. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
500
|
+
* @param {boolean} noMetadata - Omit metadata.
|
|
501
|
+
* @param {boolean} withUncached - By defaut, this endpoint only works on chains where we've cached the assets and the metadata. When set to `true`, the API will fetch metadata from upstream servers even if it's not cached - the downside being that the upstream server can block or rate limit the call and therefore resulting in time outs or slow response times on the Covalent side.
|
|
502
|
+
* @param {string} tokenId - The requested token ID.
|
|
503
|
+
*
|
|
504
|
+
*/
|
|
505
|
+
async getNftMetadataForGivenTokenIDForContract(chainName, contractAddress, tokenId, noMetadata, withUncached) {
|
|
506
|
+
let success = false;
|
|
507
|
+
let data;
|
|
508
|
+
let response;
|
|
509
|
+
const backoff = new backoff_1.ExponentialBackoff();
|
|
510
|
+
while (!success) {
|
|
511
|
+
try {
|
|
512
|
+
const urlParams = new URLSearchParams();
|
|
513
|
+
if (noMetadata !== undefined) {
|
|
514
|
+
urlParams.append("no-metadata", noMetadata.toString());
|
|
515
|
+
}
|
|
516
|
+
if (withUncached !== undefined) {
|
|
517
|
+
urlParams.append("with-uncached", withUncached.toString());
|
|
518
|
+
}
|
|
519
|
+
response = await fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`, {
|
|
520
|
+
headers: {
|
|
521
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
data = await response.json();
|
|
525
|
+
if (data.error && data.error_code === 429) {
|
|
526
|
+
try {
|
|
527
|
+
await backoff.backOff();
|
|
528
|
+
}
|
|
529
|
+
catch (error) {
|
|
530
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(data);
|
|
531
|
+
success = true;
|
|
532
|
+
return {
|
|
533
|
+
data: null,
|
|
534
|
+
error: data.error,
|
|
535
|
+
error_code: data ? data.error_code : response.status,
|
|
536
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
const dataClass = new NftMetadataResponse(data.data);
|
|
542
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
543
|
+
success = true;
|
|
544
|
+
return {
|
|
545
|
+
data: dataClass,
|
|
546
|
+
error: data.error,
|
|
547
|
+
error_code: data ? data.error_code : response.status,
|
|
548
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
catch (error) {
|
|
553
|
+
success = true;
|
|
554
|
+
return {
|
|
555
|
+
data: null,
|
|
556
|
+
error: true,
|
|
557
|
+
error_code: data ? data.error_code : response.status,
|
|
558
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
*
|
|
565
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
566
|
+
* @param {string} contractAddress - The requested NFT contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
567
|
+
* @param {string} tokenId - The requested token ID.
|
|
568
|
+
* @param {boolean} noSpam - If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`.
|
|
569
|
+
*
|
|
570
|
+
*/
|
|
571
|
+
async getNftTransactionsForContractTokenId(chainName, contractAddress, tokenId, noSpam) {
|
|
572
|
+
let success = false;
|
|
573
|
+
let data;
|
|
574
|
+
let response;
|
|
575
|
+
const backoff = new backoff_1.ExponentialBackoff();
|
|
576
|
+
while (!success) {
|
|
577
|
+
try {
|
|
578
|
+
const urlParams = new URLSearchParams();
|
|
579
|
+
if (noSpam !== undefined) {
|
|
580
|
+
urlParams.append("no-spam", noSpam.toString());
|
|
581
|
+
}
|
|
582
|
+
response = await fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`, {
|
|
583
|
+
headers: {
|
|
584
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
data = await response.json();
|
|
588
|
+
if (data.error && data.error_code === 429) {
|
|
589
|
+
try {
|
|
590
|
+
await backoff.backOff();
|
|
591
|
+
}
|
|
592
|
+
catch (error) {
|
|
593
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(data);
|
|
594
|
+
success = true;
|
|
595
|
+
return {
|
|
596
|
+
data: null,
|
|
597
|
+
error: data.error,
|
|
598
|
+
error_code: data ? data.error_code : response.status,
|
|
599
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
const dataClass = new NftTransactionsResponse(data.data);
|
|
605
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
606
|
+
success = true;
|
|
607
|
+
return {
|
|
608
|
+
data: dataClass,
|
|
609
|
+
error: data.error,
|
|
610
|
+
error_code: data ? data.error_code : response.status,
|
|
611
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
catch (error) {
|
|
616
|
+
success = true;
|
|
617
|
+
return {
|
|
618
|
+
data: null,
|
|
619
|
+
error: true,
|
|
620
|
+
error_code: data ? data.error_code : response.status,
|
|
621
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
*
|
|
628
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
629
|
+
* @param {string} collectionContract - The requested collection address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
630
|
+
*
|
|
631
|
+
*/
|
|
632
|
+
async getTraitsForCollection(chainName, collectionContract) {
|
|
633
|
+
let success = false;
|
|
634
|
+
let data;
|
|
635
|
+
let response;
|
|
636
|
+
const backoff = new backoff_1.ExponentialBackoff();
|
|
637
|
+
while (!success) {
|
|
638
|
+
try {
|
|
639
|
+
const urlParams = new URLSearchParams();
|
|
640
|
+
response = await fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`, {
|
|
641
|
+
headers: {
|
|
642
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
data = await response.json();
|
|
646
|
+
if (data.error && data.error_code === 429) {
|
|
647
|
+
try {
|
|
648
|
+
await backoff.backOff();
|
|
649
|
+
}
|
|
650
|
+
catch (error) {
|
|
651
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(data);
|
|
652
|
+
success = true;
|
|
653
|
+
return {
|
|
654
|
+
data: null,
|
|
655
|
+
error: data.error,
|
|
656
|
+
error_code: data ? data.error_code : response.status,
|
|
657
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
const dataClass = new NftCollectionTraitsResponse(data.data);
|
|
663
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
664
|
+
success = true;
|
|
665
|
+
return {
|
|
666
|
+
data: dataClass,
|
|
667
|
+
error: data.error,
|
|
668
|
+
error_code: data ? data.error_code : response.status,
|
|
669
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
catch (error) {
|
|
674
|
+
success = true;
|
|
675
|
+
return {
|
|
676
|
+
data: null,
|
|
677
|
+
error: true,
|
|
678
|
+
error_code: data ? data.error_code : response.status,
|
|
679
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
*
|
|
686
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
687
|
+
* @param {string} collectionContract - The requested collection address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
688
|
+
* @param {string} trait - The requested trait.
|
|
689
|
+
*
|
|
690
|
+
*/
|
|
691
|
+
async getAttributesForTraitInCollection(chainName, collectionContract, trait) {
|
|
692
|
+
let success = false;
|
|
693
|
+
let data;
|
|
694
|
+
let response;
|
|
695
|
+
const backoff = new backoff_1.ExponentialBackoff();
|
|
696
|
+
while (!success) {
|
|
697
|
+
try {
|
|
698
|
+
const urlParams = new URLSearchParams();
|
|
699
|
+
response = await fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`, {
|
|
700
|
+
headers: {
|
|
701
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
data = await response.json();
|
|
705
|
+
if (data.error && data.error_code === 429) {
|
|
706
|
+
try {
|
|
707
|
+
await backoff.backOff();
|
|
708
|
+
}
|
|
709
|
+
catch (error) {
|
|
710
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(data);
|
|
711
|
+
success = true;
|
|
712
|
+
return {
|
|
713
|
+
data: null,
|
|
714
|
+
error: data.error,
|
|
715
|
+
error_code: data ? data.error_code : response.status,
|
|
716
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
else {
|
|
721
|
+
const dataClass = new NftCollectionAttributesForTraitResponse(data.data);
|
|
722
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
723
|
+
success = true;
|
|
724
|
+
return {
|
|
725
|
+
data: dataClass,
|
|
726
|
+
error: data.error,
|
|
727
|
+
error_code: data ? data.error_code : response.status,
|
|
728
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
catch (error) {
|
|
733
|
+
success = true;
|
|
734
|
+
return {
|
|
735
|
+
data: null,
|
|
736
|
+
error: true,
|
|
737
|
+
error_code: data ? data.error_code : response.status,
|
|
738
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
*
|
|
745
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
746
|
+
* @param {string} collectionContract - The requested collection address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
747
|
+
*
|
|
748
|
+
*/
|
|
749
|
+
async getCollectionTraitsSummary(chainName, collectionContract) {
|
|
750
|
+
let success = false;
|
|
751
|
+
let data;
|
|
752
|
+
let response;
|
|
753
|
+
const backoff = new backoff_1.ExponentialBackoff();
|
|
754
|
+
while (!success) {
|
|
755
|
+
try {
|
|
756
|
+
const urlParams = new URLSearchParams();
|
|
757
|
+
response = await fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`, {
|
|
758
|
+
headers: {
|
|
759
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
data = await response.json();
|
|
763
|
+
if (data.error && data.error_code === 429) {
|
|
764
|
+
try {
|
|
765
|
+
await backoff.backOff();
|
|
766
|
+
}
|
|
767
|
+
catch (error) {
|
|
768
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(data);
|
|
769
|
+
success = true;
|
|
770
|
+
return {
|
|
771
|
+
data: null,
|
|
772
|
+
error: data.error,
|
|
773
|
+
error_code: data ? data.error_code : response.status,
|
|
774
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
else {
|
|
779
|
+
const dataClass = new NftCollectionTraitSummaryResponse(data.data);
|
|
780
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
781
|
+
success = true;
|
|
782
|
+
return {
|
|
783
|
+
data: dataClass,
|
|
784
|
+
error: data.error,
|
|
785
|
+
error_code: data ? data.error_code : response.status,
|
|
786
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
catch (error) {
|
|
791
|
+
success = true;
|
|
792
|
+
return {
|
|
793
|
+
data: null,
|
|
794
|
+
error: true,
|
|
795
|
+
error_code: data ? data.error_code : response.status,
|
|
796
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
*
|
|
803
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
804
|
+
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
805
|
+
* @param {string} collectionContract - The requested collection address.
|
|
806
|
+
*
|
|
807
|
+
*/
|
|
808
|
+
async checkOwnershipInNft(chainName, walletAddress, collectionContract) {
|
|
809
|
+
let success = false;
|
|
810
|
+
let data;
|
|
811
|
+
let response;
|
|
812
|
+
const backoff = new backoff_1.ExponentialBackoff();
|
|
813
|
+
while (!success) {
|
|
814
|
+
try {
|
|
815
|
+
const urlParams = new URLSearchParams();
|
|
816
|
+
response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`, {
|
|
817
|
+
headers: {
|
|
818
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
data = await response.json();
|
|
822
|
+
if (data.error && data.error_code === 429) {
|
|
823
|
+
try {
|
|
824
|
+
await backoff.backOff();
|
|
825
|
+
}
|
|
826
|
+
catch (error) {
|
|
827
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(data);
|
|
828
|
+
success = true;
|
|
829
|
+
return {
|
|
830
|
+
data: null,
|
|
831
|
+
error: data.error,
|
|
832
|
+
error_code: data ? data.error_code : response.status,
|
|
833
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
else {
|
|
838
|
+
const dataClass = new NftOwnershipForCollectionResponse(data.data);
|
|
839
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
840
|
+
success = true;
|
|
841
|
+
return {
|
|
842
|
+
data: dataClass,
|
|
843
|
+
error: data.error,
|
|
844
|
+
error_code: data ? data.error_code : response.status,
|
|
845
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
catch (error) {
|
|
850
|
+
success = true;
|
|
851
|
+
return {
|
|
852
|
+
data: null,
|
|
853
|
+
error: true,
|
|
854
|
+
error_code: data ? data.error_code : response.status,
|
|
855
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
*
|
|
862
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
863
|
+
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
864
|
+
* @param {string} collectionContract - The requested collection address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
865
|
+
* @param {string} tokenId - The requested token ID.
|
|
866
|
+
*
|
|
867
|
+
*/
|
|
868
|
+
async checkOwnershipInNftForSpecificTokenId(chainName, walletAddress, collectionContract, tokenId) {
|
|
869
|
+
let success = false;
|
|
870
|
+
let data;
|
|
871
|
+
let response;
|
|
872
|
+
const backoff = new backoff_1.ExponentialBackoff();
|
|
873
|
+
while (!success) {
|
|
874
|
+
try {
|
|
875
|
+
const urlParams = new URLSearchParams();
|
|
876
|
+
response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`, {
|
|
877
|
+
headers: {
|
|
878
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
data = await response.json();
|
|
882
|
+
if (data.error && data.error_code === 429) {
|
|
883
|
+
try {
|
|
884
|
+
await backoff.backOff();
|
|
885
|
+
}
|
|
886
|
+
catch (error) {
|
|
887
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(data);
|
|
888
|
+
success = true;
|
|
889
|
+
return {
|
|
890
|
+
data: null,
|
|
891
|
+
error: data.error,
|
|
892
|
+
error_code: data ? data.error_code : response.status,
|
|
893
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
else {
|
|
898
|
+
const dataClass = new NftOwnershipForCollectionResponse(data.data);
|
|
899
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
900
|
+
success = true;
|
|
901
|
+
return {
|
|
902
|
+
data: dataClass,
|
|
903
|
+
error: data.error,
|
|
904
|
+
error_code: data ? data.error_code : response.status,
|
|
905
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
catch (error) {
|
|
910
|
+
success = true;
|
|
911
|
+
return {
|
|
912
|
+
data: null,
|
|
913
|
+
error: true,
|
|
914
|
+
error_code: data ? data.error_code : response.status,
|
|
915
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
*
|
|
922
|
+
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
923
|
+
* @param {string} contractAddress - The requested NFT contract. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
924
|
+
* @param {string} tokenId - The requested token ID.
|
|
925
|
+
*
|
|
926
|
+
*/
|
|
927
|
+
async getNftExternalMetadataForContract(chainName, contractAddress, tokenId) {
|
|
928
|
+
let success = false;
|
|
929
|
+
let data;
|
|
930
|
+
let response;
|
|
931
|
+
const backoff = new backoff_1.ExponentialBackoff();
|
|
932
|
+
while (!success) {
|
|
933
|
+
try {
|
|
934
|
+
const urlParams = new URLSearchParams();
|
|
935
|
+
response = await fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_metadata/${tokenId}/?${urlParams}`, {
|
|
936
|
+
headers: {
|
|
937
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
data = await response.json();
|
|
941
|
+
if (data.error && data.error_code === 429) {
|
|
942
|
+
try {
|
|
943
|
+
await backoff.backOff();
|
|
944
|
+
}
|
|
945
|
+
catch (error) {
|
|
946
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(data);
|
|
947
|
+
success = true;
|
|
948
|
+
return {
|
|
949
|
+
data: null,
|
|
950
|
+
error: data.error,
|
|
951
|
+
error_code: data ? data.error_code : response.status,
|
|
952
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
else {
|
|
957
|
+
const dataClass = new NftMetadataResponse(data.data);
|
|
958
|
+
(0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
|
|
959
|
+
success = true;
|
|
960
|
+
return {
|
|
961
|
+
data: dataClass,
|
|
962
|
+
error: data.error,
|
|
963
|
+
error_code: data ? data.error_code : response.status,
|
|
964
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
catch (error) {
|
|
969
|
+
success = true;
|
|
970
|
+
return {
|
|
971
|
+
data: null,
|
|
972
|
+
error: true,
|
|
973
|
+
error_code: data ? data.error_code : response.status,
|
|
974
|
+
error_message: data ? data.error_message : "401 Authorization Required"
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
exports.NftService = NftService;
|
|
981
|
+
//# sourceMappingURL=NftService.js.map
|