This is a repo about NFTs. This repo is similar to the NFT-dynamic-fully-on-chain and NFT-IPFS-VRF repos but all together and much complete. Testing is done in this repo.
Altough this repo is a similar implementation of the other 2 mentioned repos, this one is more structurated, is constructed in such a way that can be deployed on different chains automatically and testing is done and pinata is used to host NFT Uris.
This is a workshop from Patrick Alpha's FFC couse.
The workshop followed to complete this repo is this one.
The repo that we are going to implement is like this one.
We are creating 3 contracts for different NFT implementations:
- Basic NFT ✅.
- Random IPFS NFT ✅.
- Pros: Cheap.
- Cons: Someone needs to pin our data.
- Dynamic SVG NFT ✅.
- Pros: Data is on-chain.
- Cons: Much more expensive.
- Objetives: Mint an NFT based on the price of ETH
- If ETHprice > someNumer: NFT1
- if ETHprice < someNumber: NFT2
- Install yarn and start hardhat project:
yarn
yarn add --dev hardhat
yarn hardhat
- Install ALL the dependencies:
yarn add --dev @nomiclabs/hardhat-waffle@^2.0.0 ethereum-waffle@^3.0.0 chai@^4.2.0 @nomiclabs/hardhat-ethers@^2.0.0 ethers@^5.0.0 @nomiclabs/hardhat-etherscan@^3.0.0 dotenv@^16.0.0 eslint@^7.29.0 eslint-config-prettier@^8.3.0 eslint-config-standard@^16.0.3 eslint-plugin-import@^2.23.4 eslint-plugin-node@^11.1.0 eslint-plugin-prettier@^3.4.0 eslint-plugin-promise@^5.1.0 hardhat-gas-reporter@^1.0.4 prettier@^2.3.2 prettier-plugin-solidity@^1.0.0-beta.13 solhint@^3.3.6 solidity-coverage@^0.7.16 @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers ethers @chainlink/contracts hardhat-deploy hardhat-shorthand @aave/protocol-v2
- Install OpenZeppelin dependencies (contracts):
yarn add --dev @openzeppelin/contracts
- Install Base64 dependencies (to encode SVGs):
yarn add --dev base64-sol
- Use pinata:
yarn add --dev @pinata/sdk
yarn add --dev path
- Create uploadToPinata folder and execute:
yarn hardhat deploy --tags randomipfs
yarn hardhat compile
or
npx hardhat compile
If you want to use Hardhat shorthand:
yarn global add hardhat-shorthand
- Deploy to local network (Harhat by default):
hh compile
hh deploy
- Deploy to a TESTNET (Rinkeby): You can not deploy all scripts at the same time because you can deploy mint.js script without firtly add randomNFT to ConsumerBase.
To deploy every script expect mint.js:
yarn hardhat deploy --network rinkeby --tags main
Two types of tests are created for this project:
- "Unit tests" inside unit: used to test functions separately
To execute tests unit tests (on development chain):
yarn hardhat test
and to see test coverage:
yarn hardhat coverage
NOTICE: most of the below mentioned dependencies are already installed, just check it and include the corresponding requires
inside hardhat.config.js.
- If you want to execute solhint to search for potential Solidity errors Execute:
yarn solhint contracts/*.sol
-
If you want to use a text formarter: Check .prettierrc and .prettierignore.
-
To automatically verify our contract on etherscan:
yarn add --dev @nomiclabs/hardhat-etherscan
Then, include inside hardhat.config.js:
require("@nomiclabs/hardhat-etherscan");
Add ETHERSCAN_API_KEY
inside .env
file.
- Use Hardhat Gas Reporter:
yarn add --dev hardhat-gas-reporter
Then, include inside hardhat.config.js:
require("hardhat-gas-reporter");
- Use Solidity Coverage:
yarn add --dev solidity-coverage
Then, include inside hardhat.config.js:
require("solidity-coverage");
In order to execute it:
yarn hardhat coverage
- Use Hardhat Waffle:
yarn add @nomiclabs/hardhat-waffle
Then, include inside hardhat.config.js:
require("@nomiclabs/hardhat-waffle");
- BASIC NFT:
- RANDOM NFT:
- hardhat-nft-fcc: Patrick's repo for NFTs
- hardhat-starter-kit
- OpenZeppeling github: OpenZeppeling github
- Chainlink VRF: NECESARY for getting an actually random number
- Chainlink VRF contract addresses: Smart Contract addresses for Chainlink VRF (VRFCoordinator and Key Hash)
- Chainlink VRF subscription: Needed to create subscriptionId for using Chainlink VRF - Create subscription - add funds - get 'ID' - add deployed Smart Contract address as consumer
- pinata
- DYNAMIC SVG NFT:
- hardhat-nft-fcc: Patrick's repo for NFTs.
- hardhat-starter-kit
- OpenZeppeling github: OpenZeppeling github.
- ERC721 JSON example: remove 'https://'
- SVG documentation: SVG documentation and examples.
- SVG real time encoding: encode SVG and see result in real time.
- Base64.sol SmartContract: used to base64 encode SVGs
- Chainlink Data Feeds: Chainlink Data Feeds documentation for getting ETH price.
- Ethereum Price Data Feed: Needed when deploy