From 7b22ec5174de0ae8c1e9f3321844338c8dfaea18 Mon Sep 17 00:00:00 2001 From: Yan Luiz Date: Thu, 1 Aug 2024 21:50:12 -0300 Subject: [PATCH] script to add a new course at NFT Contract --- nfts/scripts/addCourse.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 nfts/scripts/addCourse.js diff --git a/nfts/scripts/addCourse.js b/nfts/scripts/addCourse.js new file mode 100644 index 00000000..d8bbab6f --- /dev/null +++ b/nfts/scripts/addCourse.js @@ -0,0 +1,39 @@ +require('dotenv').config({ path: '../.env' }) +const { ethers } = require('hardhat') + +async function main() { + // Load environment variables + const contractAddress = process.env.NFT_BOOTCAMP_CONTRACT_ADDRESS + + if (!contractAddress) { + console.error( + 'Please set the NFT_BOOTCAMP_CONTRACT_ADDRESS environment variable in the .env file' + ) + process.exit(1) + } + + // Get the first signer from Hardhat's configured signers + const [signer] = await ethers.getSigners() + console.log('Signer address:', signer.address) + + // Connect to the contract + const contract = await ethers.getContractAt('W3DBootcamp', contractAddress, signer) + + // Define function parameters + const newCourse = 'Rust State Machine' + const description = `Certification for completing the ${newCourse} Bootcamp` + + // Call the addCourse function + const tx = await contract.addCourse(newCourse, description) + + // Wait for the transaction confirmation + await tx.wait() + console.log('Course registered at:', tx.hash) +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error) + process.exit(1) + })