This project was created to research about smart contracts on Solidity to be deployed and executed in Mumbai testnet and Polygon mainet.
It uses Hardhat, OpenZeppelin, Alchemy... etc.
Assumes you have installed nodejs and npm
Create a new directory and install hardhat
mkdir NFTutorial
cd NFTutorial
npm install --save-dev hardhat
We recommend reviewing the hardhat documentation and tutorial.
Next, start a hardhat project
npx hardhat
Select "Create a sample hardhat project". You can say yes to everything.
Now you have a hardhat project ready to go!
First, install Open Zeppelin contracts
npm install @openzeppelin/contracts
Install waffle, ethers dependencies
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers
Install EtherScan
npm install --save-dev @nomiclabs/hardhat-etherscan
Install dotenv
npm install dotenv --save
You can delete Greeter.sol and use ThreeDigitals.sol ( rename de Collection )
Try customizing the solidity code with the name of your NFT if you want.
To compile the contract, just go
npx hardhat compile
Copy the .env.example
file in this directory to .env
(which will be ignored by Git)
cp .env.example .env
Then set each variable on .env
:
MUMBAI_URL
: The Alchemy URL to mumbai testnet got from your account.MATIC_URL
: The Alchemy URL to Polygon mainet (MATIC) got from your account.PRIVATE_KEY
: Private key of the account being used to deploy contract in polygon mainet.POLYGONSCAN_API_KEY
: Polygon API Key got from https://polygonscan.com/ website.
Use https://alchemy.com, blockchain developer platform.
To deploy smart contract to mumbai (Polygon testnet):
npx hardhat run --network mumbai scripts/deploy.js
To deploy smart contract to Polygon mainet (MATIC):
npx hardhat run --network matic scripts/deploy.js
First need create a virtual enviroment
npx hardhat node
Deploy smart contract on localhost
npx hardhat run --network localhost scripts/deploy.js
When you deploy you can verify your smart contract in polygonscan Chance DEPLOYED_YOUR_NFT_CONTRACT by the smart contract code followed by the fields that the constructor initializes
to Polygon mainet
npx hardhat verify --network matic <DEPLOYED_YOUR_NFT_CONTRACT>
to Polygon mumbai testnet
npx hardhat verify --network mumbai <DEPLOYED_YOUR_NFT_CONTRACT>
Use the Hardhat console
npx hardhat console
- contracts > Run test on smart contract
- generate > Generate X number of NFT images
- ipfs > Upload these images to ipfs using Pinata. Get CID (i.e. QmTiEQ4LLmaMFpsUTbDJthgnCoPygXmiaXRFU8DvsZvUD2)
- ipfs > Upload json metadata to Pinata. Get CID
- contracts > Update
deploy.js
to set X as max supply andhttps://ipfs.io/ipfs/<CID>
as baseURL - contracts > Deploy smart contract
- polygonscan > Complete form