forked from BankkRoll/BitMint-BETA-Ordinal-Mint-Site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateCollection.ts
88 lines (77 loc) · 3.53 KB
/
createCollection.ts
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import axios, { CancelTokenSource } from 'axios';
import constants from './const/config';
import fs from 'fs';
import path from 'path';
import FormData from 'form-data';
async function createCollection() {
console.log('Creating collection...');
const extension = constants.mintOptions.artFilesExtension;
const totalSupply = constants.mintOptions.totalSupply;
console.log(`Extension: ${extension}, Total supply: ${totalSupply}`);
const filePromises = Array.from({ length: totalSupply }, async (_, i) => {
const fileName = `${i + 1}.${extension}`;
const localFilePath = path.join(__dirname, constants.mintOptions.artFilesFolder, fileName);
return {
name: fileName,
url: localFilePath
};
});
console.log('Awaiting file promises...');
const files = await Promise.all(filePromises);
console.log('File promises resolved.');
const formData = new FormData();
files.forEach(file => {
formData.append('files', fs.createReadStream(file.url), file.name);
});
// Append other fields
formData.append('id', constants.collectionOptions.id);
formData.append('name', constants.title);
formData.append('description', constants.description);
formData.append('creator', constants.collectionOptions.creator);
formData.append('price', constants.mintOptions.publicMintPrice.toString());
formData.append('totalCount', totalSupply.toString());
formData.append('serviceFee', constants.mintOptions.serviceFee.toString());
formData.append('receiveAddress', constants.mintOptions.recipientBTCAddress);
formData.append('fee', constants.mintOptions.fee.toString());
formData.append('optimize-images', constants.mintOptions.optimizeImages.toString());
const options = {
headers: {
...formData.getHeaders(),
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537'
},
};
console.log('Making request to create collection...');
try {
const response = await axios.post('https://api2.ordinalsbot.com/collection-upload', formData, options);
console.log(`Created collection. Response data: ${JSON.stringify(response.data)}`);
return response.data;
} catch (error: any) {
console.error(`Caught error while creating collection: ${error}`);
if (axios.isAxiosError(error)) {
if (error.response) {
console.error('Error details:', error.response.data);
} else {
console.error('Error:', error.message);
}
} else {
console.error('Error:', error.message);
}
}
}
console.log('Starting collection creation...');
createCollection()
.then(() => {
console.log(`${constants.collectionOptions.id} creation process completed. Here are the details of the collection:
- Collection ID: ${constants.collectionOptions.id}
- Number of pieces: ${constants.mintOptions.totalSupply}
- Art file extension: ${constants.mintOptions.artFilesExtension}
- Collection creator: ${constants.collectionOptions.creator}
- Public mint price: ${constants.mintOptions.publicMintPrice} BTC
- Recipient BTC address: ${constants.mintOptions.recipientBTCAddress}
- Image optimization: ${constants.mintOptions.optimizeImages}`);
console.log('Please join the OrdinalsBot discord and open a ticket to get your collection approved.');
console.log('\x1b[34m%s\x1b[0m', 'https://discord.gg/9nBhVgCjct');
})
.catch(error => {
console.error(`Error during collection creation process: ${error.message}`);
});