NFT Demos contains two examples of ERC‑721 non‑fungible tokens built with the Foundry framework.
- BasicNft – off-chain IPFS metadata.
- MoodNft – fully on-chain SVG that flips between HAPPY and SAD.
- Git
- Foundry (forge,cast,anvil)
- An Ethereum wallet and RPC endpoint (e.g. Sepolia or mainnet)
git clone https://github.com/web3pavlou/foundry-NFT-f23
cd foundry-NFT-f23
forge install
forge buildmake anvilforge test -vvvvor
forge test --fork-url $SEPOLIA_RPC_URLforge coverageSet your SEPOLIA_RPC_URL and PRIVATE_KEY as environment variables.Deployment is handled via the scripts located in the script/ directory:
# Deploy the BasicNft contract
make deploy $ARGS
# Deploy the MoodNft contract (reads and encodes SVGs)
make deployMood $ARGSAfter deployment, you can mint or flip tokens using the interaction scripts:
# Mint a BasicNft (uses a constant IPFS URI)
make mint $ARGS
# Mint a MoodNft
make mintMoodNft $ARGS
# Flip the mood of token 0 on the most recent MoodNft deployment
make flipMoodNft $ARGSOptionally, add your ETHERSCAN_API_KEY if you want to verify your contract on Etherscan.
To get the base64 of an image, you can use the following command:
echo "data:image/svg+xml;base64,$(base64 -i ./images/dynamicNft/happy.svg)"Then, you can get the base64 encoding of the json object by placing the imageURI into happy_image_uri.json then running:
echo "data:application/json;base64,$(base64 -i ./images/dynamicNft/happy_image_uri.json)"This project is licensed under the MIT License. See the LICENSE file for full license text.
- Cyfrin Updraft – Thanks to @patrickalphaC for the educational material
- Foundry – For the dev tools
- OpenZeppelin-For battle-tested libs