ERC721 - Mint NFT with exact property

Can I somehow mint NFT with an exact property like color: green. There are a lot of colors but I want to give the user option to choose the color. To pass it somewhere. Maybe in _safeMint but as I see I cannot do this with the _data parameter.
If you have any solution for this problem I will appreciate it.

1 Like

Hi, welcome.

It should be possible. The image or NFT itself will have to prepare to recieve this variations before producing output.

You can customize the ERC721 contract's mint function as follows:

contract MyNFT is ERC721 {
    mapping(uint256 => string) public tokenColorCode;

    function mintNFT (string memory colorCode) onlyOwner {
        // Call to SafeMint
        // Set ColorCode
        tokenColorCode[tokenId] = colorCode;


  • Contract MyNFT is inherited from OpenZeppelin's ERC721 & Ownable contracts
  • When displaying the NFT it's color code can be fetched from tokenColorCode
  • If you are storing NFT metadata on IPFS/S3 storage, then you should leave the tokenColorCode as empty and populate the same from the contract by giving call to MyNFT.tokenColorCode(tokenId)

I hope this helps

1 Like

Thanks for the fast reply, but I already have a collection. Let's say there are 4 colors - blue, orange, green, white. Every single color has a 25% rarity. My idea is to give the user chance to pick NFT from this already created collection based on his color preferences.
If there is no way for this I will use this "runtime" solution you mentioned. And how to add the color layer to the already created PNG if we use your solution.