-
Notifications
You must be signed in to change notification settings - Fork 518
/
updateMetadataOpenSea.js
40 lines (32 loc) · 1014 Bytes
/
updateMetadataOpenSea.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const fetch = require('node-fetch');
// Update Contract Address Here
const OPENSEA_URI = 'https://api.opensea.io/asset/ADD_CONTRACT_ADDRESS';
// Maximum Tokens Belonging to Contract
const MAX_TOKENS = 3349;
function refreshData(tokenId) {
const URI = `${OPENSEA_URI}/${tokenId}/?force_update=true`;
const OPTIONS = {method: 'GET'};
fetch(URI, OPTIONS)
.then(res => res.json())
.then(json => {
if(json.detail) {
console.log(`failed: ${tokenId}`);
} else if(json.token_id) {
console.log(`success: ${tokenId}`);
}
})
.catch(err => console.error(`failed: ${tokenId}`));
};
const refreshTokens = (start, end) => {
Array.from({length: end - start + 1}, (x, i) => start + i).forEach((tokenId) => {
refreshData(tokenId);
});
}
let start = 0;
let end = 1;
const id = setInterval(() => {
refreshTokens(start, end);
if(end > MAX_TOKENS) clearInterval(id);
start = end + 1;
end = start + 1;
},2000);