Skip to content

A customizable & dynamic NFT that blooms into a pretty flower when you water it 🌸

Notifications You must be signed in to change notification settings

dayana0425/blooming-flower-nft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blooming Flower NFT - A Customizable Dynamic NFT

  • Week 3 of Alchemy's Road To Web3 Challenge link
  • Made an NFT with On-Chain & Updatable Metadata, SVG Image, and Base64 Encoding

Choose Your Colors Here

Mint Your Blooming Flower NFT

  • Minting Inputs:
    • Name of your flower (ex: Your name...)
    • Background Color (CSS Hex Input, ex: "#8ef6e4")
    • Font Color of your flower's name (CSS Hex Input, ex: "#9896f1")
    • Seed Color (CSS Hex Input, ex: "#9896f1")

Example Mint Call:

let txn = await contract.mint("Dayana", "#8ef6e4", "#9896f1", "#9896f1");

Water Your Flower

  • Watering Inputs
    • Provide your flower's token ID (ex: 1)
    • Provide color for the new petal (CSS Hex Input, ex: "#f5c7f7")
    • You can only water your flower 8 times for it to complete.

Example Water Call:

txn = await contract.water(1, "#f5c7f7");

Example Output of Completed Flowers:

Quick Start

  • First, Fork & Clone Repository
yarn compile
yarn deploy
yarn test
yarn color

Debugging Tips

  • To test how your svg image is looking like without deploying to testnet & inspecting opensea eachtime (Been there, done that) I recommend:

    • Use this editor to paste your image's Base64 in the src of the img tag: https://www.w3docs.com/tools/code-editor/10848
    • How do you get the base64 image?
      • console.log() it in your solidity code
    • How do you console.log() in Solidity?
      • Add import "hardhat/console.sol"; to your file
      • Make sure you're running your script on --network hardhat
  • Example of pasting the base64 img into the editor above:

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <div>
      <img src="data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIxMyAtNCA0NjEgNDU1IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOmJ4PSJodHRwczovL3d3dy5ib3h5LXN2Zy5jb20vYngiPjxyZWN0IHdpZHRo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5lPSdtaWRkbGUnIHRleHQtYW5jaG9yPSdtaWRkbGUnPk1hZ2ljYWwgRmxvd2VyPC90ZXh0Pjwvc3ZnPg=="/>
    </div>
  </body>
</html>

Solidity - console.log(base64img):

    function generateFlower(uint256 id) internal returns(string memory){
        FlowerStats memory data = idToFlowerStats[id];
        bytes memory svg = abi.encodePacked(
            '<svg viewBox="13 -4 461 455" xmlns="http://www.w3.org/2000/svg" xmlns:bx="https://www.boxy-svg.com/bx">',
            string(abi.encodePacked("<rect width='100%' height='100%' fill='", data.background,"'/>")),
            getPetals(id),
            string(abi.encodePacked("<ellipse style='fill:", data.seed,";' cx='242.767' cy='223.713' rx='26.285' ry='25.904'/>")),
            string(abi.encodePacked("<text x='50%' y='95%' fill='", data.font, "' dominant-baseline='middle' text-anchor='middle'>")),
            data.name, 
            '</text>'
            '</svg>'
        );

        string memory base64img = 
              string(abi.encodePacked(
                "data:image/svg+xml;base64,",
                Base64.encode(svg))
              );

        if (data.level == 8) {
          console.log(base64img);
        }

        return base64img;
    }    

Testnet Walkthrough

About

A customizable & dynamic NFT that blooms into a pretty flower when you water it 🌸

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published