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

week4 sol #15

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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@ MyNFT

Inform your UniDAO lead once the submission has been made.

Feel free to ask any questions or seek clarification on Discord.
Feel free to ask any questions or seek clarification on Discord.
29 changes: 14 additions & 15 deletions contracts/MyNFT.sol
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
// Contract based on https://docs.openzeppelin.com/contracts/4.x/erc721
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.20;

// Import the OpenZeppelin ERC721 and URI Storage contracts
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "hardhat/console.sol"; // Console is useful for debugging but can be removed in production

contract MyNFT is ERC721URIStorage {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
using Counters for Counters.Counter; // Using the Counters library
Counters.Counter private _tokenIds; // Counter for token IDs

constructor() ERC721("MyNFT", "MNFT") {}
constructor() ERC721("MyNFT", "MNFT") {} // Constructor initializes the ERC721 token

function mintNFT(address recipient, string memory tokenURI)
public
returns (uint256)
{
_tokenIds.increment();
// Function to mint a new NFT
function mintNFT(address recipient, string memory tokenURI) public returns (uint256) {
_tokenIds.increment(); // Increment the token counter

uint256 newItemId = _tokenIds.current();
_mint(recipient, newItemId);
_setTokenURI(newItemId, tokenURI);

return newItemId;
uint256 newItemId = _tokenIds.current(); // Get the current token ID
_mint(recipient, newItemId); // Mint the NFT
_setTokenURI(newItemId, tokenURI); // Set the URI for the newly minted token
return newItemId; // Return the new token ID
}
}
14 changes: 14 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type import('hardhat/config').HardhatUserConfig */
require("@nomicfoundation/hardhat-toolbox");
require('dotenv').config();
require("./tasks/nft.js");

module.exports = {
solidity: "0.8.20",
networks: {
sepolia: {
url: `https://eth-sepolia.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`,
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.

11 changes: 9 additions & 2 deletions lib/env.ts → lib/env.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
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