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

Submitted week 4 assignment #11

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
Binary file added DS_Store
Binary file not shown.
127 changes: 0 additions & 127 deletions README.md

This file was deleted.

34 changes: 17 additions & 17 deletions contracts/MyNFT.sol
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
// Contract based on https://docs.openzeppelin.com/contracts/4.x/erc721
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyNFT is ERC721URIStorage {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
contract MyNFT is ERC721, Ownable {
uint256 private _tokenIdCounter;

constructor() ERC721("MyNFT", "MNFT") {}

function mintNFT(address recipient, string memory tokenURI)
public
returns (uint256)
{
_tokenIds.increment();

uint256 newItemId = _tokenIds.current();
_mint(recipient, newItemId);
_setTokenURI(newItemId, tokenURI);
constructor() ERC721("MyNFT", "MNFT") Ownable(msg.sender) {
_tokenIdCounter = 0;
}

function mintNFT(address recipient) public onlyOwner returns (uint256) {
require(recipient != address(0), "Cannot mint to zero address");

uint256 newItemId = _tokenIdCounter + 1;
_tokenIdCounter = newItemId;
_safeMint(recipient, newItemId);
return newItemId;
}

function getCurrentCounter() public view returns (uint256) {
return _tokenIdCounter;
}
}
17 changes: 17 additions & 0 deletions gitignore.txt
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
34 changes: 21 additions & 13 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
import("@nomiclabs/hardhat-ethers");
import("@nomiclabs/hardhat-waffle");
import dotenv from "dotenv";
import { HardhatUserConfig } from 'hardhat/config';
import '@nomicfoundation/hardhat-toolbox';
import * as dotenv from 'dotenv';
import './tasks/nft';

const argv = JSON.parse(env("npm_config_argv"));
if (argv.original !== ["hardhat", "test"]) {
require('dotenv').config();
}
dotenv.config();

import("./tasks/nft");

import { HardhatUserConfig } from "hardhat/config";
const ALCHEMY_API_KEY = process.env.ALCHEMY_API_KEY || '';
const PRIVATE_KEY = process.env.PRIVATE_KEY || '';

const config: HardhatUserConfig = {
solidity: "0.8.0",
solidity: {
version: '0.8.27',
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
networks: {
sepolia: {
url: `https://eth-sepolia.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY}`,
accounts: [process.env.ETH_PRIVATE_KEY],
url: `https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}`,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [],
},
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY || '',
},
};

export default config;
18 changes: 18 additions & 0 deletions library/contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Contract, ethers } from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { env } from "./env";
import { getProvider } from "./provider";

export async function getContract(
name: string,
hre: HardhatRuntimeEnvironment
): Promise<Contract> {

const WALLET = new ethers.Wallet(env("ETH_PRIVATE_KEY"), getProvider());

const contract = await hre.ethers.getContractAt(name, env("NFT_CONTRACT_ADDRESS"), WALLET);

return contract;
}

7 changes: 7 additions & 0 deletions library/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function env(key: string): string {
const value = process.env[key];
if (value === undefined) {
throw `${key} is undefined`;
}
return value;
}
7 changes: 7 additions & 0 deletions library/provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ethers } from "ethers";

export function getProvider(): ethers.Provider {
return ethers.getDefaultProvider("ropsten", {
alchemy: process.env.ALCHEMY_API_KEY,
});
}
7 changes: 7 additions & 0 deletions library/wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ethers } from "ethers";
import { env } from "./env";
import { getProvider } from "./provider";

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading