Hey folks, I’m stuck with my NFT project. I’m trying to make a site where users can mint their own ERC721 tokens. The idea is they input a name, a symbol, and a URL for their NFT. However, when the first NFT is minted, the contract locks in that initial name and symbol, and any subsequent minting doesn’t update these values. I’m using OpenZeppelin’s library, but I’m not sure why it’s behaving this way.
Here’s a revised snippet of my code:
pragma solidity ^0.7.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract CustomNFT is ERC721 {
uint256 private tokenCounter;
constructor() ERC721("Initial", "INIT") {
tokenCounter = 0;
}
function createNFT(string memory tokenURI, string memory newName, string memory newSymbol) public returns (uint256) {
uint256 newTokenId = tokenCounter;
_safeMint(msg.sender, newTokenId);
_setTokenURI(newTokenId, tokenURI);
tokenCounter++;
// Attempting to update name and symbol on each mint
_name = newName;
_symbol = newSymbol;
return newTokenId;
}
}
When I look on PolygonScan, it still shows the initial name and symbol after additional NFTs are created. Has anyone encountered this issue or have ideas on how to ensure each NFT reflects the input name and symbol?
heyyy BrilliantCoder39! i feel ur pain with the nft name/symbol thing. it’s a tricky one for sure 
ive been playing around with nfts too and ran into similar issues. have u considered storing the custom names and symbols separately for each token? like, instead of trying to change the main contract details, u could keep a mapping of tokenId to custom data.
something like this maybe:
mapping(uint256 => TokenInfo) private _tokenInfo;
struct TokenInfo {
string customName;
string customSymbol;
}
function createNFT(string memory tokenURI, string memory newName, string memory newSymbol) public returns (uint256) {
uint256 newTokenId = tokenCounter;
_safeMint(msg.sender, newTokenId);
_setTokenURI(newTokenId, tokenURI);
_tokenInfo[newTokenId] = TokenInfo(newName, newSymbol);
tokenCounter++;
return newTokenId;
}
this way, u can keep track of unique names/symbols for each token without messing with the main contract stuff. when u need to display or use the custom info, just pull it from the mapping.
what do u think? could this work for ur project? lemme know if u wanna bounce more ideas around!
I understand your frustration with the name and symbol not updating for each NFT. Unfortunately, the ERC721 standard doesn’t support changing these values dynamically after contract deployment. The name and symbol are meant to identify the entire collection, not individual tokens.
For your use case, I’d recommend storing custom metadata for each token instead. You could create a mapping in your contract to associate each tokenId with its unique name and symbol:
mapping(uint256 => TokenMetadata) public tokenMetadata;
struct TokenMetadata {
string name;
string symbol;
}
Then in your createNFT function, store the custom data:
tokenMetadata[newTokenId] = TokenMetadata(newName, newSymbol);
This approach lets you maintain unique identifiers for each NFT while keeping the contract’s overall name and symbol constant. You’d need to create custom functions to retrieve this metadata when needed. Hope this helps solve your issue!
hey, i ran into this too. once deployed, erc721 name/symbol are fixed. try storing custom metadata in a mapping to record each token’s unique name and symbol. then, use that data when needed rather than trying to change the contract’s original values.