-
-
Save farzaa/483c04bd5929b92d6c4a194bd3c515a5 to your computer and use it in GitHub Desktop.
| const main = async () => { | |
| const nftContractFactory = await hre.ethers.getContractFactory('MyEpicNFT'); | |
| const nftContract = await nftContractFactory.deploy(); | |
| await nftContract.deployed(); | |
| console.log("Contract deployed to:", nftContract.address); | |
| // Call the function. | |
| let txn = await nftContract.makeAnEpicNFT() | |
| // Wait for it to be mined. | |
| await txn.wait() | |
| console.log("Minted NFT #1") | |
| txn = await nftContract.makeAnEpicNFT() | |
| // Wait for it to be mined. | |
| await txn.wait() | |
| console.log("Minted NFT #2") | |
| }; | |
| const runMain = async () => { | |
| try { | |
| await main(); | |
| process.exit(0); | |
| } catch (error) { | |
| console.log(error); | |
| process.exit(1); | |
| } | |
| }; | |
| runMain(); | |
| require('@nomiclabs/hardhat-waffle'); | |
| module.export = { | |
| solidity: '0.8.0', | |
| networks: { | |
| rinkeby: { | |
| url: 'YOUR ALCHEMY_API_URL', | |
| accounts: ['YOUR_PRIVATE_RINKEBY_ACCOUNT_KEY'], | |
| }, | |
| }, | |
| };` |
| pragma solidity 0.8.0; | |
| import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
| import "@openzeppelin/contracts/utils/Counters.sol"; | |
| import "hardhat/console.sol"; | |
| contract MyEpicNFT is ERC721URIStorage { | |
| using Counters for Counters.Counter; | |
| Counters.Counter private _tokenIds; | |
| constructor() ERC721 ("SquareNFT", "SQUARE") { | |
| console.log("This is my NFT contract. Woah!"); | |
| } | |
| function makeAnEpicNFT() public { | |
| uint256 newItemId = _tokenIds.current(); | |
| _safeMint(msg.sender, newItemId); | |
| _setTokenURI(newItemId, "https://jsonkeeper.com/b/RUUS"); | |
| _tokenIds.increment(); | |
| console.log("An NFT w/ ID %s has been minted to %s", newItemId, msg.sender); | |
| } | |
| } |
| const main = async () => { | |
| const nftContractFactory = await hre.ethers.getContractFactory('MyEpicNFT'); | |
| const nftContract = await nftContractFactory.deploy(); | |
| await nftContract.deployed(); | |
| console.log("Contract deployed to:", nftContract.address); | |
| // Call the function. | |
| let txn = await nftContract.makeAnEpicNFT() | |
| // Wait for it to be mined. | |
| await txn.wait() | |
| txn = await nftContract.makeAnEpicNFT() | |
| // Wait for it to be mined. | |
| await txn.wait() | |
| }; | |
| const runMain = async () => { | |
| try { | |
| await main(); | |
| process.exit(0); | |
| } catch (error) { | |
| console.log(error); | |
| process.exit(1); | |
| } | |
| }; | |
| runMain(); | |
Amazing Stuff !! ✨✨
hardhat-config-js have a symbol ` which should be removed
amazing!, thank you
accounts: ['YOUR_PRIVATE_RINKEBY_ACCOUNT_KEY'] which private key is it ( is it the rinkbey test network private key on my metamask wallet or is it something else?
@cl-rs yes the private key on your metamask wallet.
hardhat.config.js to git.
If you want to commit to git, use dotenv.
hardhat.config.js
...
require('dotenv').config();
...
module.exports = {
solidity: ...,
networks: {
rinkeby: {
url: process.env.RINKEBY_URL,
accounts: [process.env.PRIVATE_KEY],
},
},
};
Create a file named .env in the source of the project with the following content
RINKEBY_URL=[REPLACE_BY_YOUR_ALCHEMY_URL]
PRIVATE_KEY=[REPLACE_BY_YOUR_METAMASK_PRIV_KEY]
Finally run npm instal env.
I'm not sure if this was necessary, but I added the 0x prior to the account key:
accounts: [0x${PRIVATE_RINKEBY_ACCOUNT_KEY}]
If yours isn't working, this might be why. Didn't try it without, so not sure if this is just common sense or if it was unnecessary.
big thanks mate!
In hardhat.config.js > line 3 > module.export = {
It should be module.exports = {
@farzaa
How about using parseEther so user does not have to use an external faucet for development, like you did in the waver portal
This would also be necessary I think
Kudos! 🍻