Reputation: 81
i'm learning solidity using Openzeppelin Framework.
Currently i'm using the ERC721 Preset Contract (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol)
I would like to add custom attributes for each token minted in order to store some important data on the blockchain (i would not use for certain attributes the REST API, but i prefer to write them on the chain).
Each token will have different data.
string: Name
string: Surname
bytes32: 0x63383a61613a62323a30373a63383a323020
Is it possible to do it creating some new functions (without editing the mint function), allowing only the addresses that have the minter role?
Upvotes: 5
Views: 2304
Reputation: 6131
Yes.
You can create a mapping between the tokenId and whatever you want it to have. Let's call it name
.
mapping(uint256 => string) name;
If you have a lot of attributes, you can do a mapping of a struct.
struct Character {
uint256 strength;
uint256 dexterity;
uint256 constitution;
uint256 intelligence;
uint256 wisdom;
uint256 charisma;
uint256 experience;
string name;
}
Character[] public characters;
mapping(uint256 => uint256) tokenIdToCharacterIndex;
Then, just make sure to update your tokenURI to include the on-chain attributes so that they show up in NFT marketplaces.
Upvotes: 6