1

I'm actually trying to create an NFT Marketplace, where a user can upload his NFT (create/mint new NFT) and other users can give some Ether and mint the same NFT. Trying to achieve this with the ERC721 standard. Maybe ERC1155 will be a better choice but I have to use ERC721.

So, I think how I can achieve this using ERC721 by minting NFTs with different tokenIDs but with pointing to the same NFT metadata or TokenURI.

I know this is possible as mentioned in this post: Two ERC721 tokens that refer to the same metadata

But I can't fo it programatically.

This is how I'm trying: (It's not working, even 1 NFT is not showing on he opensea testnet)

// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";

contract navich is ERC721URIStorage, Ownable {

    using Strings for uint256;
    using Counters for Counters.Counter;

    Counters.Counter private _tokenId;
    string public baseURI = "ipfs://QmRyezUtChrpvH4i4wKEoPngwTFKHuu4YYjZrSg89wvqVq/";

    constructor() ERC721("Wagmi", "Wagmi") {}

    function mintNFT() public payable {
        uint256 dynamic = 1;
        _tokenId.increment();
        _mint(msg.sender, _tokenId.current());
        _setTokenURI(dynamic, baseURI);
    }

    function tokenURI(uint256 tokenId) public view override returns (string memory) {
        return
            string(
                abi.encodePacked(
                    baseURI,
                    tokenId.toString(),
                    ".json"
                )
            );
    }

    // function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
    //     require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

    //     return "ipfs://QmRyezUtChrpvH4i4wKEoPngwTFKHuu4YYjZrSg89wvqVq";
    // }

}

Pls, Help me out. I need to get this thing done asap. and btw this is not the full Marketplace code.

Thanks

1 Answer 1

1

I'm not convinced this is the best answer, because I found this post looking for a better one. But it at least works:

    // set the base uri at top of contract
    string public uri = "ipfs://<enter your cid here>"
    
    function tokenURI(uint256 _tokenId) public view override returns (string memory) {
        // _tokenId parameter required to override the base function
        // even though it's not used (same uri for all NFTs)

        return uri;
    }

What I don't like is the compiler complaining that I am not using the _tokenId variable. But if I remove it then it is not actually overriding the underlying tokenURI method so it has to stay.

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.