-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
script to add a new course at NFT Contract
- Loading branch information
1 parent
2d59b62
commit 7b22ec5
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |