Mood NFT: Dynamic SVG-based NFTs
Blockchain DevelopmentNFT'sSVG'sERC721
Saturday, June 1, 2024
Mood NFT: Dynamic SVG-based NFTs on the Ethereum Blockchain
Objective:
Developed an innovative Mood NFT project using Solidity and Foundry, leveraging SVGs to create dynamic NFTs that visually change based on the owner's mood.
Technical Skills and Tools Used:
- Languages: Solidity
- Frameworks/Libraries: OpenZeppelin Contracts, Forge-Std
- Technologies/Tools: Ethereum, Foundry, MetaMask, ERC721
Functionality Overview:
Dynamic SVG-based NFTs:
Implemented an NFT that can display different emotions using scalable vector graphics (SVGs), allowing for on-chain storage and dynamic rendering of NFT images.
- Happy State: Represents a joyful state with a unique SVG.
- Sad State: Reflects a sorrowful mood with a different SVG.


Smart Contract Features:
- Using Enums: Utilized Solidity enums to switch between the "Happy" and "Sad" states.
- Encoding SVGs: SVG images are encoded in Base64 and stored on-chain, reducing gas costs.
- Dynamic Rendering: The NFT’s appearance changes based on its state, which is queried and rendered in real-time.
Technical Details:
Smart Contract Implementation:
- Solidity: Developed the smart contract using Solidity to ensure secure and efficient NFT management.
- OpenZeppelin: Leveraged OpenZeppelin's ERC721 contract for NFT functionality and Ownable contract for ownership management.
- Base64 Encoding: Used Base64 encoding to store SVG data on-chain, enabling dynamic image rendering.

NFT Functionality:
- Minting NFTs: Users can mint new NFTs with embedded SVG images.
- Mood Flipping: NFT owners can change the mood (state) of their NFTs, switching between "Happy" and "Sad".
- Token URI: The token URI dynamically generates metadata, including the appropriate SVG based on the current mood.
Project Insights and Achievements:
- Security: Ensured the contract's security by implementing role-based access control and thorough testing.
- Efficiency: Demonstrated efficiency in developing and deploying a dynamic NFT mechanism on the blockchain.
- Interoperability: Achieved seamless interoperability through a helper configuration that enables deployment to mainnet, testnet, and local environments.
- Streamlined Deployment: Included a Makefile to streamline the deployment process across different networks.

Detailed Breakdown:
Smart Contract Features:
- SVG Integration: Embedded SVGs directly into the smart contract, allowing on-chain storage and dynamic image updates.
- State Management: Utilized enums to manage and switch NFT states efficiently.
- Event Logging: Implemented event logging for transparency and tracking of key contract activities.
Testing and Deployment:
- Foundry Testing: Conducted comprehensive testing using Foundry to ensure robust contract functionality.
- Deployment: Deployed the contract on local and test networks using Foundry and a streamlined Makefile for efficient deployment.
- Overall, the Mood NFT project showcased my ability to integrate dynamic SVG rendering within NFTs, providing a unique and interactive user experience.