Skip to content

Instantly share code, notes, and snippets.

@farzaa
Last active December 27, 2022 18:23
Show Gist options
  • Save farzaa/483c04bd5929b92d6c4a194bd3c515a5 to your computer and use it in GitHub Desktop.
Save farzaa/483c04bd5929b92d6c4a194bd3c515a5 to your computer and use it in GitHub Desktop.
End of Section #1 Code
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();
@sdkosm
Copy link

sdkosm commented Dec 30, 2021

Amazing Stuff !! ✨✨

@MatteoZhang
Copy link

hardhat-config-js have a symbol ` which should be removed

@mounyr
Copy link

mounyr commented Mar 2, 2022

amazing!, thank you

@bloodgroup-cplusplus
Copy link

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?

@mwrites
Copy link

mwrites commented Mar 9, 2022

@cl-rs yes the private key on your metamask wallet.

⚠️ Please make sure to not commit 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.

@RhaphePDX
Copy link

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.

@enesBurakElmal
Copy link

big thanks mate!

@Jake9811
Copy link

In hardhat.config.js > line 3 > module.export = {

It should be module.exports = {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment