A tutorial that teaches how to make simple nfts that are procedurally generated and have onchain metadata and images.
mintTo
function that accepts the address that should receive the NFT.
msg.sender
is the users custodial address - where you want to send the NFT. This is not always the case with account abstraction. In some other implementations, msg.sender
is the smart contract address, even if the user signs in with an EOA. Regardless, it’s becoming a common practice to pass the address you want the NFT to go to explicitly.json
file on the traditional internet, you can put your metadata directly in the contract. To do so, first import some helper libraries:
override
the functions for _baseURI
and tokenURI
to return base 64 encoded json metadata with the appropriate information:
render
function:
viewbox
. Although not listed directly in the MDN page for rectangles, you can add a fill
property to add a fill color to any SVG element. You can use color names, or hex codes for colors:
tokenURI
function is called. Add a mapping to store this relationship:
tokenURI
Functionrender
function to generate the SVG.
tokenURI
function to use it, and return the SVG as base64 encoded data:
EnumerableSet
from OpenZeppelin:
uint
sets and add a mapping to relate addresses
to token ids.
_update
function to handle changes of ownership, including minting:
tokenURI
and an online or console base64 decoder to decode and check the json metadata and SVG image.