Skip to content

About

Implementation of "MoodNft" with ERC721 standard using "OpenZeppelin", storing Dynamic NFT 100% on-chain using "SVG" format.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

ERC721 - Dynamic SVG

A ERC721 SVG Solidity Smart contract built on Foundry development framework.

Overview

The "MoodNft" smart contract inherits functions from "OpenZeppelin's" ERC721 standard to mint NFT, Insted of the usual reliance on "IPFS" to store NFT metadata off-chain, here we use "SVG" (Scalable Vector Graphics) files as our NFT, which can be stored 100% on-chain. This smart contract has an additional function which makes the SVG NFT Dynamic, which means we can change the metadata of a deployed NFT, here in this case using flipMood() changes a " Happy " NFT to " Sad " NFT.

SVG NFT in "MoodNFT" Collection

Happy Sad

Functionality

constructor(string memory mood1SvgImageUri, string memory mood2SvgImageUri) ERC721("MOOD NFT", "MNFT")

  • Initializes the ERC-721 with name/symbol, sets the token counter to 0 and stores the two on-chain SVG image URIs for the two moods (s_mood1SvgImageUri, s_mood2SvgImageUri).

function mintNft() public

  • Mints a new token to msg.sender using _safeMint with the current s_tokenCounter as tokenId, sets that token’s mood to Mood.M1, then increments s_tokenCounter.

function flipMood(uint256 tokenId) public

  • Toggles the stored Mood for tokenId between M1 ( happy ) and M2 ( sad ). First obtains the token owner via ownerOf(tokenId) and enforces authorization (_checkAuthorized) so only the owner or an approved operator may call it. Reverts if the token does not exist or caller is not authorized.

function tokenURI(uint256 tokenId) public view override returns (string memory)

  • Returns a data:application/json;base64, URI containing a base64-encoded JSON metadata blob. The image field is populated with the SVG URI corresponding to the token’s current mood (s_mood1SvgImageUri or s_mood2SvgImageUri). Calls into name() for the name field; reverts if tokenId does not exist (inherited check).

Interact

Interact with "MoodNft" smart contract deployed on Sepolia through Etherscan -

https://sepolia.etherscan.io/address/0xD026EF89A18392A7A5D171159E2256625AA6711e#code

About

Implementation of "MoodNft" with ERC721 standard using "OpenZeppelin", storing Dynamic NFT 100% on-chain using "SVG" format.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages