MoodNFT is an ERC721 smart contract that allows users to mint NFTs that reflect their mood. Each NFT can flip between two moods: Happy and Sad. The contract is built using Solidity and leverages OpenZeppelin's ERC721 implementation.
- Mint MoodNFT: Users can mint an NFT that starts with a "Happy" mood.
- Flip Mood: The owner of the NFT can flip its mood between "Happy" and "Sad".
- Dynamic Metadata: The NFT's metadata updates dynamically based on its mood.
To use this contract, you need to have the following tools installed:
-
Clone the repository:
git clone https://github.com/TheOnma/mood-nft-project.git cd mood-nft
-
Install dependencies:
forge install
-
Compile the smart contract:
forge build
To deploy the MoodNFT contract, you will need to pass in the SVG image URIs for both the "Happy" and "Sad" states:
string memory sadSvgImageUri = "data:image/svg+xml;base64,...";
string memory happySvgImageUri = "data:image/svg+xml;base64,...";
MoodNft moodNft = new MoodNft(sadSvgImageUri, happySvgImageUri);
-
Minting an NFT:
moodNft.mintNft();
This mints a new NFT with an initial mood set to "Happy".
-
Flipping the Mood:
moodNft.flipMood(tokenId);
Only the owner of the NFT can flip its mood between "Happy" and "Sad".
-
Getting the Token URI:
string memory tokenUri = moodNft.tokenURI(tokenId);
This returns the metadata of the NFT, including its mood-specific image.
The mintNft
function allows any user to mint a new MoodNFT. The newly minted NFT will start with the "Happy" mood.
The flipMood
function allows the owner of the NFT to toggle its mood between "Happy" and "Sad". This operation is restricted to the NFT's owner.
The tokenURI
function generates the metadata URI for the NFT. The metadata includes the name, description, attributes, and mood-specific image URI of the NFT.
{
"name": "Mood NFT",
"description": "An NFT that reflects the owners mood.",
"attributes": [
{
"trait_type": "moodiness",
"value": 100
}
],
"image": "<imageURI>"
}
The contract includes custom error handling to ensure that only the owner of an NFT can flip its mood:
MoodNft__CantFlipMoodIfNotOwner
: This error is thrown if a user who is not the owner of the NFT attempts to flip its mood.
This project is licensed under the MIT License. See the LICENSE file for details.