I'm currently working on an NFT project, using the openzeppelin ERC721 standard for the nfts.
When Inheriting the ERC721 NFT contract standard from openzeppelin you're required to pass in the "tokenName" and "tokenSymbol" for the nft in the constructor.
My issue with this is that in order to do this I need to hard-code the name of the nft and symbol into the contract before deploying. This code snippet is from an NFT contract that is going to be controlled from a different contract(A master contract), I need to be able to pass in information( e:g tokenName and tokenSymbol) from the master contract to the nft contract
hard-coding the tokenName and tokenSymbol into this nft contract is an issue.
Instead of hard coding, I want to be able to give the NFTs a dynamic name and symbol, when I deploy the contract from the master contract.
solidity version 0.8.4
This is a regular ERC721 constructor from openzeppelin; Token name "Metaverse Tokens" and symbol "METT" are hard-coded into the contract.
constructor (address marketPlaceAddress) ERC721 ("Metaverse Tokens", "METT") {
contractAddress = marketPlaceAddress;
}
This is my modified code; Token name and symbol are collected as inputs from the constructor in the contract.
// import erc721 token standard import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
// import extension to set token uri import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
contract NFT is ERC721URIStorage { // contract address of NFT dispenser address contractAddress; // keep track of tokens uint256 public tokenCount; string public tokenName; string public tokenSymbol;
constructor (address Dispenser, string memory _tokenName, string memory _tokenSymbol)
ERC721 ( tokenName , tokenSymbol) {
// use Dispenser address to deploy NFT contract
contractAddress = Dispenser;
// set the name of the token
tokenName = _tokenName;
// set the symbol of the token
tokenSymbol = _tokenSymbol;
// set the tokenCount to 0 on deployment
tokenCount = 0;
}
The issue with my code is that it doesn't pass in the name and symbol to the ERC721 contract that it inherits from, but the unmodified code passes them(name & symbol) in.
So my questions are as follows;
- How do you pass in a variable as a string to a constructor in solidity
- Am I on the right track with my code? and What do I need to change with my code to make this work
- Does the openZeppelin ERC721 contract not support this?
- Am I on the wrong track, and do you think I'm asking the wrong question
Please help