Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deployed on holesky testnet #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
node_modules
.env

# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types

# solidity-coverage files
/coverage
/coverage.json

# Hardhat Ignition default folder for deployments against a local node
ignition/deployments/chain-31337
130 changes: 8 additions & 122 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,127 +1,13 @@
# 📝 Assignment for Week 4: NFTs and the Metaverse
# Sample Hardhat Project

In this week's assignment, we will work on building a simple NFT contract, setting up Hardhat tasks, and creating test cases to ensure proper functionality. The tasks involve deploying, minting, and interacting with an NFT smart contract, which we'll build using OpenZeppelin and Hardhat.
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a Hardhat Ignition module that deploys that contract.

## Exercise Breakdown
Try running some of the following tasks:


### Exercise 0 : Initialise your Hardhat project

```
mkdir nft-project
cd nft-project
npx hardhat
```

make sure to use `.env` file for sensetive info.


#### IMPORTANT : The given files are just for helping purposes and giving idea of the structure of the project.
This repo contains Demo codes for the files without the depandancies.

### Exercise 1: Create Your Solidity Contract
You will write a simple ERC721-based contract for minting NFTs using OpenZeppelin libraries.

The contract file is located at:

- [contracts/MyNFT.sol](contracts/MyNFT.sol)

### Exercise 2: Create Hardhat Tasks for Deploying and Minting NFTs
We will create tasks to deploy the NFT contract and mint NFTs using Hardhat.

The task file is located at:

- [tasks/nft.ts](tasks/nft.ts)

### Exercise 3: Create Helpers
The helpers for interacting with our contract and environment variables are implemented in the following files:

- [lib/contract.ts](lib/contract.ts)
- [lib/env.ts](lib/env.ts)
- [lib/provider.ts](lib/provider.ts)
- [lib/wallet.ts](lib/wallet.ts)

### Exercise 4: Create Tests
We will write unit and integration tests to validate the NFT contract functionality. The tests will check minting functionality and balance tracking.

Test files:

- [test/MyNFT.spec.ts](test/MyNFT.spec.ts) – Unit tests for the NFT contract.
- [test/tasks.spec.ts](test/tasks.spec.ts) – Integration tests for Hardhat tasks.
- [test/test-helpers.ts](test/test-helpers.ts) – Helpers used in the tests.

### Exercise 5: Hardhat Configuration
We will configure Hardhat to use the Alchemy API and connect to the Sepolia test network.

Configuration file:

- [hardhat.config.ts](hardhat.config.ts)

---

## Useful Commands


- Compile the smart contracts:

```bash
npx hardhat compile
```

- Deploy the contract:

```bash
npx hardhat deploy-contract
```

- Mint an NFT:

```bash
npx hardhat mint-nft --tokenUri "https://example.com/token-metadata"
```

---

## Running Tests

To run the test cases, execute:

```bash
```shell
npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat ignition deploy ./ignition/modules/Lock.js
```

Example output:

```
mintNft
✓ calls through and returns the transaction object (60ms)

MyNFT
mintNft
✓ emits the Transfer event (60ms)
✓ returns the new item ID
✓ increments the item ID (57ms)
✓ cannot mint to address zero
balanceOf
✓ gets the count of NFTs for this address

6 passing (2s)
✨ Done in 5.66s.
```

---

## Resources

- [OpenZeppelin Documentation](https://docs.openzeppelin.com/)
- [Hardhat Documentation](https://hardhat.org/getting-started/)

## What to Submit

- A link to your GitHub Pull Request with the implemented contract and tasks.

- Head over to the Coursework submission link: [Google Form](https://docs.google.com/forms/d/e/1FAIpQLScspmFUymr7wMW9HxjwRSlSa1Zxnnj9H3LJK6Y9xsPeus-iCw/viewform?usp=sf_link) to submit your work.

Inform your UniDAO lead once the submission has been made.

Feel free to ask any questions or seek clarification on Discord.
17 changes: 17 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require("@nomicfoundation/hardhat-toolbox");
require('dotenv').config();
require("./tasks/nft");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.0",
networks: {
localhost: {
url: "http://localhost:8545",
},
holesky: {
url: process.env.HOLESKY_RPC_URL,
accounts: [process.env.ETH_PRIVATE_KEY],
}
}
};
24 changes: 0 additions & 24 deletions hardhat.config.ts

This file was deleted.

15 changes: 15 additions & 0 deletions lib/contract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const {ethers} = require("ethers");
require("@nomicfoundation/hardhat-toolbox");
const {env} = require("./env");
const {getProvider} = require("./provider");

async function getContract(name, hre) {
const WALLET = new ethers.Wallet(env("ETH_PRIVATE_KEY"), getProvider());

// Use hre.ethers.getContractAt here:
return await hre.ethers.getContractAt(name, env("NFT_CONTRACT_ADDRESS"), WALLET);
}

module.exports = {
getContract
};
13 changes: 0 additions & 13 deletions lib/contract.ts

This file was deleted.

9 changes: 7 additions & 2 deletions lib/env.ts → lib/env.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
export function env(key: string): string {
function env(key) {
console.log(process.env.key);
const value = process.env[key];
if (value === undefined) {
throw `${key} is undefined`;
}
return value;
}
}

module.exports = {
env
}
17 changes: 17 additions & 0 deletions lib/provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const ethers = require('ethers');
require('dotenv').config(); // Ensure environment variables are loaded

function getProvider() {
const alchemyApiKey = process.env.ALCHEMY_API_KEY;

if(!alchemyApiKey) {
throw new Error("Missing Alchemy API key in environment variables.");
}

// Construct the provider with the correct RPC URL
return new ethers.JsonRpcProvider(`https://eth-ropsten.alchemyapi.io/v2/${alchemyApiKey}`);
}

module.exports = {
getProvider
}
7 changes: 0 additions & 7 deletions lib/provider.ts

This file was deleted.

11 changes: 11 additions & 0 deletions lib/wallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const {ethers} = require('ethers');
const {env} = require('./env');
const {getProvider} = require('./provider');

function getWallet() {
return new ethers.Wallet(env("ETH_PRIVATE_KEY"), getProvider());
}

module.exports = {
getWallet
}
7 changes: 0 additions & 7 deletions lib/wallet.ts

This file was deleted.

Loading