@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.
- package/LICENSE +201 -0
- package/README.md +223 -282
- package/package.json +25 -12
- package/dist/cjs/index.d.ts +0 -20
- package/dist/cjs/index.js +0 -8190
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/services/BalanceService.d.ts +0 -638
- package/dist/cjs/services/BaseService.d.ts +0 -571
- package/dist/cjs/services/CovalentClient.d.ts +0 -57
- package/dist/cjs/services/NftService.d.ts +0 -686
- package/dist/cjs/services/PricingService.d.ts +0 -103
- package/dist/cjs/services/SecurityService.d.ts +0 -162
- package/dist/cjs/services/TransactionService.d.ts +0 -711
- package/dist/cjs/services/XykService.d.ts +0 -1018
- package/dist/cjs/util/ApiHelpers.d.ts +0 -6
- package/dist/cjs/util/ApiKeyValidator.d.ts +0 -8
- package/dist/cjs/util/CalculatePrettyBalance.d.ts +0 -1
- package/dist/cjs/util/Chains.d.ts +0 -223
- package/dist/cjs/util/backoff.d.ts +0 -12
- package/dist/cjs/util/prettifyCurrency.d.ts +0 -2
- package/dist/cjs/util/types/BalanceServiceTypes.d.ts +0 -378
- package/dist/cjs/util/types/BaseServiceTypes.d.ts +0 -276
- package/dist/cjs/util/types/GenericTypes.d.ts +0 -116
- package/dist/cjs/util/types/NftServiceTypes.d.ts +0 -303
- package/dist/cjs/util/types/PricingServiceTypes.d.ts +0 -33
- package/dist/cjs/util/types/SecurityServiceTypes.d.ts +0 -121
- package/dist/cjs/util/types/TransactionServiceTypes.d.ts +0 -388
- package/dist/cjs/util/types/XykServiceTypes.d.ts +0 -687
- package/dist/es/index.d.ts +0 -20
- package/dist/es/index.js +0 -8176
- package/dist/es/index.js.map +0 -1
- package/dist/es/services/BalanceService.d.ts +0 -638
- package/dist/es/services/BaseService.d.ts +0 -571
- package/dist/es/services/CovalentClient.d.ts +0 -57
- package/dist/es/services/NftService.d.ts +0 -686
- package/dist/es/services/PricingService.d.ts +0 -103
- package/dist/es/services/SecurityService.d.ts +0 -162
- package/dist/es/services/TransactionService.d.ts +0 -711
- package/dist/es/services/XykService.d.ts +0 -1018
- package/dist/es/util/ApiHelpers.d.ts +0 -6
- package/dist/es/util/ApiKeyValidator.d.ts +0 -8
- package/dist/es/util/CalculatePrettyBalance.d.ts +0 -1
- package/dist/es/util/Chains.d.ts +0 -223
- package/dist/es/util/backoff.d.ts +0 -12
- package/dist/es/util/prettifyCurrency.d.ts +0 -2
- package/dist/es/util/types/BalanceServiceTypes.d.ts +0 -378
- package/dist/es/util/types/BaseServiceTypes.d.ts +0 -276
- package/dist/es/util/types/GenericTypes.d.ts +0 -116
- package/dist/es/util/types/NftServiceTypes.d.ts +0 -303
- package/dist/es/util/types/PricingServiceTypes.d.ts +0 -33
- package/dist/es/util/types/SecurityServiceTypes.d.ts +0 -121
- package/dist/es/util/types/TransactionServiceTypes.d.ts +0 -388
- package/dist/es/util/types/XykServiceTypes.d.ts +0 -687
- package/dist/esm/index.d.ts +0 -20
- package/dist/esm/index.js +0 -8176
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/services/BalanceService.d.ts +0 -638
- package/dist/esm/services/BaseService.d.ts +0 -571
- package/dist/esm/services/CovalentClient.d.ts +0 -57
- package/dist/esm/services/NftService.d.ts +0 -686
- package/dist/esm/services/PricingService.d.ts +0 -103
- package/dist/esm/services/SecurityService.d.ts +0 -162
- package/dist/esm/services/TransactionService.d.ts +0 -711
- package/dist/esm/services/XykService.d.ts +0 -1018
- package/dist/esm/util/ApiHelpers.d.ts +0 -6
- package/dist/esm/util/ApiKeyValidator.d.ts +0 -8
- package/dist/esm/util/CalculatePrettyBalance.d.ts +0 -1
- package/dist/esm/util/Chains.d.ts +0 -223
- package/dist/esm/util/backoff.d.ts +0 -12
- package/dist/esm/util/prettifyCurrency.d.ts +0 -2
- package/dist/esm/util/types/BalanceServiceTypes.d.ts +0 -378
- package/dist/esm/util/types/BaseServiceTypes.d.ts +0 -276
- package/dist/esm/util/types/GenericTypes.d.ts +0 -116
- package/dist/esm/util/types/NftServiceTypes.d.ts +0 -303
- package/dist/esm/util/types/PricingServiceTypes.d.ts +0 -33
- package/dist/esm/util/types/SecurityServiceTypes.d.ts +0 -121
- package/dist/esm/util/types/TransactionServiceTypes.d.ts +0 -388
- package/dist/esm/util/types/XykServiceTypes.d.ts +0 -687
- package/dist/index.d.ts +0 -20
- package/dist/index.js +0 -21
- package/dist/index.js.map +0 -1
- package/dist/services/BalanceService.d.ts +0 -638
- package/dist/services/BalanceService.js +0 -959
- package/dist/services/BalanceService.js.map +0 -1
- package/dist/services/BaseService.d.ts +0 -571
- package/dist/services/BaseService.js +0 -1202
- package/dist/services/BaseService.js.map +0 -1
- package/dist/services/CovalentClient.d.ts +0 -57
- package/dist/services/CovalentClient.js +0 -49
- package/dist/services/CovalentClient.js.map +0 -1
- package/dist/services/NftService.d.ts +0 -686
- package/dist/services/NftService.js +0 -1490
- package/dist/services/NftService.js.map +0 -1
- package/dist/services/PricingService.d.ts +0 -103
- package/dist/services/PricingService.js +0 -155
- package/dist/services/PricingService.js.map +0 -1
- package/dist/services/SecurityService.d.ts +0 -162
- package/dist/services/SecurityService.js +0 -249
- package/dist/services/SecurityService.js.map +0 -1
- package/dist/services/TransactionService.d.ts +0 -711
- package/dist/services/TransactionService.js +0 -1687
- package/dist/services/TransactionService.js.map +0 -1
- package/dist/services/XykService.d.ts +0 -1018
- package/dist/services/XykService.js +0 -1827
- package/dist/services/XykService.js.map +0 -1
- package/dist/util/ApiHelpers.d.ts +0 -6
- package/dist/util/ApiHelpers.js +0 -87
- package/dist/util/ApiHelpers.js.map +0 -1
- package/dist/util/ApiKeyValidator.d.ts +0 -8
- package/dist/util/ApiKeyValidator.js +0 -13
- package/dist/util/ApiKeyValidator.js.map +0 -1
- package/dist/util/CalculatePrettyBalance.d.ts +0 -1
- package/dist/util/CalculatePrettyBalance.js +0 -32
- package/dist/util/CalculatePrettyBalance.js.map +0 -1
- package/dist/util/Chains.d.ts +0 -223
- package/dist/util/Chains.js +0 -225
- package/dist/util/Chains.js.map +0 -1
- package/dist/util/backoff.d.ts +0 -12
- package/dist/util/backoff.js +0 -47
- package/dist/util/backoff.js.map +0 -1
- package/dist/util/prettifyCurrency.d.ts +0 -2
- package/dist/util/prettifyCurrency.js +0 -69
- package/dist/util/prettifyCurrency.js.map +0 -1
- package/dist/util/types/BalanceServiceTypes.d.ts +0 -378
- package/dist/util/types/BalanceServiceTypes.js +0 -2
- package/dist/util/types/BalanceServiceTypes.js.map +0 -1
- package/dist/util/types/BaseServiceTypes.d.ts +0 -276
- package/dist/util/types/BaseServiceTypes.js +0 -2
- package/dist/util/types/BaseServiceTypes.js.map +0 -1
- package/dist/util/types/GenericTypes.d.ts +0 -116
- package/dist/util/types/GenericTypes.js +0 -2
- package/dist/util/types/GenericTypes.js.map +0 -1
- package/dist/util/types/NftServiceTypes.d.ts +0 -303
- package/dist/util/types/NftServiceTypes.js +0 -2
- package/dist/util/types/NftServiceTypes.js.map +0 -1
- package/dist/util/types/PricingServiceTypes.d.ts +0 -33
- package/dist/util/types/PricingServiceTypes.js +0 -2
- package/dist/util/types/PricingServiceTypes.js.map +0 -1
- package/dist/util/types/SecurityServiceTypes.d.ts +0 -121
- package/dist/util/types/SecurityServiceTypes.js +0 -2
- package/dist/util/types/SecurityServiceTypes.js.map +0 -1
- package/dist/util/types/TransactionServiceTypes.d.ts +0 -388
- package/dist/util/types/TransactionServiceTypes.js +0 -2
- package/dist/util/types/TransactionServiceTypes.js.map +0 -1
- package/dist/util/types/XykServiceTypes.d.ts +0 -687
- package/dist/util/types/XykServiceTypes.js +0 -2
- package/dist/util/types/XykServiceTypes.js.map +0 -1
|
@@ -1,1490 +0,0 @@
|
|
|
1
|
-
import { userAgent } from "./CovalentClient";
|
|
2
|
-
import { debugOutput, paginateEndpoint } from "../util/ApiHelpers";
|
|
3
|
-
import { parseISO } from "date-fns";
|
|
4
|
-
import { ExponentialBackoff } from "../util/backoff";
|
|
5
|
-
import pLimit from "p-limit";
|
|
6
|
-
import { ApiKeyValidator } from "../util/ApiKeyValidator";
|
|
7
|
-
class ChainCollectionResponse {
|
|
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 ChainCollectionItem(itemData)) : null;
|
|
13
|
-
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
class ChainCollectionItem {
|
|
17
|
-
constructor(data) {
|
|
18
|
-
this.contract_address = data.contract_address;
|
|
19
|
-
this.contract_name = data.contract_name;
|
|
20
|
-
this.is_spam = data.is_spam;
|
|
21
|
-
this.token_total_supply = data.token_total_supply;
|
|
22
|
-
this.cached_metadata_count = data.cached_metadata_count;
|
|
23
|
-
this.cached_asset_count = data.cached_asset_count;
|
|
24
|
-
this.last_scraped_at = data.last_scraped_at && data.last_scraped_at !== null ? parseISO(data.last_scraped_at.toString()) : null;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
class Pagination {
|
|
28
|
-
constructor(data) {
|
|
29
|
-
this.has_more = data.has_more;
|
|
30
|
-
this.page_number = data.page_number;
|
|
31
|
-
this.page_size = data.page_size;
|
|
32
|
-
this.total_count = data.total_count;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
class NftAddressBalanceNftResponse {
|
|
36
|
-
constructor(data) {
|
|
37
|
-
this.address = data.address;
|
|
38
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
39
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTokenContractBalanceItem(itemData)) : null;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
class NftTokenContractBalanceItem {
|
|
43
|
-
constructor(data) {
|
|
44
|
-
this.contract_name = data.contract_name;
|
|
45
|
-
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
46
|
-
this.contract_address = data.contract_address;
|
|
47
|
-
this.supports_erc = data.supports_erc;
|
|
48
|
-
this.is_spam = data.is_spam;
|
|
49
|
-
this.last_transfered_at = data.last_transfered_at && data.last_transfered_at !== null ? parseISO(data.last_transfered_at.toString()) : null;
|
|
50
|
-
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
51
|
-
this.balance_24h = data.balance_24h;
|
|
52
|
-
this.type = data.type;
|
|
53
|
-
this.floor_price_quote = data.floor_price_quote;
|
|
54
|
-
this.pretty_floor_price_quote = data.pretty_floor_price_quote;
|
|
55
|
-
this.floor_price_native_quote = data.floor_price_native_quote;
|
|
56
|
-
this.nft_data = data.nft_data && data.nft_data !== null ? data.nft_data.map((itemData) => new NftData(itemData)) : null;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
class NftData {
|
|
60
|
-
constructor(data) {
|
|
61
|
-
this.token_id = data.token_id && data.token_id !== null ? BigInt(data.token_id) : null;
|
|
62
|
-
this.token_url = data.token_url;
|
|
63
|
-
this.original_owner = data.original_owner;
|
|
64
|
-
this.current_owner = data.current_owner;
|
|
65
|
-
this.asset_cached = data.asset_cached;
|
|
66
|
-
this.image_cached = data.image_cached;
|
|
67
|
-
this.external_data = data.external_data && data.external_data !== null ? new NftExternalData(data.external_data) : null;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
class NftExternalData {
|
|
71
|
-
constructor(data) {
|
|
72
|
-
this.name = data.name;
|
|
73
|
-
this.description = data.description;
|
|
74
|
-
this.asset_url = data.asset_url;
|
|
75
|
-
this.asset_file_extension = data.asset_file_extension;
|
|
76
|
-
this.asset_mime_type = data.asset_mime_type;
|
|
77
|
-
this.asset_size_bytes = data.asset_size_bytes;
|
|
78
|
-
this.image = data.image;
|
|
79
|
-
this.image_256 = data.image_256;
|
|
80
|
-
this.image_512 = data.image_512;
|
|
81
|
-
this.image_1024 = data.image_1024;
|
|
82
|
-
this.animation_url = data.animation_url;
|
|
83
|
-
this.external_url = data.external_url;
|
|
84
|
-
this.attributes = data.attributes && data.attributes !== null ? data.attributes.map((itemData) => new NftCollectionAttribute(itemData)) : null;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
class NftCollectionAttribute {
|
|
88
|
-
constructor(data) {
|
|
89
|
-
this.trait_type = data.trait_type;
|
|
90
|
-
this.value = data.value;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
class NftMetadataResponse {
|
|
94
|
-
constructor(data) {
|
|
95
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
96
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTokenContract(itemData)) : null;
|
|
97
|
-
this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
class NftTokenContract {
|
|
101
|
-
constructor(data) {
|
|
102
|
-
this.contract_name = data.contract_name;
|
|
103
|
-
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
104
|
-
this.contract_address = data.contract_address;
|
|
105
|
-
this.is_spam = data.is_spam;
|
|
106
|
-
this.type = data.type;
|
|
107
|
-
this.nft_data = data.nft_data && data.nft_data !== null ? new NftData(data.nft_data) : null;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
class NftTransactionsResponse {
|
|
111
|
-
constructor(data) {
|
|
112
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
113
|
-
this.chain_id = data.chain_id;
|
|
114
|
-
this.chain_name = data.chain_name;
|
|
115
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTransaction(itemData)) : null;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
class NftTransaction {
|
|
119
|
-
constructor(data) {
|
|
120
|
-
this.contract_decimals = data.contract_decimals;
|
|
121
|
-
this.contract_name = data.contract_name;
|
|
122
|
-
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
123
|
-
this.logo_url = data.logo_url;
|
|
124
|
-
this.contract_address = data.contract_address;
|
|
125
|
-
this.supports_erc = data.supports_erc;
|
|
126
|
-
this.is_spam = data.is_spam;
|
|
127
|
-
this.nft_transactions = data.nft_transactions && data.nft_transactions !== null ? data.nft_transactions.map((itemData) => new NftTransactionItem(itemData)) : null;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
class NftTransactionItem {
|
|
131
|
-
constructor(data) {
|
|
132
|
-
this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
|
|
133
|
-
this.block_height = data.block_height;
|
|
134
|
-
this.tx_hash = data.tx_hash;
|
|
135
|
-
this.tx_offset = data.tx_offset;
|
|
136
|
-
this.successful = data.successful;
|
|
137
|
-
this.from_address = data.from_address;
|
|
138
|
-
this.from_address_label = data.from_address_label;
|
|
139
|
-
this.to_address = data.to_address;
|
|
140
|
-
this.to_address_label = data.to_address_label;
|
|
141
|
-
this.value = data.value && data.value !== null ? BigInt(data.value) : null;
|
|
142
|
-
this.value_quote = data.value_quote;
|
|
143
|
-
this.pretty_value_quote = data.pretty_value_quote;
|
|
144
|
-
this.gas_offered = data.gas_offered;
|
|
145
|
-
this.gas_spent = data.gas_spent;
|
|
146
|
-
this.gas_price = data.gas_price;
|
|
147
|
-
this.fees_paid = data.fees_paid && data.fees_paid !== null ? BigInt(data.fees_paid) : null;
|
|
148
|
-
this.gas_quote = data.gas_quote;
|
|
149
|
-
this.pretty_gas_quote = data.pretty_gas_quote;
|
|
150
|
-
this.gas_quote_rate = data.gas_quote_rate;
|
|
151
|
-
this.log_events = data.log_events && data.log_events !== null ? data.log_events.map((itemData) => new LogEvent(itemData)) : null;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
class LogEvent {
|
|
155
|
-
constructor(data) {
|
|
156
|
-
this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
|
|
157
|
-
this.block_height = data.block_height;
|
|
158
|
-
this.tx_offset = data.tx_offset;
|
|
159
|
-
this.log_offset = data.log_offset;
|
|
160
|
-
this.tx_hash = data.tx_hash;
|
|
161
|
-
this.raw_log_topics = data.raw_log_topics;
|
|
162
|
-
this.sender_contract_decimals = data.sender_contract_decimals;
|
|
163
|
-
this.sender_name = data.sender_name;
|
|
164
|
-
this.sender_contract_ticker_symbol = data.sender_contract_ticker_symbol;
|
|
165
|
-
this.sender_address = data.sender_address;
|
|
166
|
-
this.sender_address_label = data.sender_address_label;
|
|
167
|
-
this.sender_logo_url = data.sender_logo_url;
|
|
168
|
-
this.supports_erc = data.supports_erc;
|
|
169
|
-
this.sender_factory_address = data.sender_factory_address;
|
|
170
|
-
this.raw_log_data = data.raw_log_data;
|
|
171
|
-
this.decoded = data.decoded && data.decoded !== null ? new DecodedItem(data.decoded) : null;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
class DecodedItem {
|
|
175
|
-
constructor(data) {
|
|
176
|
-
this.name = data.name;
|
|
177
|
-
this.signature = data.signature;
|
|
178
|
-
this.params = data.params && data.params !== null ? data.params.map((itemData) => new Param(itemData)) : null;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
class Param {
|
|
182
|
-
constructor(data) {
|
|
183
|
-
this.name = data.name;
|
|
184
|
-
this.type = data.type;
|
|
185
|
-
this.indexed = data.indexed;
|
|
186
|
-
this.decoded = data.decoded;
|
|
187
|
-
this.value = data.value;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
class NftCollectionTraitsResponse {
|
|
191
|
-
constructor(data) {
|
|
192
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
193
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTrait(itemData)) : null;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
class NftTrait {
|
|
197
|
-
constructor(data) {
|
|
198
|
-
this.name = data.name;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
class NftCollectionAttributesForTraitResponse {
|
|
202
|
-
constructor(data) {
|
|
203
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
204
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftSummaryAttribute(itemData)) : null;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
class NftSummaryAttribute {
|
|
208
|
-
constructor(data) {
|
|
209
|
-
this.trait_type = data.trait_type;
|
|
210
|
-
this.unique_values = data.unique_values;
|
|
211
|
-
this.values = data.values && data.values !== null ? data.values.map((itemData) => new NftAttribute(itemData)) : null;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
class NftAttribute {
|
|
215
|
-
constructor(data) {
|
|
216
|
-
this.value = data.value;
|
|
217
|
-
this.count = data.count;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
class NftCollectionTraitSummaryResponse {
|
|
221
|
-
constructor(data) {
|
|
222
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
223
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTraitSummary(itemData)) : null;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
class NftTraitSummary {
|
|
227
|
-
constructor(data) {
|
|
228
|
-
this.name = data.name;
|
|
229
|
-
this.value_type = data.value_type;
|
|
230
|
-
this.value_numeric = data.value_numeric && data.value_numeric !== null ? new NftTraitNumeric(data.value_numeric) : null;
|
|
231
|
-
this.value_string = data.value_string && data.value_string !== null ? new NftTraitString(data.value_string) : null;
|
|
232
|
-
this.attributes = data.attributes && data.attributes !== null ? data.attributes.map((itemData) => new NftSummaryAttribute(itemData)) : null;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
class NftTraitNumeric {
|
|
236
|
-
constructor(data) {
|
|
237
|
-
this.min = data.min;
|
|
238
|
-
this.max = data.max;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
class NftTraitString {
|
|
242
|
-
constructor(data) {
|
|
243
|
-
this.value = data.value;
|
|
244
|
-
this.token_count = data.token_count;
|
|
245
|
-
this.trait_percentage = data.trait_percentage;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
class NftOwnershipForCollectionResponse {
|
|
249
|
-
constructor(data) {
|
|
250
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
251
|
-
this.address = data.address;
|
|
252
|
-
this.collection = data.collection;
|
|
253
|
-
this.is_spam = data.is_spam;
|
|
254
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftOwnershipForCollectionItem(itemData)) : null;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
class NftOwnershipForCollectionItem {
|
|
258
|
-
constructor(data) {
|
|
259
|
-
this.contract_name = data.contract_name;
|
|
260
|
-
this.contract_ticker_symbol = data.contract_ticker_symbol;
|
|
261
|
-
this.contract_address = data.contract_address;
|
|
262
|
-
this.token_id = data.token_id && data.token_id !== null ? BigInt(data.token_id) : null;
|
|
263
|
-
this.supports_erc = data.supports_erc;
|
|
264
|
-
this.last_transfered_at = data.last_transfered_at && data.last_transfered_at !== null ? parseISO(data.last_transfered_at.toString()) : null;
|
|
265
|
-
this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
|
|
266
|
-
this.balance_24h = data.balance_24h;
|
|
267
|
-
this.type = data.type;
|
|
268
|
-
this.nft_data = data.nft_data && data.nft_data !== null ? new NftData(data.nft_data) : null;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
class NftMarketSaleCountResponse {
|
|
272
|
-
constructor(data) {
|
|
273
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
274
|
-
this.address = data.address;
|
|
275
|
-
this.quote_currency = data.quote_currency;
|
|
276
|
-
this.chain_name = data.chain_name;
|
|
277
|
-
this.chain_id = data.chain_id;
|
|
278
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new MarketSaleCountItem(itemData)) : null;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
class MarketSaleCountItem {
|
|
282
|
-
constructor(data) {
|
|
283
|
-
this.date = data.date && data.date !== null ? parseISO(data.date.toString()) : null;
|
|
284
|
-
this.sale_count = data.sale_count;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
class NftMarketVolumeResponse {
|
|
288
|
-
constructor(data) {
|
|
289
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
290
|
-
this.address = data.address;
|
|
291
|
-
this.quote_currency = data.quote_currency;
|
|
292
|
-
this.chain_name = data.chain_name;
|
|
293
|
-
this.chain_id = data.chain_id;
|
|
294
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new MarketVolumeItem(itemData)) : null;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
class MarketVolumeItem {
|
|
298
|
-
constructor(data) {
|
|
299
|
-
this.date = data.date && data.date !== null ? parseISO(data.date.toString()) : null;
|
|
300
|
-
this.native_ticker_symbol = data.native_ticker_symbol;
|
|
301
|
-
this.native_name = data.native_name;
|
|
302
|
-
this.volume_quote = data.volume_quote;
|
|
303
|
-
this.volume_native_quote = data.volume_native_quote;
|
|
304
|
-
this.pretty_volume_quote = data.pretty_volume_quote;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
class NftMarketFloorPriceResponse {
|
|
308
|
-
constructor(data) {
|
|
309
|
-
this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
|
|
310
|
-
this.address = data.address;
|
|
311
|
-
this.quote_currency = data.quote_currency;
|
|
312
|
-
this.chain_name = data.chain_name;
|
|
313
|
-
this.chain_id = data.chain_id;
|
|
314
|
-
this.items = data.items && data.items !== null ? data.items.map((itemData) => new MarketFloorPriceItem(itemData)) : null;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
class MarketFloorPriceItem {
|
|
318
|
-
constructor(data) {
|
|
319
|
-
this.date = data.date && data.date !== null ? parseISO(data.date.toString()) : null;
|
|
320
|
-
this.native_ticker_symbol = data.native_ticker_symbol;
|
|
321
|
-
this.native_name = data.native_name;
|
|
322
|
-
this.floor_price_native_quote = data.floor_price_native_quote;
|
|
323
|
-
this.floor_price_quote = data.floor_price_quote;
|
|
324
|
-
this.pretty_floor_price_quote = data.pretty_floor_price_quote;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* NFT APIs
|
|
329
|
-
*
|
|
330
|
-
*/
|
|
331
|
-
export class NftService {
|
|
332
|
-
constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
|
|
333
|
-
this.apiKey = apiKey;
|
|
334
|
-
this.debug = debug;
|
|
335
|
-
this.threadCount = threadCount;
|
|
336
|
-
this.is_key_valid = is_key_valid;
|
|
337
|
-
this.enableRetry = enableRetry;
|
|
338
|
-
this.source = source;
|
|
339
|
-
this.LIMIT = pLimit(this.threadCount);
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
*
|
|
343
|
-
* Commonly used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files.
|
|
344
|
-
*
|
|
345
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
346
|
-
* @param {GetChainCollectionsQueryParamOpts} queryParamOpts
|
|
347
|
-
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
348
|
-
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
349
|
-
* - `noSpam`: If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`.
|
|
350
|
-
*
|
|
351
|
-
*/
|
|
352
|
-
async *getChainCollections(chainName, queryParamOpts) {
|
|
353
|
-
let success = false;
|
|
354
|
-
let res;
|
|
355
|
-
while (!success) {
|
|
356
|
-
try {
|
|
357
|
-
const urlParams = new URLSearchParams();
|
|
358
|
-
if (!this.is_key_valid) {
|
|
359
|
-
throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
|
|
360
|
-
}
|
|
361
|
-
if (queryParamOpts?.pageSize !== undefined) {
|
|
362
|
-
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
363
|
-
}
|
|
364
|
-
if (queryParamOpts?.pageNumber !== undefined) {
|
|
365
|
-
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
366
|
-
}
|
|
367
|
-
if (queryParamOpts?.noSpam !== undefined) {
|
|
368
|
-
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
369
|
-
}
|
|
370
|
-
for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount, this.enableRetry, this.source)) {
|
|
371
|
-
yield res;
|
|
372
|
-
}
|
|
373
|
-
success = true;
|
|
374
|
-
}
|
|
375
|
-
catch (error) {
|
|
376
|
-
success = true;
|
|
377
|
-
throw new Error(error.message);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
*
|
|
383
|
-
* Commonly used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files.
|
|
384
|
-
*
|
|
385
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
386
|
-
* @param {GetChainCollectionsQueryParamOpts} queryParamOpts
|
|
387
|
-
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
388
|
-
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
389
|
-
* - `noSpam`: If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`.
|
|
390
|
-
*
|
|
391
|
-
*/
|
|
392
|
-
async getChainCollectionsByPage(chainName, queryParamOpts) {
|
|
393
|
-
let success = false;
|
|
394
|
-
let data;
|
|
395
|
-
let response;
|
|
396
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
397
|
-
while (!success) {
|
|
398
|
-
try {
|
|
399
|
-
const urlParams = new URLSearchParams();
|
|
400
|
-
if (!this.is_key_valid) {
|
|
401
|
-
return {
|
|
402
|
-
data: null,
|
|
403
|
-
error: true,
|
|
404
|
-
error_code: 401,
|
|
405
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
if (queryParamOpts?.pageSize !== undefined) {
|
|
409
|
-
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
410
|
-
}
|
|
411
|
-
if (queryParamOpts?.pageNumber !== undefined) {
|
|
412
|
-
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
413
|
-
}
|
|
414
|
-
if (queryParamOpts?.noSpam !== undefined) {
|
|
415
|
-
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
416
|
-
}
|
|
417
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`;
|
|
418
|
-
let startTime;
|
|
419
|
-
if (this.debug) {
|
|
420
|
-
startTime = new Date();
|
|
421
|
-
}
|
|
422
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`, {
|
|
423
|
-
headers: {
|
|
424
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
425
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
426
|
-
}
|
|
427
|
-
}));
|
|
428
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
429
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
430
|
-
try {
|
|
431
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
432
|
-
}
|
|
433
|
-
catch (error) {
|
|
434
|
-
success = true;
|
|
435
|
-
return {
|
|
436
|
-
data: null,
|
|
437
|
-
error: true,
|
|
438
|
-
error_code: response.status ?? 429,
|
|
439
|
-
error_message: error.message
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
data = await response.json();
|
|
445
|
-
}
|
|
446
|
-
const dataClass = new ChainCollectionResponse(data.data);
|
|
447
|
-
success = true;
|
|
448
|
-
return {
|
|
449
|
-
data: dataClass,
|
|
450
|
-
error: data ? data.error : true,
|
|
451
|
-
error_code: data ? data.error_code : response.status,
|
|
452
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
catch (error) {
|
|
456
|
-
success = true;
|
|
457
|
-
return {
|
|
458
|
-
data: null,
|
|
459
|
-
error: true,
|
|
460
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
461
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
/**
|
|
467
|
-
*
|
|
468
|
-
* Commonly used to render the NFTs (including ERC721 and ERC1155) held by an address.
|
|
469
|
-
*
|
|
470
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
471
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
472
|
-
* @param {GetNftsForAddressQueryParamOpts} queryParamOpts
|
|
473
|
-
* - `noSpam`: If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`.
|
|
474
|
-
* - `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.
|
|
475
|
-
* - `withUncached`: By default, 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.
|
|
476
|
-
*
|
|
477
|
-
*/
|
|
478
|
-
async getNftsForAddress(chainName, walletAddress, queryParamOpts) {
|
|
479
|
-
let success = false;
|
|
480
|
-
let data;
|
|
481
|
-
let response;
|
|
482
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
483
|
-
while (!success) {
|
|
484
|
-
try {
|
|
485
|
-
const urlParams = new URLSearchParams();
|
|
486
|
-
if (!this.is_key_valid) {
|
|
487
|
-
return {
|
|
488
|
-
data: null,
|
|
489
|
-
error: true,
|
|
490
|
-
error_code: 401,
|
|
491
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
if (queryParamOpts?.noSpam !== undefined) {
|
|
495
|
-
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
496
|
-
}
|
|
497
|
-
if (queryParamOpts?.noNftAssetMetadata !== undefined) {
|
|
498
|
-
urlParams.append("no-nft-asset-metadata", queryParamOpts?.noNftAssetMetadata.toString());
|
|
499
|
-
}
|
|
500
|
-
if (queryParamOpts?.withUncached !== undefined) {
|
|
501
|
-
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
502
|
-
}
|
|
503
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`;
|
|
504
|
-
let startTime;
|
|
505
|
-
if (this.debug) {
|
|
506
|
-
startTime = new Date();
|
|
507
|
-
}
|
|
508
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`, {
|
|
509
|
-
headers: {
|
|
510
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
511
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
512
|
-
}
|
|
513
|
-
}));
|
|
514
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
515
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
516
|
-
try {
|
|
517
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
518
|
-
}
|
|
519
|
-
catch (error) {
|
|
520
|
-
success = true;
|
|
521
|
-
return {
|
|
522
|
-
data: null,
|
|
523
|
-
error: true,
|
|
524
|
-
error_code: response.status ?? 429,
|
|
525
|
-
error_message: error.message
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
data = await response.json();
|
|
531
|
-
}
|
|
532
|
-
const dataClass = new NftAddressBalanceNftResponse(data.data);
|
|
533
|
-
success = true;
|
|
534
|
-
return {
|
|
535
|
-
data: dataClass,
|
|
536
|
-
error: data ? data.error : true,
|
|
537
|
-
error_code: data ? data.error_code : response.status,
|
|
538
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
catch (error) {
|
|
542
|
-
success = true;
|
|
543
|
-
return {
|
|
544
|
-
data: null,
|
|
545
|
-
error: true,
|
|
546
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
547
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
/**
|
|
553
|
-
*
|
|
554
|
-
* Commonly used to get NFT token IDs with metadata from a collection. Useful for building NFT card displays.
|
|
555
|
-
*
|
|
556
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
557
|
-
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
558
|
-
* @param {GetTokenIdsForContractWithMetadataQueryParamOpts} queryParamOpts
|
|
559
|
-
* - `noMetadata`: Omit metadata.
|
|
560
|
-
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
561
|
-
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
562
|
-
* - `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.
|
|
563
|
-
* - `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.
|
|
564
|
-
* - `withUncached`: By default, 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.
|
|
565
|
-
*
|
|
566
|
-
*/
|
|
567
|
-
async *getTokenIdsForContractWithMetadata(chainName, contractAddress, queryParamOpts) {
|
|
568
|
-
let success = false;
|
|
569
|
-
let res;
|
|
570
|
-
while (!success) {
|
|
571
|
-
try {
|
|
572
|
-
const urlParams = new URLSearchParams();
|
|
573
|
-
if (!this.is_key_valid) {
|
|
574
|
-
throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
|
|
575
|
-
}
|
|
576
|
-
if (queryParamOpts?.noMetadata !== undefined) {
|
|
577
|
-
urlParams.append("no-metadata", queryParamOpts?.noMetadata.toString());
|
|
578
|
-
}
|
|
579
|
-
if (queryParamOpts?.pageSize !== undefined) {
|
|
580
|
-
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
581
|
-
}
|
|
582
|
-
if (queryParamOpts?.pageNumber !== undefined) {
|
|
583
|
-
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
584
|
-
}
|
|
585
|
-
if (queryParamOpts?.traitsFilter !== undefined) {
|
|
586
|
-
urlParams.append("traits-filter", queryParamOpts?.traitsFilter.toString());
|
|
587
|
-
}
|
|
588
|
-
if (queryParamOpts?.valuesFilter !== undefined) {
|
|
589
|
-
urlParams.append("values-filter", queryParamOpts?.valuesFilter.toString());
|
|
590
|
-
}
|
|
591
|
-
if (queryParamOpts?.withUncached !== undefined) {
|
|
592
|
-
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
593
|
-
}
|
|
594
|
-
for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/`, this.apiKey, urlParams, NftTokenContract, this.debug, this.threadCount, this.enableRetry, this.source)) {
|
|
595
|
-
yield res;
|
|
596
|
-
}
|
|
597
|
-
success = true;
|
|
598
|
-
}
|
|
599
|
-
catch (error) {
|
|
600
|
-
success = true;
|
|
601
|
-
throw new Error(error.message);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
/**
|
|
606
|
-
*
|
|
607
|
-
* Commonly used to get NFT token IDs with metadata from a collection. Useful for building NFT card displays.
|
|
608
|
-
*
|
|
609
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
610
|
-
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
611
|
-
* @param {GetTokenIdsForContractWithMetadataQueryParamOpts} queryParamOpts
|
|
612
|
-
* - `noMetadata`: Omit metadata.
|
|
613
|
-
* - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
|
|
614
|
-
* - `pageNumber`: 0-indexed page number to begin pagination.
|
|
615
|
-
* - `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.
|
|
616
|
-
* - `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.
|
|
617
|
-
* - `withUncached`: By default, 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.
|
|
618
|
-
*
|
|
619
|
-
*/
|
|
620
|
-
async getTokenIdsForContractWithMetadataByPage(chainName, contractAddress, queryParamOpts) {
|
|
621
|
-
let success = false;
|
|
622
|
-
let data;
|
|
623
|
-
let response;
|
|
624
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
625
|
-
while (!success) {
|
|
626
|
-
try {
|
|
627
|
-
const urlParams = new URLSearchParams();
|
|
628
|
-
if (!this.is_key_valid) {
|
|
629
|
-
return {
|
|
630
|
-
data: null,
|
|
631
|
-
error: true,
|
|
632
|
-
error_code: 401,
|
|
633
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
if (queryParamOpts?.noMetadata !== undefined) {
|
|
637
|
-
urlParams.append("no-metadata", queryParamOpts?.noMetadata.toString());
|
|
638
|
-
}
|
|
639
|
-
if (queryParamOpts?.pageSize !== undefined) {
|
|
640
|
-
urlParams.append("page-size", queryParamOpts?.pageSize.toString());
|
|
641
|
-
}
|
|
642
|
-
if (queryParamOpts?.pageNumber !== undefined) {
|
|
643
|
-
urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
|
|
644
|
-
}
|
|
645
|
-
if (queryParamOpts?.traitsFilter !== undefined) {
|
|
646
|
-
urlParams.append("traits-filter", queryParamOpts?.traitsFilter.toString());
|
|
647
|
-
}
|
|
648
|
-
if (queryParamOpts?.valuesFilter !== undefined) {
|
|
649
|
-
urlParams.append("values-filter", queryParamOpts?.valuesFilter.toString());
|
|
650
|
-
}
|
|
651
|
-
if (queryParamOpts?.withUncached !== undefined) {
|
|
652
|
-
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
653
|
-
}
|
|
654
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`;
|
|
655
|
-
let startTime;
|
|
656
|
-
if (this.debug) {
|
|
657
|
-
startTime = new Date();
|
|
658
|
-
}
|
|
659
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`, {
|
|
660
|
-
headers: {
|
|
661
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
662
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
663
|
-
}
|
|
664
|
-
}));
|
|
665
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
666
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
667
|
-
try {
|
|
668
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
669
|
-
}
|
|
670
|
-
catch (error) {
|
|
671
|
-
success = true;
|
|
672
|
-
return {
|
|
673
|
-
data: null,
|
|
674
|
-
error: true,
|
|
675
|
-
error_code: response.status ?? 429,
|
|
676
|
-
error_message: error.message
|
|
677
|
-
};
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
else {
|
|
681
|
-
data = await response.json();
|
|
682
|
-
}
|
|
683
|
-
const dataClass = new NftMetadataResponse(data.data);
|
|
684
|
-
success = true;
|
|
685
|
-
return {
|
|
686
|
-
data: dataClass,
|
|
687
|
-
error: data ? data.error : true,
|
|
688
|
-
error_code: data ? data.error_code : response.status,
|
|
689
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
catch (error) {
|
|
693
|
-
success = true;
|
|
694
|
-
return {
|
|
695
|
-
data: null,
|
|
696
|
-
error: true,
|
|
697
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
698
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
699
|
-
};
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
/**
|
|
704
|
-
*
|
|
705
|
-
* Commonly used to get a single NFT metadata by token ID from a collection. Useful for building NFT card displays.
|
|
706
|
-
*
|
|
707
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
708
|
-
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
709
|
-
* @param {string} tokenId - The requested token ID.
|
|
710
|
-
* @param {GetNftMetadataForGivenTokenIdForContractQueryParamOpts} queryParamOpts
|
|
711
|
-
* - `noMetadata`: Omit metadata.
|
|
712
|
-
* - `withUncached`: By default, 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.
|
|
713
|
-
*
|
|
714
|
-
*/
|
|
715
|
-
async getNftMetadataForGivenTokenIdForContract(chainName, contractAddress, tokenId, queryParamOpts) {
|
|
716
|
-
let success = false;
|
|
717
|
-
let data;
|
|
718
|
-
let response;
|
|
719
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
720
|
-
while (!success) {
|
|
721
|
-
try {
|
|
722
|
-
const urlParams = new URLSearchParams();
|
|
723
|
-
if (!this.is_key_valid) {
|
|
724
|
-
return {
|
|
725
|
-
data: null,
|
|
726
|
-
error: true,
|
|
727
|
-
error_code: 401,
|
|
728
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
729
|
-
};
|
|
730
|
-
}
|
|
731
|
-
if (queryParamOpts?.noMetadata !== undefined) {
|
|
732
|
-
urlParams.append("no-metadata", queryParamOpts?.noMetadata.toString());
|
|
733
|
-
}
|
|
734
|
-
if (queryParamOpts?.withUncached !== undefined) {
|
|
735
|
-
urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
|
|
736
|
-
}
|
|
737
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`;
|
|
738
|
-
let startTime;
|
|
739
|
-
if (this.debug) {
|
|
740
|
-
startTime = new Date();
|
|
741
|
-
}
|
|
742
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`, {
|
|
743
|
-
headers: {
|
|
744
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
745
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
746
|
-
}
|
|
747
|
-
}));
|
|
748
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
749
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
750
|
-
try {
|
|
751
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
752
|
-
}
|
|
753
|
-
catch (error) {
|
|
754
|
-
success = true;
|
|
755
|
-
return {
|
|
756
|
-
data: null,
|
|
757
|
-
error: true,
|
|
758
|
-
error_code: response.status ?? 429,
|
|
759
|
-
error_message: error.message
|
|
760
|
-
};
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
else {
|
|
764
|
-
data = await response.json();
|
|
765
|
-
}
|
|
766
|
-
const dataClass = new NftMetadataResponse(data.data);
|
|
767
|
-
success = true;
|
|
768
|
-
return {
|
|
769
|
-
data: dataClass,
|
|
770
|
-
error: data ? data.error : true,
|
|
771
|
-
error_code: data ? data.error_code : response.status,
|
|
772
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
catch (error) {
|
|
776
|
-
success = true;
|
|
777
|
-
return {
|
|
778
|
-
data: null,
|
|
779
|
-
error: true,
|
|
780
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
781
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
782
|
-
};
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
/**
|
|
787
|
-
*
|
|
788
|
-
* Commonly used to get all transactions of an NFT token. Useful for building a transaction history table or price chart.
|
|
789
|
-
*
|
|
790
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
791
|
-
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
792
|
-
* @param {string} tokenId - The requested token ID.
|
|
793
|
-
* @param {GetNftTransactionsForContractTokenIdQueryParamOpts} queryParamOpts
|
|
794
|
-
* - `noSpam`: If `true`, the suspected spam tokens are removed. Supports `eth-mainnet` and `matic-mainnet`.
|
|
795
|
-
*
|
|
796
|
-
*/
|
|
797
|
-
async getNftTransactionsForContractTokenId(chainName, contractAddress, tokenId, queryParamOpts) {
|
|
798
|
-
let success = false;
|
|
799
|
-
let data;
|
|
800
|
-
let response;
|
|
801
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
802
|
-
while (!success) {
|
|
803
|
-
try {
|
|
804
|
-
const urlParams = new URLSearchParams();
|
|
805
|
-
if (!this.is_key_valid) {
|
|
806
|
-
return {
|
|
807
|
-
data: null,
|
|
808
|
-
error: true,
|
|
809
|
-
error_code: 401,
|
|
810
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
811
|
-
};
|
|
812
|
-
}
|
|
813
|
-
if (queryParamOpts?.noSpam !== undefined) {
|
|
814
|
-
urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
|
|
815
|
-
}
|
|
816
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`;
|
|
817
|
-
let startTime;
|
|
818
|
-
if (this.debug) {
|
|
819
|
-
startTime = new Date();
|
|
820
|
-
}
|
|
821
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`, {
|
|
822
|
-
headers: {
|
|
823
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
824
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
825
|
-
}
|
|
826
|
-
}));
|
|
827
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
828
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
829
|
-
try {
|
|
830
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
831
|
-
}
|
|
832
|
-
catch (error) {
|
|
833
|
-
success = true;
|
|
834
|
-
return {
|
|
835
|
-
data: null,
|
|
836
|
-
error: true,
|
|
837
|
-
error_code: response.status ?? 429,
|
|
838
|
-
error_message: error.message
|
|
839
|
-
};
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
else {
|
|
843
|
-
data = await response.json();
|
|
844
|
-
}
|
|
845
|
-
const dataClass = new NftTransactionsResponse(data.data);
|
|
846
|
-
success = true;
|
|
847
|
-
return {
|
|
848
|
-
data: dataClass,
|
|
849
|
-
error: data ? data.error : true,
|
|
850
|
-
error_code: data ? data.error_code : response.status,
|
|
851
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
852
|
-
};
|
|
853
|
-
}
|
|
854
|
-
catch (error) {
|
|
855
|
-
success = true;
|
|
856
|
-
return {
|
|
857
|
-
data: null,
|
|
858
|
-
error: true,
|
|
859
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
860
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
861
|
-
};
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
/**
|
|
866
|
-
*
|
|
867
|
-
* Commonly used to fetch and render the traits of a collection as seen in rarity calculators.
|
|
868
|
-
*
|
|
869
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
870
|
-
* @param {string} collectionContract - The requested collection address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
871
|
-
*
|
|
872
|
-
*/
|
|
873
|
-
async getTraitsForCollection(chainName, collectionContract) {
|
|
874
|
-
let success = false;
|
|
875
|
-
let data;
|
|
876
|
-
let response;
|
|
877
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
878
|
-
while (!success) {
|
|
879
|
-
try {
|
|
880
|
-
const urlParams = new URLSearchParams();
|
|
881
|
-
if (!this.is_key_valid) {
|
|
882
|
-
return {
|
|
883
|
-
data: null,
|
|
884
|
-
error: true,
|
|
885
|
-
error_code: 401,
|
|
886
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
887
|
-
};
|
|
888
|
-
}
|
|
889
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`;
|
|
890
|
-
let startTime;
|
|
891
|
-
if (this.debug) {
|
|
892
|
-
startTime = new Date();
|
|
893
|
-
}
|
|
894
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`, {
|
|
895
|
-
headers: {
|
|
896
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
897
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
898
|
-
}
|
|
899
|
-
}));
|
|
900
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
901
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
902
|
-
try {
|
|
903
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
904
|
-
}
|
|
905
|
-
catch (error) {
|
|
906
|
-
success = true;
|
|
907
|
-
return {
|
|
908
|
-
data: null,
|
|
909
|
-
error: true,
|
|
910
|
-
error_code: response.status ?? 429,
|
|
911
|
-
error_message: error.message
|
|
912
|
-
};
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
else {
|
|
916
|
-
data = await response.json();
|
|
917
|
-
}
|
|
918
|
-
const dataClass = new NftCollectionTraitsResponse(data.data);
|
|
919
|
-
success = true;
|
|
920
|
-
return {
|
|
921
|
-
data: dataClass,
|
|
922
|
-
error: data ? data.error : true,
|
|
923
|
-
error_code: data ? data.error_code : response.status,
|
|
924
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
925
|
-
};
|
|
926
|
-
}
|
|
927
|
-
catch (error) {
|
|
928
|
-
success = true;
|
|
929
|
-
return {
|
|
930
|
-
data: null,
|
|
931
|
-
error: true,
|
|
932
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
933
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
934
|
-
};
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
/**
|
|
939
|
-
*
|
|
940
|
-
* Commonly used to get the count of unique values for traits within an NFT collection.
|
|
941
|
-
*
|
|
942
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
943
|
-
* @param {string} collectionContract - The requested collection address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
944
|
-
* @param {string} trait - The requested trait.
|
|
945
|
-
*
|
|
946
|
-
*/
|
|
947
|
-
async getAttributesForTraitInCollection(chainName, collectionContract, trait) {
|
|
948
|
-
let success = false;
|
|
949
|
-
let data;
|
|
950
|
-
let response;
|
|
951
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
952
|
-
while (!success) {
|
|
953
|
-
try {
|
|
954
|
-
const urlParams = new URLSearchParams();
|
|
955
|
-
if (!this.is_key_valid) {
|
|
956
|
-
return {
|
|
957
|
-
data: null,
|
|
958
|
-
error: true,
|
|
959
|
-
error_code: 401,
|
|
960
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
961
|
-
};
|
|
962
|
-
}
|
|
963
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`;
|
|
964
|
-
let startTime;
|
|
965
|
-
if (this.debug) {
|
|
966
|
-
startTime = new Date();
|
|
967
|
-
}
|
|
968
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`, {
|
|
969
|
-
headers: {
|
|
970
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
971
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
972
|
-
}
|
|
973
|
-
}));
|
|
974
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
975
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
976
|
-
try {
|
|
977
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
978
|
-
}
|
|
979
|
-
catch (error) {
|
|
980
|
-
success = true;
|
|
981
|
-
return {
|
|
982
|
-
data: null,
|
|
983
|
-
error: true,
|
|
984
|
-
error_code: response.status ?? 429,
|
|
985
|
-
error_message: error.message
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
else {
|
|
990
|
-
data = await response.json();
|
|
991
|
-
}
|
|
992
|
-
const dataClass = new NftCollectionAttributesForTraitResponse(data.data);
|
|
993
|
-
success = true;
|
|
994
|
-
return {
|
|
995
|
-
data: dataClass,
|
|
996
|
-
error: data ? data.error : true,
|
|
997
|
-
error_code: data ? data.error_code : response.status,
|
|
998
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
999
|
-
};
|
|
1000
|
-
}
|
|
1001
|
-
catch (error) {
|
|
1002
|
-
success = true;
|
|
1003
|
-
return {
|
|
1004
|
-
data: null,
|
|
1005
|
-
error: true,
|
|
1006
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1007
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1008
|
-
};
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
/**
|
|
1013
|
-
*
|
|
1014
|
-
* Commonly used to calculate rarity scores for a collection based on its traits.
|
|
1015
|
-
*
|
|
1016
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1017
|
-
* @param {string} collectionContract - The requested collection address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
1018
|
-
*
|
|
1019
|
-
*/
|
|
1020
|
-
async getCollectionTraitsSummary(chainName, collectionContract) {
|
|
1021
|
-
let success = false;
|
|
1022
|
-
let data;
|
|
1023
|
-
let response;
|
|
1024
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1025
|
-
while (!success) {
|
|
1026
|
-
try {
|
|
1027
|
-
const urlParams = new URLSearchParams();
|
|
1028
|
-
if (!this.is_key_valid) {
|
|
1029
|
-
return {
|
|
1030
|
-
data: null,
|
|
1031
|
-
error: true,
|
|
1032
|
-
error_code: 401,
|
|
1033
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
1034
|
-
};
|
|
1035
|
-
}
|
|
1036
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`;
|
|
1037
|
-
let startTime;
|
|
1038
|
-
if (this.debug) {
|
|
1039
|
-
startTime = new Date();
|
|
1040
|
-
}
|
|
1041
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`, {
|
|
1042
|
-
headers: {
|
|
1043
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
1044
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1045
|
-
}
|
|
1046
|
-
}));
|
|
1047
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1048
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1049
|
-
try {
|
|
1050
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1051
|
-
}
|
|
1052
|
-
catch (error) {
|
|
1053
|
-
success = true;
|
|
1054
|
-
return {
|
|
1055
|
-
data: null,
|
|
1056
|
-
error: true,
|
|
1057
|
-
error_code: response.status ?? 429,
|
|
1058
|
-
error_message: error.message
|
|
1059
|
-
};
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
else {
|
|
1063
|
-
data = await response.json();
|
|
1064
|
-
}
|
|
1065
|
-
const dataClass = new NftCollectionTraitSummaryResponse(data.data);
|
|
1066
|
-
success = true;
|
|
1067
|
-
return {
|
|
1068
|
-
data: dataClass,
|
|
1069
|
-
error: data ? data.error : true,
|
|
1070
|
-
error_code: data ? data.error_code : response.status,
|
|
1071
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
1072
|
-
};
|
|
1073
|
-
}
|
|
1074
|
-
catch (error) {
|
|
1075
|
-
success = true;
|
|
1076
|
-
return {
|
|
1077
|
-
data: null,
|
|
1078
|
-
error: true,
|
|
1079
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1080
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1081
|
-
};
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
/**
|
|
1086
|
-
*
|
|
1087
|
-
* Commonly used to verify ownership of NFTs (including ERC-721 and ERC-1155) within a collection.
|
|
1088
|
-
*
|
|
1089
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1090
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
1091
|
-
* @param {string} collectionContract - The requested collection address.
|
|
1092
|
-
* @param {CheckOwnershipInNftQueryParamOpts} queryParamOpts
|
|
1093
|
-
* - `traitsFilter`: Filters NFTs based on a specific trait. If this filter is used, the API will return all NFTs with the specified trait. Must be used with "values-filter", is case-sensitive, and requires proper URL encoding.
|
|
1094
|
-
* - `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. Must be used with "traits-filter", is case-sensitive, and requires proper URL encoding.
|
|
1095
|
-
*
|
|
1096
|
-
*/
|
|
1097
|
-
async checkOwnershipInNft(chainName, walletAddress, collectionContract, queryParamOpts) {
|
|
1098
|
-
let success = false;
|
|
1099
|
-
let data;
|
|
1100
|
-
let response;
|
|
1101
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1102
|
-
while (!success) {
|
|
1103
|
-
try {
|
|
1104
|
-
const urlParams = new URLSearchParams();
|
|
1105
|
-
if (!this.is_key_valid) {
|
|
1106
|
-
return {
|
|
1107
|
-
data: null,
|
|
1108
|
-
error: true,
|
|
1109
|
-
error_code: 401,
|
|
1110
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
1111
|
-
};
|
|
1112
|
-
}
|
|
1113
|
-
if (queryParamOpts?.traitsFilter !== undefined) {
|
|
1114
|
-
urlParams.append("traits-filter", queryParamOpts?.traitsFilter.toString());
|
|
1115
|
-
}
|
|
1116
|
-
if (queryParamOpts?.valuesFilter !== undefined) {
|
|
1117
|
-
urlParams.append("values-filter", queryParamOpts?.valuesFilter.toString());
|
|
1118
|
-
}
|
|
1119
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`;
|
|
1120
|
-
let startTime;
|
|
1121
|
-
if (this.debug) {
|
|
1122
|
-
startTime = new Date();
|
|
1123
|
-
}
|
|
1124
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`, {
|
|
1125
|
-
headers: {
|
|
1126
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
1127
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1128
|
-
}
|
|
1129
|
-
}));
|
|
1130
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1131
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1132
|
-
try {
|
|
1133
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1134
|
-
}
|
|
1135
|
-
catch (error) {
|
|
1136
|
-
success = true;
|
|
1137
|
-
return {
|
|
1138
|
-
data: null,
|
|
1139
|
-
error: true,
|
|
1140
|
-
error_code: response.status ?? 429,
|
|
1141
|
-
error_message: error.message
|
|
1142
|
-
};
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
else {
|
|
1146
|
-
data = await response.json();
|
|
1147
|
-
}
|
|
1148
|
-
const dataClass = new NftOwnershipForCollectionResponse(data.data);
|
|
1149
|
-
success = true;
|
|
1150
|
-
return {
|
|
1151
|
-
data: dataClass,
|
|
1152
|
-
error: data ? data.error : true,
|
|
1153
|
-
error_code: data ? data.error_code : response.status,
|
|
1154
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
1155
|
-
};
|
|
1156
|
-
}
|
|
1157
|
-
catch (error) {
|
|
1158
|
-
success = true;
|
|
1159
|
-
return {
|
|
1160
|
-
data: null,
|
|
1161
|
-
error: true,
|
|
1162
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1163
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1164
|
-
};
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
/**
|
|
1169
|
-
*
|
|
1170
|
-
* Commonly used to verify ownership of a specific token (ERC-721 or ERC-1155) within a collection.
|
|
1171
|
-
*
|
|
1172
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1173
|
-
* @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
1174
|
-
* @param {string} collectionContract - The requested collection address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
1175
|
-
* @param {string} tokenId - The requested token ID.
|
|
1176
|
-
*
|
|
1177
|
-
*/
|
|
1178
|
-
async checkOwnershipInNftForSpecificTokenId(chainName, walletAddress, collectionContract, tokenId) {
|
|
1179
|
-
let success = false;
|
|
1180
|
-
let data;
|
|
1181
|
-
let response;
|
|
1182
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1183
|
-
while (!success) {
|
|
1184
|
-
try {
|
|
1185
|
-
const urlParams = new URLSearchParams();
|
|
1186
|
-
if (!this.is_key_valid) {
|
|
1187
|
-
return {
|
|
1188
|
-
data: null,
|
|
1189
|
-
error: true,
|
|
1190
|
-
error_code: 401,
|
|
1191
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
1192
|
-
};
|
|
1193
|
-
}
|
|
1194
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`;
|
|
1195
|
-
let startTime;
|
|
1196
|
-
if (this.debug) {
|
|
1197
|
-
startTime = new Date();
|
|
1198
|
-
}
|
|
1199
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`, {
|
|
1200
|
-
headers: {
|
|
1201
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
1202
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1203
|
-
}
|
|
1204
|
-
}));
|
|
1205
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1206
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1207
|
-
try {
|
|
1208
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1209
|
-
}
|
|
1210
|
-
catch (error) {
|
|
1211
|
-
success = true;
|
|
1212
|
-
return {
|
|
1213
|
-
data: null,
|
|
1214
|
-
error: true,
|
|
1215
|
-
error_code: response.status ?? 429,
|
|
1216
|
-
error_message: error.message
|
|
1217
|
-
};
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
else {
|
|
1221
|
-
data = await response.json();
|
|
1222
|
-
}
|
|
1223
|
-
const dataClass = new NftOwnershipForCollectionResponse(data.data);
|
|
1224
|
-
success = true;
|
|
1225
|
-
return {
|
|
1226
|
-
data: dataClass,
|
|
1227
|
-
error: data ? data.error : true,
|
|
1228
|
-
error_code: data ? data.error_code : response.status,
|
|
1229
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
1230
|
-
};
|
|
1231
|
-
}
|
|
1232
|
-
catch (error) {
|
|
1233
|
-
success = true;
|
|
1234
|
-
return {
|
|
1235
|
-
data: null,
|
|
1236
|
-
error: true,
|
|
1237
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1238
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1239
|
-
};
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
/**
|
|
1244
|
-
*
|
|
1245
|
-
* Commonly used to build a time-series chart of the sales count of an NFT collection.
|
|
1246
|
-
*
|
|
1247
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1248
|
-
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
1249
|
-
* @param {GetNftMarketSaleCountQueryParamOpts} queryParamOpts
|
|
1250
|
-
* - `days`: The number of days to return data for. Request up 365 days. Defaults to 30 days.
|
|
1251
|
-
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
1252
|
-
*
|
|
1253
|
-
*/
|
|
1254
|
-
async getNftMarketSaleCount(chainName, contractAddress, queryParamOpts) {
|
|
1255
|
-
let success = false;
|
|
1256
|
-
let data;
|
|
1257
|
-
let response;
|
|
1258
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1259
|
-
while (!success) {
|
|
1260
|
-
try {
|
|
1261
|
-
const urlParams = new URLSearchParams();
|
|
1262
|
-
if (!this.is_key_valid) {
|
|
1263
|
-
return {
|
|
1264
|
-
data: null,
|
|
1265
|
-
error: true,
|
|
1266
|
-
error_code: 401,
|
|
1267
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
1268
|
-
};
|
|
1269
|
-
}
|
|
1270
|
-
if (queryParamOpts?.days !== undefined) {
|
|
1271
|
-
urlParams.append("days", queryParamOpts?.days.toString());
|
|
1272
|
-
}
|
|
1273
|
-
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
1274
|
-
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
1275
|
-
}
|
|
1276
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/sale_count/?${urlParams}`;
|
|
1277
|
-
let startTime;
|
|
1278
|
-
if (this.debug) {
|
|
1279
|
-
startTime = new Date();
|
|
1280
|
-
}
|
|
1281
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/sale_count/?${urlParams}`, {
|
|
1282
|
-
headers: {
|
|
1283
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
1284
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1285
|
-
}
|
|
1286
|
-
}));
|
|
1287
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1288
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1289
|
-
try {
|
|
1290
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1291
|
-
}
|
|
1292
|
-
catch (error) {
|
|
1293
|
-
success = true;
|
|
1294
|
-
return {
|
|
1295
|
-
data: null,
|
|
1296
|
-
error: true,
|
|
1297
|
-
error_code: response.status ?? 429,
|
|
1298
|
-
error_message: error.message
|
|
1299
|
-
};
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
else {
|
|
1303
|
-
data = await response.json();
|
|
1304
|
-
}
|
|
1305
|
-
const dataClass = new NftMarketSaleCountResponse(data.data);
|
|
1306
|
-
success = true;
|
|
1307
|
-
return {
|
|
1308
|
-
data: dataClass,
|
|
1309
|
-
error: data ? data.error : true,
|
|
1310
|
-
error_code: data ? data.error_code : response.status,
|
|
1311
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
1312
|
-
};
|
|
1313
|
-
}
|
|
1314
|
-
catch (error) {
|
|
1315
|
-
success = true;
|
|
1316
|
-
return {
|
|
1317
|
-
data: null,
|
|
1318
|
-
error: true,
|
|
1319
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1320
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1321
|
-
};
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
/**
|
|
1326
|
-
*
|
|
1327
|
-
* Commonly used to build a time-series chart of the transaction volume of an NFT collection.
|
|
1328
|
-
*
|
|
1329
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1330
|
-
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
1331
|
-
* @param {GetNftMarketVolumeQueryParamOpts} queryParamOpts
|
|
1332
|
-
* - `days`: The number of days to return data for. Request up 365 days. Defaults to 30 days.
|
|
1333
|
-
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
1334
|
-
*
|
|
1335
|
-
*/
|
|
1336
|
-
async getNftMarketVolume(chainName, contractAddress, queryParamOpts) {
|
|
1337
|
-
let success = false;
|
|
1338
|
-
let data;
|
|
1339
|
-
let response;
|
|
1340
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1341
|
-
while (!success) {
|
|
1342
|
-
try {
|
|
1343
|
-
const urlParams = new URLSearchParams();
|
|
1344
|
-
if (!this.is_key_valid) {
|
|
1345
|
-
return {
|
|
1346
|
-
data: null,
|
|
1347
|
-
error: true,
|
|
1348
|
-
error_code: 401,
|
|
1349
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
1350
|
-
};
|
|
1351
|
-
}
|
|
1352
|
-
if (queryParamOpts?.days !== undefined) {
|
|
1353
|
-
urlParams.append("days", queryParamOpts?.days.toString());
|
|
1354
|
-
}
|
|
1355
|
-
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
1356
|
-
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
1357
|
-
}
|
|
1358
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/volume/?${urlParams}`;
|
|
1359
|
-
let startTime;
|
|
1360
|
-
if (this.debug) {
|
|
1361
|
-
startTime = new Date();
|
|
1362
|
-
}
|
|
1363
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/volume/?${urlParams}`, {
|
|
1364
|
-
headers: {
|
|
1365
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
1366
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1367
|
-
}
|
|
1368
|
-
}));
|
|
1369
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1370
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1371
|
-
try {
|
|
1372
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1373
|
-
}
|
|
1374
|
-
catch (error) {
|
|
1375
|
-
success = true;
|
|
1376
|
-
return {
|
|
1377
|
-
data: null,
|
|
1378
|
-
error: true,
|
|
1379
|
-
error_code: response.status ?? 429,
|
|
1380
|
-
error_message: error.message
|
|
1381
|
-
};
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
else {
|
|
1385
|
-
data = await response.json();
|
|
1386
|
-
}
|
|
1387
|
-
const dataClass = new NftMarketVolumeResponse(data.data);
|
|
1388
|
-
success = true;
|
|
1389
|
-
return {
|
|
1390
|
-
data: dataClass,
|
|
1391
|
-
error: data ? data.error : true,
|
|
1392
|
-
error_code: data ? data.error_code : response.status,
|
|
1393
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
1394
|
-
};
|
|
1395
|
-
}
|
|
1396
|
-
catch (error) {
|
|
1397
|
-
success = true;
|
|
1398
|
-
return {
|
|
1399
|
-
data: null,
|
|
1400
|
-
error: true,
|
|
1401
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1402
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1403
|
-
};
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
/**
|
|
1408
|
-
*
|
|
1409
|
-
* Commonly used to render a price floor chart for an NFT collection.
|
|
1410
|
-
*
|
|
1411
|
-
* @param {string} chainName - The chain name eg: `eth-mainnet`.
|
|
1412
|
-
* @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
|
|
1413
|
-
* @param {GetNftMarketFloorPriceQueryParamOpts} queryParamOpts
|
|
1414
|
-
* - `days`: The number of days to return data for. Request up 365 days. Defaults to 30 days.
|
|
1415
|
-
* - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
|
|
1416
|
-
*
|
|
1417
|
-
*/
|
|
1418
|
-
async getNftMarketFloorPrice(chainName, contractAddress, queryParamOpts) {
|
|
1419
|
-
let success = false;
|
|
1420
|
-
let data;
|
|
1421
|
-
let response;
|
|
1422
|
-
const backoff = new ExponentialBackoff(this.apiKey, this.debug);
|
|
1423
|
-
while (!success) {
|
|
1424
|
-
try {
|
|
1425
|
-
const urlParams = new URLSearchParams();
|
|
1426
|
-
if (!this.is_key_valid) {
|
|
1427
|
-
return {
|
|
1428
|
-
data: null,
|
|
1429
|
-
error: true,
|
|
1430
|
-
error_code: 401,
|
|
1431
|
-
error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
|
|
1432
|
-
};
|
|
1433
|
-
}
|
|
1434
|
-
if (queryParamOpts?.days !== undefined) {
|
|
1435
|
-
urlParams.append("days", queryParamOpts?.days.toString());
|
|
1436
|
-
}
|
|
1437
|
-
if (queryParamOpts?.quoteCurrency !== undefined) {
|
|
1438
|
-
urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
|
|
1439
|
-
}
|
|
1440
|
-
const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/floor_price/?${urlParams}`;
|
|
1441
|
-
let startTime;
|
|
1442
|
-
if (this.debug) {
|
|
1443
|
-
startTime = new Date();
|
|
1444
|
-
}
|
|
1445
|
-
response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/floor_price/?${urlParams}`, {
|
|
1446
|
-
headers: {
|
|
1447
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
1448
|
-
"X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
|
|
1449
|
-
}
|
|
1450
|
-
}));
|
|
1451
|
-
debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
|
|
1452
|
-
if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
|
|
1453
|
-
try {
|
|
1454
|
-
data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
|
|
1455
|
-
}
|
|
1456
|
-
catch (error) {
|
|
1457
|
-
success = true;
|
|
1458
|
-
return {
|
|
1459
|
-
data: null,
|
|
1460
|
-
error: true,
|
|
1461
|
-
error_code: response.status ?? 429,
|
|
1462
|
-
error_message: error.message
|
|
1463
|
-
};
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
else {
|
|
1467
|
-
data = await response.json();
|
|
1468
|
-
}
|
|
1469
|
-
const dataClass = new NftMarketFloorPriceResponse(data.data);
|
|
1470
|
-
success = true;
|
|
1471
|
-
return {
|
|
1472
|
-
data: dataClass,
|
|
1473
|
-
error: data ? data.error : true,
|
|
1474
|
-
error_code: data ? data.error_code : response.status,
|
|
1475
|
-
error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : response.status === 429 ? "429 Timeout Error" : "Unknown Error"
|
|
1476
|
-
};
|
|
1477
|
-
}
|
|
1478
|
-
catch (error) {
|
|
1479
|
-
success = true;
|
|
1480
|
-
return {
|
|
1481
|
-
data: null,
|
|
1482
|
-
error: true,
|
|
1483
|
-
error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
|
|
1484
|
-
error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
|
|
1485
|
-
};
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
//# sourceMappingURL=NftService.js.map
|