Build your own NFT based on the ERC-721 standard.
MyERC721
, that inherits from ERC721Token
. Add a constructor that initializes the _name
and _symbol
.
Reveal code
_safeMint
, is internal
. To use it to let your customers mint NFTs, you’ll need to implement a function in your contract that calls the one in the imported contract.
Before you can do that, you need a way to supply the two parameters needed for _safeMint
:
address to
- the owner of the new NFTuint256 tokenId
- the ID number for the new NFTmsg.sender
to grant ownership to the wallet doing the minting.
ID is slightly more challenging. A common practice is to simply assign the total number of NFTs, including the one being minted, as the tokenId
. Doing so is straightforward, makes it easier to find all of the NFTs within a collection, and helps lean in to the common community perception that lower-number NFTs are better, just like other limited-edition collectibles.
134
is a valid customer_id
, it is likely that 135
is too. The same can’t be said for bfcb51bd-c04f-42d5-8116-3def754e8c32
.This practice is not as useful on the blockchain, because all information is public.uint
called counter
to storage and initialize it as 1, either at declaration or in the constructor.
Now, you can add a function called redeemNFT
that calls safeMint
using the msg.sender
and counter
, and then increments the counter
:
Reveal code
undefined
, and “deleted” values return to their default value, which is 0 for numbers.To prevent security risks, you’ll need to make sure that you never give an ID or array index of 0 to anything. Otherwise, attempting to delete a value, such as a struct
member called authorizedSellerID
might give the wallet address stored at index 0 access to that resource.0x0000000000000000000000000000000000000000
json
file following the ERC721 Metadata JSON Schema
_baseURI
is virtual
and must be overridden by an inheriting contract.
Reveal code
_baseURI
that returns the appropriate selection based on which collection is active, and a function to swap the URI.
Reveal code
tokenURI
to find the information for token number 1. You should get:
switchURI
function and then call tokenURI
again for token 1.
Now, you’ll get a new link for metadata: