Reputation: 81
i'm using the ECR721 preset smart contract from Openzeppelin for studying.
I would like to add a new field when i mint new token to store a string (public).
At the moment there is only the field "to:address" (screenshot below)
I'm sure i need to add something in the mint function:
Upvotes: 1
Views: 1110
Reputation: 43491
Easiest way to store the message on blockchain is to emit an event. Event is permanently stored and publicly readable.
MintMessage
event outside the mint()
function. I don't recommend expanding the default Transfer
event that is used during minting, because external tools (such as Etherscan) might ignore the non-standard event and not show minted tokens as a result.mint()
functionMintMessage
event within the mint()
functionevent MintMessage(string message);
function mint(address to, string message) public virtual {
// keep the rest of your function as is
// add a new line emiting the event to the end of the function
emit MintMessage(message);
}
Upvotes: 3