0

I have a doubt wich is if its possible to have different mint functions pointing to different tokenURI.

Lets say i have 2 mint functions and 2 variables called tokenURI1 and TokenURI2 just like this:

String tokenURI1 = ipfs://test1;
String TokenURI2 = ipfs://test2;

 function mint1(uint256 _mintAmount) public payable {
    _safeMint(_msgSender(),_mintAmount);
  }

 function mint2(uint256 _mintAmount) public payable {
    _safeMint(_msgSender(),_mintAmount);
  }

It is possible to if someone mint in the mint1 function that saves in the memory the url of the tokenURI1 with that token, and if someones mint in the mint2 function that saves in the memory the url of the tokenURI2?

The idea of this is create multiple mint functions in just one smart contract with different images but remaining in the same collection.it is possible to do? how to do that?

2 Answers 2

0

It should be possible. For example the OpenZeppelin implementation allows overriding tokenURI(tokenId) function and return the corresponding URI depending on the tokenId.

enum TokenType { Type1, Type2 }

mapping (uint256 => TokenType) tokenType;

function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
    if (tokenType[tokenId] == TokenType.Type1) {
        return string(abi.encodePacked(tokenURI1, tokenId.toString()));
    } else {
        return string(abi.encodePacked(tokenURI2, tokenId.toString()));
    }
}
5
  • How do i pass the "Type1, Type2" TokenType inside the mint function? i tested a couple of times but still give me errors. Thanks for the help!
    – Pablo
    Commented Sep 10, 2022 at 21:59
  • @Pablo In mint functions you have to assign the correct type. For example for mint1 you have to do something like tokenType[tokenId] = TokenType.Type1;.
    – Ismael
    Commented Sep 11, 2022 at 2:32
  • Thanks for the reply. This is what i got .function mint1(uint256 _mintAmount, uint256 _tokenId) public payable { tokenType[_tokenId] = TokenType.Type1; _safeMint(_msgSender(), _mintAmount); } Right now when i mint i have to pass manually the tokenId, but that is not what we want, right? We need the current TokenId to be passed normally. How do i acommplish that? Sorry for the questions, im just trying to learn new things
    – Pablo
    Commented Sep 11, 2022 at 5:17
  • What is _mintAmount? Are you using OpenZeppelin contracts? In that case the _safeMint signature is _safeMint(address to, uint256 tokenId). If you want to assign tokenId automatically use something like OpenZeppelin Counters library. If you have another question it is better to create a new one.
    – Ismael
    Commented Sep 12, 2022 at 4:29
  • I already have, the url is ethereum.stackexchange.com/questions/135500/…
    – Pablo
    Commented Sep 13, 2022 at 4:18
0

It's absolutely possible.

My contract does exactly this. 100%

Allows the owner to - after deployment - add volumes, and correspond tokens to those volumes, that are then minted cleanly on our dApp (and of course more rudimentary in contract itself), based on what volume the minter has chosen. Each volume gets its own associated merkle root as well, in order to whitelist every volume differently, and separate.

You have one deployed contract, with the appearance and control of numerous collections thereafter, all falling under the same deployment address.

You can see it here currently (in its latest test performance;

https://goerli.etherscan.io/address/0x94793fedc87ca4f42fbafee3807709522f5f9b11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.