UNPKG

@vechain/vebetterdao-contracts

Version:

Open-source repository that houses the smart contracts powering the decentralized VeBetterDAO on the VeChain Thor blockchain.

64 lines (63 loc) 2.69 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const promises_1 = __importDefault(require("fs/promises")); const helpers_1 = require("../../helpers"); const path_1 = __importDefault(require("path")); const description = "Creator NFT is a community of builders and innovators contributing to the VeBetter DAO ecosystem."; const METADATA_PATH = path_1.default.join(__dirname, "../../../metadata/creatorNFT/metadata"); const IMAGE_ZIP_PATH = path_1.default.join(__dirname, "../../../metadata/creatorNFT/images.zip"); const IMAGE_PATH = path_1.default.join(__dirname, "../../../metadata/creatorNFT/images"); /** * Generates the NFT metadata for a given level. * * @param name - The name of the level. * @param description - The description of the level. * @param imagesCID - The CID of the images directory on IPFS. * @param image - The image file for the level. * * @returns The generated NFT metadata. */ function generateMetadata(name, description, image) { return { name, description, image: image, }; } /** * Asynchronously saves the generated NFT metadata. * @param metadata - The `Metadata` object to save. */ async function saveMetadataToFile(metadata, fileName) { await promises_1.default.writeFile(`${METADATA_PATH}/${fileName}.json`, JSON.stringify(metadata, null, 2)); console.log(`Metadata saved to ${METADATA_PATH}/${fileName}`); } /** * Main function to generate and save NFT metadata. */ async function generateAndSaveMetadata() { try { // 1. Ensure the zip folder exists await (0, helpers_1.zipFolder)(IMAGE_PATH, IMAGE_ZIP_PATH); // 2. Upload images to IPFS and get URL const [imagesIpfsUrl, images, folderName] = await (0, helpers_1.uploadDirectoryToIPFS)(IMAGE_ZIP_PATH, IMAGE_PATH); console.log("Creator NFT Images IPFS URL:", (0, helpers_1.toIPFSURL)(imagesIpfsUrl, undefined, folderName)); const image = (0, helpers_1.toIPFSURL)(imagesIpfsUrl, images[0].name, folderName); const metadata = generateMetadata("VeBetterDAO Creator", description, image); await saveMetadataToFile(metadata, String(1)); } catch (error) { console.error("Error generating metadata:", error); throw error; // Rethrow the error after logging to handle it further up the call stack. } } // Generate and save the NFT metadata generateAndSaveMetadata() .then(() => process.exit(0)) .catch(error => { console.error("Unhandled error:", error); process.exit(1); });