ERC721 token uri error

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.6.0/contracts/token/ERC721/ERC721.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.6.0/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.6.0/contracts/utils/Counters.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.6.0/contracts/utils/Strings.sol";

contract boreape is ERC721, Ownable {
using Counters for Counters.Counter;
using Strings for uint256;

Counters.Counter private _tokenIds;

uint256 public constant MAX_SUPPLY = 10;
uint256 public constant MAX_PER_WALLET = 5;
string public uriPrefix = "ipfs://b--------------------q/";
string public uriSuffix = ".json";
mapping(address => uint256) public tokenCount;

constructor() ERC721("Bored Ape ", "BAYC") {}

function mint(address to, uint256 amount) public {
    require(amount > 0, "Amount cannot be zero");
    require(tokenCount[to] + amount <= MAX_PER_WALLET, "Exceeds maximum tokens per wallet");
    require(_tokenIds.current() + amount <= MAX_SUPPLY, "Exceeds maximum supply");

    for (uint256 i = 0; i < amount; i++) {
        _tokenIds.increment();
        uint256 newItemId = _tokenIds.current();
        _mint(to, newItemId);
        tokenCount[to]++;
    }
}

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

    string memory currentBaseURI = _baseURI();
    return bytes(currentBaseURI).length > 0
        ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), uriSuffix))
        : "";
}

function _baseURI() internal view virtual override returns (string memory) {
    return uriPrefix;
}

function totalSupply() public view returns (uint256) {
    return _tokenIds.current();
}

}

I am facing issue if i am using the imports without the github
Is there any other way to set the tokenUri without the suffix and prefix pls guide me
Pls tell me what all imports i need to do then and how i should set the baseuri

What is the issue?


firstly I cant verify it on etherscan.

and if i replace the import statement with these kind of imports
import "[@openzeppelin/contracts/token/ERC721/ERC721.sol];
import "[@openzeppelin/contracts/access/Ownable.sol];
then i get this error
{DeclarationError: Undeclared identifier.

require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
| ^^^^^^^

firstly I cant verify it on etherscan.

and if i replace the import statement with these kind of imports
import "[@openzeppelin/contracts/token/ERC721/ERC721.sol];
import "[@openzeppelin/contracts/access/Ownable.sol];
then i get this error
{DeclarationError: Undeclared identifier.

require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
| ^^^^^^^

This is not proper syntax.

You should get rid of the square brackets, and add a closing double-quote before the semicolon:

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

DeclarationError: Undeclared identifier.
--> contracts/Tiar.sol:54:17:
|
54 | require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
| ^^^^^^^ then i get this error

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import "@openzeppelin/contracts/utils/Strings.sol";

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

contract is ERC721, Ownable {
using Counters for Counters.Counter;
using Strings for uint256;

Counters.Counter private _tokenIds;

uint256 public constant MAX_SUPPLY = 5;
string public uriPrefix = "";

string public uriSuffix = ".json";

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


function mint() public onlyOwner {
    uint256 currentSupply = _tokenIds.current();
    require(currentSupply < MAX_SUPPLY, "All tokens have already been minted");

    for (uint256 i = currentSupply; i < MAX_SUPPLY; i++) {
        _tokenIds.increment();
        uint256 newItemId = _tokenIds.current();
        _mint(owner(), newItemId);
    }
}

function airdrop(address[] calldata recipients, uint256[][] calldata tokenIds) public onlyOwner {
    require(recipients.length == tokenIds.length, "Recipients and tokenIds length mismatch");

    for (uint256 i = 0; i < recipients.length; i++) {
        address recipient = recipients[i];
        uint256[] calldata ids = tokenIds[i];

        for (uint256 j = 0; j < ids.length; j++) {
            uint256 tokenId = ids[j];
            require(ownerOf(tokenId) == owner(), "Token not owned by owner");
            _transfer(owner(), recipient, tokenId);
        }
    }
}

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

    string memory currentBaseURI = _baseURI();
    return bytes(currentBaseURI).length > 0
        ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), uriSuffix))
        : "";
}

function _baseURI() internal view virtual override returns (string memory) {
    return uriPrefix;
}

function totalSupply() public view returns (uint256) {
    return _tokenIds.current();
}

}

Here is the updated code

Are we supposed to guess the contents of this file???

What's this then?


sorry barakman i did'nt get you

You still need to answer this.

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

string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
    ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), uriSuffix))
    : "";

the error is pointing to this function

The error-message tells you that the symbol _exists is not declared anywhere.

yeah but how can i solve it ?pls can you help me with that

You can probably replace this with ownerOf(tokenId) != address(0).

thanks i tried that . Worked for me !

but at the time of verifying on etherscan . This error is shown

Compiler debug log:
Error! Unable to generate Contract Bytecode and ABI (General Exception, unable to get compiled [bytecode])
For troubleshooting, you can try compiling your source code with the Remix - Solidity IDE and check for exceptions

I am pasting the single contract file with the correct version of compiler

New problem --> new post (and mark this current post as solved).