NFT avatar for Traveloggers.
Tools and components:
- Hardhat: interacting with, testing and deploy smart contract.
- Openzepplin Contracts: componentized and standard smart contracts.
Services:
- Alchemy: Ethereum node as a service
- Infura IPFS: IPFS storage service with NFT metadata standard.
Install dependencies:
npm i
Copy environment variables:
cp .env.json.example .env.json
Fill in the following environment variables:
network
: current network name, can belocalhost
,rinkeby
ormainnet
infuraAPIKey
: API key for Infura ETH servicedeployerAddress
: address of deployer accountdeployerPrivateKey
: private key of deployer accountcontractAddress
: address of NFT contractinfuraIPFSId
: Project ID of Infura IPFSinfuraIPFSSecret
: Project Secret of Infura IPFScoinmarketcapKey
: use Coinmarketcap API to get price of ETH and estimate gas costetherscanKey
: use Etherscan API to verify the contract
Build contract (optional):
npm run build
Unit test:
npm run test
Deploy contract to Hardhat Network:
npm run localhost:deploy
Start Hardhat Network:
npm run localhost:start
Launch interactive console:
npm run localhost:console
Generate avatar metadata files in assets/metadata
according to attributes in scripts/settings.json
.
- Each file is named by avatar id.
- Field
image
references file name inassets/images
.
Store image and metadata to IPFS, then add base_uri
in data/${network}/state.json
.
- Add to IPFS images referenced in
assets/metadata/${tokenID}
, throw error if an image doesn't exists inassets/images
. - Update filed
image
inassets/metadata/${tokenID}
with image IPFS hash. - Add
assets/metadata
as a whole directory to IPFS, and addbase_uri
indata/${network}/state.json
with the resulting hash.
Deploy contracts to the given network and add contract_address
in data/${network}/state.json
.
- Read
base_uri
indata/${network}/state.json
for deployment. - Add
contract_address
indata/${network}/state.json
.
Mint NFTs to the given addresses with inputs file.
- Result will be updated back to input files.
# batch mint
npm run localhost:mint:batch -- --inputs ./data/localhost/sample-mint-batch.json
# lottery mint
npm run localhost:mint:lottery -- --inputs ./data/localhost/sample-mint-lottery.json