-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpin_nft_assets.js
50 lines (38 loc) · 1.4 KB
/
pin_nft_assets.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
41
42
43
44
45
46
47
48
49
50
const fs = require('fs')
const { NFTStorage, File } = require('nft.storage')
const dotenv = require('dotenv');
dotenv.config();
async function uploadData(baseFileName, isJPG) {
let imgType
if (isJPG)
imgType = 'jpg'
else
imgType = 'png'
const client = new NFTStorage({ token: process.env.NFT_STORAGE_API_KEY });
console.log('Uploding image...');
const imageData = fs.readFileSync(`./assets/${baseFileName}.${imgType}`)
const imageFile = new File([imageData], `${baseFileName}.${imgType}`, { type: `image/${imgType}` });
const imageCID = await client.storeBlob(imageFile);
console.log('Uploding mp4...');
const animationData = fs.readFileSync(`./assets/${baseFileName}.mp4`)
const animationFile = new File([animationData], `${baseFileName}.mp4`, { type: ' video/mp4' });
const animationCID = await client.storeBlob(animationFile);
return {
imageCID,
animationCID
}
}
async function main() {
const { imageCID, animationCID } = await uploadData('active_members_badge', false)
console.log('================================================');
console.log(`Image CID: ${imageCID}`)
console.log(`Animation CID: ${animationCID}`)
console.log('Put those two hashes in the argument.js file');
console.log('================================================');
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});