Skip to content

Commit

Permalink
script to add a new course at NFT Contract
Browse files Browse the repository at this point in the history
  • Loading branch information
nomadbitcoin committed Sep 11, 2024
1 parent 2d59b62 commit 7b22ec5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions nfts/scripts/addCourse.js
Original file line number Diff line number Diff line change
@@ -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)
})

0 comments on commit 7b22ec5

Please sign in to comment.