Skip to content

Commit

Permalink
add reveal and macro scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
codeSTACKr committed Jan 7, 2022
1 parent 0c519e3 commit 77d8b6f
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Source Code from "How To Create An ENTIRE NFT Collection (10,000+) & MINT In Under 1 Hour Without Coding Knowledge"

Video: [How To Create An ENTIRE NFT Collection (10,000+) & MINT In Under 1 Hour Without Coding Knowledge](https://youtu.be/AaCgydeMu64)
Video 1: [How To Create An ENTIRE NFT Collection (10,000+) & MINT In Under 1 Hour Without Coding Knowledge](https://youtu.be/AaCgydeMu64)

Video 2: [How To List & Reveal An ENTIRE NFT Collection (10,000+) Without Coding Knowledge on OpenSea](https://youtu.be/Iy1n_LxUwZs)

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

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

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

The macro script from the second video: [macro1.mmmacro](macro1.mmmacro)

## UPDATES & FIXES

### npm not recognized
Expand Down
33 changes: 33 additions & 0 deletions macro1.mmmacro
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
1 | 2511 | 830 | 0 | Keypress Ctrl+ | t
2 | 2320 | 703 | 0 | Keypress %string%
3 | 2551 | 822 | 0 | Keypress %integer%
4 | 2523 | 838 | 0 | Keypress %string1%
5 | 2320 | 703 | 0 | Keypress enter
6 | RUN ACTION | WAIT SECONDS | +5
7 | 2546 | 862 | 0 | Keypress %decimal%
8 | 2546 | 862 | 0 | Keypress tab
9 | 2546 | 862 | 0 | Keypress tab
10 | 2546 | 862 | 0 | Keypress tab
11 | 2546 | 862 | 0 | Keypress tab
12 | 2546 | 862 | 0 | Keypress tab
13 | 2546 | 862 | 0 | Keypress tab
14 | 2546 | 862 | 0 | Keypress tab
15 | 2546 | 862 | 0 | Keypress tab
16 | 2546 | 862 | 0 | Keypress tab
17 | 2546 | 862 | 0 | Keypress tab
18 | 2546 | 862 | 0 | Keypress tab
19 | 2546 | 862 | 0 | Keypress tab
20 | 2546 | 862 | 0 | Keypress tab
21 | 2546 | 862 | 0 | Keypress tab
22 | 2646 | 862 | 0 | Keypress tab
23 | 2546 | 862 | 0 | Keypress enter
24 | 2546 | 862 | 2000 | Keypress tab
25 | 2546 | 862 | 0 | Keypress tab
26 | 2546 | 862 | 0 | Keypress tab
28 | 2546 | 862 | 0 | Keypress enter
29 | 2546 | 862 | 2000 | Keypress tab
30 | 2546 | 862 | 0 | Keypress tab
31 | 1228 | -936 | 0 | Keypress enter
32 | RUN ACTION | WAIT SECONDS | +5
33 | 1330 | -932 | 0 | Keypress Ctrl+ | w
34 | RUN ACTION | DEFINE INTEGER VARIABLE | %INTEGER%::+1
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "10k-collection-video",
"version": "1.0.0",
"version": "1.1.0",
"description": "Source code from \"How To Create An ENTIRE NFT Collection (10,000+) & MINT In Under 1 Hour Without Coding Knowledge\" video.",
"main": "index.js",
"bin": "index.js",
Expand Down
7 changes: 5 additions & 2 deletions utils/nftport/genericMetas.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const basePath = process.cwd();
const fs = require("fs");
const buildDir = path.join(basePath, "/build");

const GENERIC_TITLE = "Unknown" // Replace with what you want the generic titles to say.
const GENERIC_DESCRIPTION = "Unknown" // Replace with what you want the generic descriptions to say.

if (!fs.existsSync(path.join(buildDir, "/genericJson"))) {
fs.mkdirSync(path.join(buildDir, "/genericJson"));
}
Expand All @@ -12,8 +15,8 @@ fs.readdirSync(`${buildDir}/json`).forEach((file) => {

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

jsonFile.name = "Unknown";
jsonFile.description = "Unknown";
jsonFile.name = `${GENERIC_TITLE} #${jsonFile.custom_fields.edition}`;
jsonFile.description = GENERIC_DESCRIPTION;
jsonFile.file_url =
"https://ipfs.io/ipfs/QmUf9tDbkqnfHkQaMdFWSGAeXwVXWA61pFED7ypx4hcsfh";
// This is an example url, replace with yours.
Expand Down
151 changes: 151 additions & 0 deletions utils/nftport/revealNFTs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
const fetch = require("node-fetch");
const path = require("path");
const basePath = process.cwd();
const fs = require("fs");

const AUTH = 'YOUR API KEY HERE';
const CONTRACT_ADDRESS = 'YOUR CONTRACT ADDRESS HERE';
const ACCOUNT_ADDRESS = 'METAMASK ACCOUNT THAT MINTED NFTs';
const CHAIN = 'rinkeby'; // Test: rinkeby, Real: polygon
const TIMEOUT = 1000; // Milliseconds. This a timeout for errors only. If there is an error, it will wait then try again. 5000 = 5 seconds.
const INTERVAL = 900000; // Milliseconds. This is the interval for it to check for sales and reveal the NFT. 900000 = 15 minutes.

const ownedNFTs = []

if (!fs.existsSync(path.join(`${basePath}/build`, "/revealed"))) {
fs.mkdirSync(path.join(`${basePath}/build`, "revealed"));
}

async function checkOwnedNFTs() {
let page = 1
let lastPage = 1
let url = `https://api.nftport.xyz/v0/accounts/${ACCOUNT_ADDRESS}?chain=${CHAIN}&page_number=`
let options = {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: AUTH,
}
};

let ownedNFTsData = await fetchWithRetry(`${url}${page}`, options)
for(ownedNFT of ownedNFTsData.nfts) {
if(ownedNFT.contract_address === CONTRACT_ADDRESS) {
ownedNFTs.push(parseInt(ownedNFT.token_id))
}
}
lastPage = Math.ceil(ownedNFTsData.total / 50)
while(page < lastPage) {
page++
ownedNFTsData = await fetchWithRetry(`${url}${page}`, options)
for(ownedNFT of ownedNFTsData.nfts) {
if(ownedNFT.contract_address === CONTRACT_ADDRESS) {
ownedNFTs.push(parseInt(ownedNFT.token_id))
}
}
}

reveal()
}

async function reveal() {
const ipfsMetas = JSON.parse(
fs.readFileSync(`${basePath}/build/ipfsMetas/_ipfsMetas.json`)
);
for (const meta of ipfsMetas) {
const edition = meta.custom_fields.edition
if(!ownedNFTs.includes(edition)) {
const revealedFilePath = `${basePath}/build/revealed/${edition}.json`;
try {
fs.accessSync(revealedFilePath);
const revealedFile = fs.readFileSync(revealedFilePath)
if(revealedFile.length > 0) {
const revealedFileJson = JSON.parse(revealedFile)
if(revealedFileJson.updateData.response !== "OK") throw 'not revealed'
console.log(`${meta.name} already revealed`);
} else {
throw 'not revealed'
}
} catch(err) {
try {
let url = "https://api.nftport.xyz/v0/mints/customizable";

const updateInfo = {
chain: CHAIN,
contract_address: CONTRACT_ADDRESS,
metadata_uri: meta.metadata_uri,
token_id: meta.custom_fields.edition,
};

let options = {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: AUTH,
},
body: JSON.stringify(updateInfo),
};
let updateData = await fetchWithRetry(url, options, meta)
console.log(`Updated: ${meta.name}`);
const combinedData = {
metaData: meta,
updateData: updateData
}
writeMintData(meta.custom_fields.edition, combinedData)
} catch(err) {
console.log(err)
}
}
}
}
console.log(`Done revealing! Will run again in ${(INTERVAL/1000)/60} minutes`)
}

async function fetchWithRetry(url, options, meta) {
return new Promise((resolve, reject) => {
const fetch_retry = (_url, _options, _meta) => {

return fetch(url, options).then(async (res) => {
const status = res.status;

if(status === 200) {
return res.json();
}
else {
console.error(`ERROR STATUS: ${status}`)
console.log('Retrying')
await timer(TIMEOUT)
fetch_retry(_url, _options, _meta)
}
})
.then(async (json) => {
if(json.response === "OK"){
return resolve(json);
} else {
console.error(`NOK: ${json.error}`)
console.log('Retrying')
await timer(TIMEOUT)
fetch_retry(_url, _options, _meta)
}
})
.catch(async (error) => {
console.error(`CATCH ERROR: ${error}`)
console.log('Retrying')
await timer(TIMEOUT)
fetch_retry(_url, _options, _meta)
});
}
return fetch_retry(url, options, meta);
});
}

function timer(ms) {
return new Promise(res => setTimeout(res, ms));
}

const writeMintData = (_edition, _data) => {
fs.writeFileSync(`${basePath}/build/revealed/${_edition}.json`, JSON.stringify(_data, null, 2));
};

setInterval(checkOwnedNFTs, INTERVAL)
checkOwnedNFTs()

0 comments on commit 77d8b6f

Please sign in to comment.