Skip to content

Commit 85549b0

Browse files
authored
Merge pull request #19 from codeSTACKr/fix-uploads-mints
Fix uploads mints
2 parents 1745dd5 + e537394 commit 85549b0

File tree

12 files changed

+296
-131
lines changed

12 files changed

+296
-131
lines changed

README.md

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

3-
## Multiple Active Branches
4-
5-
- [main](https://github.com/codeSTACKr/video-source-code-create-nft-collection/tree/main) = Source code from the video
6-
- [fix-uploads-mints](https://github.com/codeSTACKr/video-source-code-create-nft-collection/tree/fix-uploads-mints) = Updated to fix issues uploading files, metadata, and minting explained [below](#quota-limit-reached-or-too-many-requests-errors).
7-
8-
[Video Link](https://youtu.be/AaCgydeMu64)
3+
Video: [How To Create An ENTIRE NFT Collection (10,000+) & MINT In Under 1 Hour Without Coding Knowledge](https://youtu.be/AaCgydeMu64)
94

105
Base code is from [hashlips_art_engine](https://github.com/HashLips/hashlips_art_engine)
116

@@ -44,17 +39,16 @@ Ensure that your layer names in the `config.js` file match exactly to your layer
4439

4540
### "Quota Limit Reached" or "Too many requests" errors
4641

47-
There have been some changes made to the code in the [fix-uploads-mints](https://github.com/codeSTACKr/video-source-code-create-nft-collection/tree/fix-uploads-mints) branch resulting from some errors when uploading files, metadata, and minting using NFTPort. Depending on your plan, Free vs Community, there are rate limits.
42+
There have been some changes made to the code from the original video resulting from some errors when uploading files, metadata, and minting using NFTPort. Depending on your plan, Free vs Community, there are rate limits.
4843

4944
To fix these issues, I've updated the code to include a timeout that will allow the files to be uploaded at a slower rate, instead of all at once, eliminating these errors.
5045

5146
**To use this code:**
5247

53-
- Clone this repo or download the zip file.
48+
- Clone this repo or download the latest release zip file.
5449
- Unzip, if needed, and open the folder in VS Code.
5550
- From the terminal type:
5651
- `npm install`
57-
- Ensure you are on the `fix-uploads-mints` branch if you cloned the repo.
5852
- Copy your image layers into the `layers` folder.
5953
- Use the `src/config.js` file to set up your layers and NFT information.
6054

banner.png

-431 KB
Binary file not shown.

layers/Background/Blue.png

1.88 KB
Loading

layers/Background/Orange.png

1.88 KB
Loading

layers/Background/Yellow.png

1.88 KB
Loading

logo.png

-36.8 KB
Binary file not shown.

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": "0.1.0",
3+
"version": "1.0.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",

src/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const background = {
7979
};
8080

8181
const extraMetadata = {
82-
external_url: "https://codecats.xyz",
82+
external_url: "https://codecats.xyz", // Replace with your website or remove this line if you do not have one.
8383
};
8484

8585
const rarityDelimiter = "#";

utils/nftport/genericMetas.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const path = require("path");
2-
const isLocal = typeof process.pkg === "undefined";
3-
const basePath = isLocal ? process.cwd() : path.dirname(process.execPath);
2+
const basePath = process.cwd();
43
const fs = require("fs");
54
const buildDir = path.join(basePath, "/build");
65

utils/nftport/mint.js

Lines changed: 102 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,113 @@
11
const fetch = require("node-fetch");
22
const path = require("path");
3-
const isLocal = typeof process.pkg === "undefined";
4-
const basePath = isLocal ? process.cwd() : path.dirname(process.execPath);
3+
const basePath = process.cwd();
54
const fs = require("fs");
65

76
const AUTH = 'YOUR API KEY HERE';
87
const CONTRACT_ADDRESS = 'YOUR CONTRACT ADDRESS HERE';
98
const MINT_TO_ADDRESS = 'YOUR WALLET ADDRESS HERE';
109
const CHAIN = 'rinkeby';
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.
1111

12-
const ipfsMetas = JSON.parse(
13-
fs.readFileSync(`${basePath}/build/json/_ipfsMetas.json`)
14-
);
15-
16-
fs.writeFileSync(`${basePath}/build/minted.json`, "");
17-
const writter = fs.createWriteStream(`${basePath}/build/minted.json`, {
18-
flags: "a",
19-
});
20-
writter.write("[");
21-
nftCount = ipfsMetas.length;
22-
23-
ipfsMetas.forEach((meta) => {
24-
let url = "https://api.nftport.xyz/v0/mints/customizable";
25-
26-
const mintInfo = {
27-
chain: CHAIN,
28-
contract_address: CONTRACT_ADDRESS,
29-
metadata_uri: meta.metadata_uri,
30-
mint_to_address: MINT_TO_ADDRESS,
31-
token_id: meta.custom_fields.edition,
32-
};
33-
34-
let options = {
35-
method: "POST",
36-
headers: {
37-
"Content-Type": "application/json",
38-
Authorization: AUTH,
39-
},
40-
body: JSON.stringify(mintInfo),
41-
};
42-
43-
fetch(url, options)
44-
.then((res) => res.json())
45-
.then((json) => {
46-
writter.write(JSON.stringify(json, null, 2));
47-
nftCount--;
48-
49-
if (nftCount === 0) {
50-
writter.write("]");
51-
writter.end();
52-
} else {
53-
writter.write(",\n");
12+
if (!fs.existsSync(path.join(`${basePath}/build`, "/minted"))) {
13+
fs.mkdirSync(path.join(`${basePath}/build`, "minted"));
14+
}
15+
16+
async function main() {
17+
const ipfsMetas = JSON.parse(
18+
fs.readFileSync(`${basePath}/build/ipfsMetas/_ipfsMetas.json`)
19+
);
20+
21+
for (const meta of ipfsMetas) {
22+
const mintFile = `${basePath}/build/minted/${meta.custom_fields.edition}.json`;
23+
24+
try {
25+
fs.accessSync(mintFile);
26+
const mintedFile = fs.readFileSync(mintFile)
27+
if(mintedFile.length > 0) {
28+
const mintedMeta = JSON.parse(mintedFile)
29+
if(mintedMeta.mintData.response !== "OK") throw 'not minted'
5430
}
31+
console.log(`${meta.name} already minted`);
32+
} catch(err) {
33+
try {
34+
let mintData = await fetchWithRetry(meta)
35+
const combinedData = {
36+
metaData: meta,
37+
mintData: mintData
38+
}
39+
writeMintData(meta.custom_fields.edition, combinedData)
40+
console.log(`Minted: ${meta.name}!`);
41+
} catch(err) {
42+
console.log(`Catch: ${err}`)
43+
}
44+
}
45+
}
46+
}
47+
48+
main();
49+
50+
function timer(ms) {
51+
return new Promise(res => setTimeout(res, ms));
52+
}
53+
54+
async function fetchWithRetry(meta) {
55+
await timer(TIMEOUT);
56+
return new Promise((resolve, reject) => {
57+
const fetch_retry = (_meta) => {
58+
let url = "https://api.nftport.xyz/v0/mints/customizable";
59+
60+
const mintInfo = {
61+
chain: CHAIN,
62+
contract_address: CONTRACT_ADDRESS,
63+
metadata_uri: _meta.metadata_uri,
64+
mint_to_address: MINT_TO_ADDRESS,
65+
token_id: _meta.custom_fields.edition,
66+
};
67+
68+
let options = {
69+
method: "POST",
70+
headers: {
71+
"Content-Type": "application/json",
72+
Authorization: AUTH,
73+
},
74+
body: JSON.stringify(mintInfo),
75+
};
76+
77+
return fetch(url, options).then(async (res) => {
78+
const status = res.status;
79+
80+
if(status === 200) {
81+
return res.json();
82+
}
83+
else {
84+
console.error(`ERROR STATUS: ${status}`)
85+
console.log('Retrying')
86+
await timer(TIMEOUT)
87+
fetch_retry(_meta)
88+
}
89+
})
90+
.then(async (json) => {
91+
if(json.response === "OK"){
92+
return resolve(json);
93+
} else {
94+
console.error(`NOK: ${json.error}`)
95+
console.log('Retrying')
96+
await timer(TIMEOUT)
97+
fetch_retry(_meta)
98+
}
99+
})
100+
.catch(async (error) => {
101+
console.error(`CATCH ERROR: ${error}`)
102+
console.log('Retrying')
103+
await timer(TIMEOUT)
104+
fetch_retry(_meta)
105+
});
106+
}
107+
return fetch_retry(meta);
108+
});
109+
}
55110

56-
console.log(`Minted: ${json.transaction_external_url}`);
57-
})
58-
.catch((err) => console.error("error:" + err));
59-
});
111+
const writeMintData = (_edition, _data) => {
112+
fs.writeFileSync(`${basePath}/build/minted/${_edition}.json`, JSON.stringify(_data, null, 2));
113+
};

0 commit comments

Comments
 (0)