Skip to content

Commit 77d8b6f

Browse files
committed
add reveal and macro scripts
1 parent 0c519e3 commit 77d8b6f

File tree

5 files changed

+195
-4
lines changed

5 files changed

+195
-4
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Source Code from "How To Create An ENTIRE NFT Collection (10,000+) & MINT In Under 1 Hour Without Coding Knowledge"
22

3-
Video: [How To Create An ENTIRE NFT Collection (10,000+) & MINT In Under 1 Hour Without Coding Knowledge](https://youtu.be/AaCgydeMu64)
3+
Video 1: [How To Create An ENTIRE NFT Collection (10,000+) & MINT In Under 1 Hour Without Coding Knowledge](https://youtu.be/AaCgydeMu64)
4+
5+
Video 2: [How To List & Reveal An ENTIRE NFT Collection (10,000+) Without Coding Knowledge on OpenSea](https://youtu.be/Iy1n_LxUwZs)
46

57
Original video code: [v0.1.0-alpha](https://github.com/codeSTACKr/video-source-code-create-nft-collection/releases/tag/v0.1.0-alpha)
68

@@ -10,6 +12,8 @@ Minting uses [NFTPort](https://nftport.xyz)
1012

1113
Join the Discord server for more help from the community: [codeSTACKr Discord](https://discord.gg/A9CnsVzzkZ)
1214

15+
The macro script from the second video: [macro1.mmmacro](macro1.mmmacro)
16+
1317
## UPDATES & FIXES
1418

1519
### npm not recognized

macro1.mmmacro

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
1 | 2511 | 830 | 0 | Keypress Ctrl+ | t
2+
2 | 2320 | 703 | 0 | Keypress %string%
3+
3 | 2551 | 822 | 0 | Keypress %integer%
4+
4 | 2523 | 838 | 0 | Keypress %string1%
5+
5 | 2320 | 703 | 0 | Keypress enter
6+
6 | RUN ACTION | WAIT SECONDS | +5
7+
7 | 2546 | 862 | 0 | Keypress %decimal%
8+
8 | 2546 | 862 | 0 | Keypress tab
9+
9 | 2546 | 862 | 0 | Keypress tab
10+
10 | 2546 | 862 | 0 | Keypress tab
11+
11 | 2546 | 862 | 0 | Keypress tab
12+
12 | 2546 | 862 | 0 | Keypress tab
13+
13 | 2546 | 862 | 0 | Keypress tab
14+
14 | 2546 | 862 | 0 | Keypress tab
15+
15 | 2546 | 862 | 0 | Keypress tab
16+
16 | 2546 | 862 | 0 | Keypress tab
17+
17 | 2546 | 862 | 0 | Keypress tab
18+
18 | 2546 | 862 | 0 | Keypress tab
19+
19 | 2546 | 862 | 0 | Keypress tab
20+
20 | 2546 | 862 | 0 | Keypress tab
21+
21 | 2546 | 862 | 0 | Keypress tab
22+
22 | 2646 | 862 | 0 | Keypress tab
23+
23 | 2546 | 862 | 0 | Keypress enter
24+
24 | 2546 | 862 | 2000 | Keypress tab
25+
25 | 2546 | 862 | 0 | Keypress tab
26+
26 | 2546 | 862 | 0 | Keypress tab
27+
28 | 2546 | 862 | 0 | Keypress enter
28+
29 | 2546 | 862 | 2000 | Keypress tab
29+
30 | 2546 | 862 | 0 | Keypress tab
30+
31 | 1228 | -936 | 0 | Keypress enter
31+
32 | RUN ACTION | WAIT SECONDS | +5
32+
33 | 1330 | -932 | 0 | Keypress Ctrl+ | w
33+
34 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::+1

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "10k-collection-video",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Source code from \"How To Create An ENTIRE NFT Collection (10,000+) & MINT In Under 1 Hour Without Coding Knowledge\" video.",
55
"main": "index.js",
66
"bin": "index.js",

utils/nftport/genericMetas.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const basePath = process.cwd();
33
const fs = require("fs");
44
const buildDir = path.join(basePath, "/build");
55

6+
const GENERIC_TITLE = "Unknown" // Replace with what you want the generic titles to say.
7+
const GENERIC_DESCRIPTION = "Unknown" // Replace with what you want the generic descriptions to say.
8+
69
if (!fs.existsSync(path.join(buildDir, "/genericJson"))) {
710
fs.mkdirSync(path.join(buildDir, "/genericJson"));
811
}
@@ -12,8 +15,8 @@ fs.readdirSync(`${buildDir}/json`).forEach((file) => {
1215

1316
const jsonFile = JSON.parse(fs.readFileSync(`${buildDir}/json/${file}`));
1417

15-
jsonFile.name = "Unknown";
16-
jsonFile.description = "Unknown";
18+
jsonFile.name = `${GENERIC_TITLE} #${jsonFile.custom_fields.edition}`;
19+
jsonFile.description = GENERIC_DESCRIPTION;
1720
jsonFile.file_url =
1821
"https://ipfs.io/ipfs/QmUf9tDbkqnfHkQaMdFWSGAeXwVXWA61pFED7ypx4hcsfh";
1922
// This is an example url, replace with yours.

utils/nftport/revealNFTs.js

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
const fetch = require("node-fetch");
2+
const path = require("path");
3+
const basePath = process.cwd();
4+
const fs = require("fs");
5+
6+
const AUTH = 'YOUR API KEY HERE';
7+
const CONTRACT_ADDRESS = 'YOUR CONTRACT ADDRESS HERE';
8+
const ACCOUNT_ADDRESS = 'METAMASK ACCOUNT THAT MINTED NFTs';
9+
const CHAIN = 'rinkeby'; // Test: rinkeby, Real: polygon
10+
const TIMEOUT = 1000; // Milliseconds. This a timeout for errors only. If there is an error, it will wait then try again. 5000 = 5 seconds.
11+
const INTERVAL = 900000; // Milliseconds. This is the interval for it to check for sales and reveal the NFT. 900000 = 15 minutes.
12+
13+
const ownedNFTs = []
14+
15+
if (!fs.existsSync(path.join(`${basePath}/build`, "/revealed"))) {
16+
fs.mkdirSync(path.join(`${basePath}/build`, "revealed"));
17+
}
18+
19+
async function checkOwnedNFTs() {
20+
let page = 1
21+
let lastPage = 1
22+
let url = `https://api.nftport.xyz/v0/accounts/${ACCOUNT_ADDRESS}?chain=${CHAIN}&page_number=`
23+
let options = {
24+
method: "GET",
25+
headers: {
26+
"Content-Type": "application/json",
27+
Authorization: AUTH,
28+
}
29+
};
30+
31+
let ownedNFTsData = await fetchWithRetry(`${url}${page}`, options)
32+
for(ownedNFT of ownedNFTsData.nfts) {
33+
if(ownedNFT.contract_address === CONTRACT_ADDRESS) {
34+
ownedNFTs.push(parseInt(ownedNFT.token_id))
35+
}
36+
}
37+
lastPage = Math.ceil(ownedNFTsData.total / 50)
38+
while(page < lastPage) {
39+
page++
40+
ownedNFTsData = await fetchWithRetry(`${url}${page}`, options)
41+
for(ownedNFT of ownedNFTsData.nfts) {
42+
if(ownedNFT.contract_address === CONTRACT_ADDRESS) {
43+
ownedNFTs.push(parseInt(ownedNFT.token_id))
44+
}
45+
}
46+
}
47+
48+
reveal()
49+
}
50+
51+
async function reveal() {
52+
const ipfsMetas = JSON.parse(
53+
fs.readFileSync(`${basePath}/build/ipfsMetas/_ipfsMetas.json`)
54+
);
55+
for (const meta of ipfsMetas) {
56+
const edition = meta.custom_fields.edition
57+
if(!ownedNFTs.includes(edition)) {
58+
const revealedFilePath = `${basePath}/build/revealed/${edition}.json`;
59+
try {
60+
fs.accessSync(revealedFilePath);
61+
const revealedFile = fs.readFileSync(revealedFilePath)
62+
if(revealedFile.length > 0) {
63+
const revealedFileJson = JSON.parse(revealedFile)
64+
if(revealedFileJson.updateData.response !== "OK") throw 'not revealed'
65+
console.log(`${meta.name} already revealed`);
66+
} else {
67+
throw 'not revealed'
68+
}
69+
} catch(err) {
70+
try {
71+
let url = "https://api.nftport.xyz/v0/mints/customizable";
72+
73+
const updateInfo = {
74+
chain: CHAIN,
75+
contract_address: CONTRACT_ADDRESS,
76+
metadata_uri: meta.metadata_uri,
77+
token_id: meta.custom_fields.edition,
78+
};
79+
80+
let options = {
81+
method: "PUT",
82+
headers: {
83+
"Content-Type": "application/json",
84+
Authorization: AUTH,
85+
},
86+
body: JSON.stringify(updateInfo),
87+
};
88+
let updateData = await fetchWithRetry(url, options, meta)
89+
console.log(`Updated: ${meta.name}`);
90+
const combinedData = {
91+
metaData: meta,
92+
updateData: updateData
93+
}
94+
writeMintData(meta.custom_fields.edition, combinedData)
95+
} catch(err) {
96+
console.log(err)
97+
}
98+
}
99+
}
100+
}
101+
console.log(`Done revealing! Will run again in ${(INTERVAL/1000)/60} minutes`)
102+
}
103+
104+
async function fetchWithRetry(url, options, meta) {
105+
return new Promise((resolve, reject) => {
106+
const fetch_retry = (_url, _options, _meta) => {
107+
108+
return fetch(url, options).then(async (res) => {
109+
const status = res.status;
110+
111+
if(status === 200) {
112+
return res.json();
113+
}
114+
else {
115+
console.error(`ERROR STATUS: ${status}`)
116+
console.log('Retrying')
117+
await timer(TIMEOUT)
118+
fetch_retry(_url, _options, _meta)
119+
}
120+
})
121+
.then(async (json) => {
122+
if(json.response === "OK"){
123+
return resolve(json);
124+
} else {
125+
console.error(`NOK: ${json.error}`)
126+
console.log('Retrying')
127+
await timer(TIMEOUT)
128+
fetch_retry(_url, _options, _meta)
129+
}
130+
})
131+
.catch(async (error) => {
132+
console.error(`CATCH ERROR: ${error}`)
133+
console.log('Retrying')
134+
await timer(TIMEOUT)
135+
fetch_retry(_url, _options, _meta)
136+
});
137+
}
138+
return fetch_retry(url, options, meta);
139+
});
140+
}
141+
142+
function timer(ms) {
143+
return new Promise(res => setTimeout(res, ms));
144+
}
145+
146+
const writeMintData = (_edition, _data) => {
147+
fs.writeFileSync(`${basePath}/build/revealed/${_edition}.json`, JSON.stringify(_data, null, 2));
148+
};
149+
150+
setInterval(checkOwnedNFTs, INTERVAL)
151+
checkOwnedNFTs()

0 commit comments

Comments
 (0)