Hey folks, I’m stuck on a tricky issue with my NFT project. I’m trying to build a platform where users can mint their own ERC721 tokens by providing a name, symbol, and URL. The problem is, after the first token is minted, the name and symbol don’t change for subsequent mints. They’re stuck on the values from the first token.
I’m using OpenZeppelin’s ERC721 implementation. Here’s a simplified version of my contract:
When I check on PolygonScan, only the first token’s name and symbol are shown, even for later mints. Any ideas on how to make this dynamic? Thanks in advance!
hey there ray84, i’ve run into this before. the thing is, ERC721 contracts arent really made for changing names/symbols per token. what you could do is keep a separate mapping for each token’s info instead of trying to change the whole contract’s name/symbol every time. that way each token can have its own unique data without messing with the main contract stuff.
hey ray84, interesting project you’ve got there! i’m curious, have you considered using a factory contract approach? it could solve your issue and give each token collection its own unique identity.
how about creating a contract that deploys a new ERC721 contract for each user? that way, every time someone wants to mint, you create a fresh contract with their desired name and symbol. it’d be like:
contract NFTFactory {
function createNFTCollection(string memory name, string memory symbol) public returns (address) {
CustomNFT newNFT = new CustomNFT(name, symbol);
return address(newNFT);
}
}
then users can mint on their personal contract. what do you think? could this work for your project? i’d love to hear more about what you’re building!
I’ve encountered a similar issue in my own NFT projects. The problem lies in how ERC721 contracts handle the name and symbol. These are typically set in the constructor and aren’t meant to be changed dynamically for each token.
Instead of trying to modify the contract’s name and symbol for each mint, consider creating a separate mapping to store individual token metadata. You could use a struct to hold the name, symbol, and URI for each token ID. This approach allows you to maintain unique metadata for each token without altering the contract’s core properties.
Here’s a rough idea of how you might implement this: