I ran in to a problem With Solidity need Some help

I was Trying it for 3days to fixed it
it's Hashlips contracts/NFT/NFT_FULL.sol
The Problem it was I put in https://remix.ethereum.org He show an erro in (using Strings for uint256;) Strings
and I fixed it (import "@openzeppelin/contracts/utils/Strings.sol":wink: it's become ok but He show onther erro
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);

_exists(tokenId), exists it;s The erro Please I need some Help

1 Like

You have given very little information.

You have shared the tokenUri function and with that we can't know anything. could it be that you are querying an id that has not been minted?

1 Like

// SPDX-License-Identifier: GPL-3.0

// Amended by HashLips
/**
!Disclaimer!
These contracts have been used to create tutorials,
and was created for the purpose to teach people
how to create smart contracts on the blockchain.
please review this code on your own before using any of
the following code for production.
HashLips will not be liable in any way if for the use
of the code. That being said, the code has been tested
to the best of the developers' knowledge to work as intended.
*/

pragma solidity >=0.7.0 <0.9.0;

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

contract NFT is ERC721Enumerable, Ownable {
using Strings for uint256;

string public baseURI;
string public baseExtension = ".json";
uint256 public cost = 0.05 ether;
uint256 public maxSupply = 10000;
uint256 public maxMintAmount = 20;
bool public paused = false;
bool public revealed = false;
string public notRevealedUri;
mapping(address => bool) public whitelisted;

constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
mint(msg.sender, 20);
}

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

// public
function mint(address _to, uint256 _mintAmount) public payable {
uint256 supply = totalSupply();
require(!paused);
require(_mintAmount > 0);
require(_mintAmount <= maxMintAmount);
require(supply + _mintAmount <= maxSupply);

if (msg.sender != owner()) {
    if(whitelisted[msg.sender] != true) {
      require(msg.value >= cost * _mintAmount);
    }
}

for (uint256 i = 1; i <= _mintAmount; i++) {
  _safeMint(_to, supply + i);
}

}

function walletOfOwner(address _owner)
public
view
returns (uint256 memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256 memory tokenIds = new uint256;
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}

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

if(revealed == false) {
    return notRevealedUri;
}

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

}

//only owner
function reveal() public onlyOwner {
revealed = true;
}

function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}

function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}

function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}

function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}

function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
baseExtension = _newBaseExtension;
}

function pause(bool _state) public onlyOwner {
paused = _state;
}

function whitelistUser(address _user) public onlyOwner {
whitelisted[_user] = true;
}

function removeWhitelistUser(address _user) public onlyOwner {
whitelisted[_user] = false;
}

function withdraw() public payable onlyOwner {
// This will pay HashLips 5% of the initial sale.
// You can remove this if you want, or keep it in to support HashLips and his channel.
// =============================================================================
(bool hs, ) = payable(0x943590A42C27D08e3744202c4Ae5eD55c2dE240D).call{value: address(this).balance * 5 / 100}("");
require(hs);
// =============================================================================

// This will payout the owner 95% of the contract balance.
// Do not remove this otherwise you will not be able to withdraw the funds.
// =============================================================================
(bool os, ) = payable(owner()).call{value: address(this).balance}("");
require(os);
// =============================================================================

}
}

at The first point The Error became (Using (String) and I fixed it (import "@openzeppelin/contracts/utils/Strings.sol"
again Error in _exists(tokenId), What should I do Please need Help

If you don't care a little so that we can understand you properly, you can't be helped no matter how much urgency you have.

Do not run. As they say in Spain "do it slowly because I'm in a hurry".

Then I recommend you to describe correctly what error you have, it is not clear at all. Copy the contract properly so that we do not have problems in understanding it.

If you help the one who has to help you, the help will come.

1 Like

It looks like a tutorial contract. You'll probably have all the code correctly posted somewhere. Re-post the contract correctly and please explain better the error you have, and when it reproduces itself to you.

1 Like

Thanks for your quick response error it's become in in

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

(_exists ) There's a red line

The tokenUri function you have to override does not have the _exist() function in the version you are using in your inheritance:

function tokenURI(uint256 tokenId) public view virtual returns (string memory) {
_requireOwned(tokenId);

    string memory baseURI = _baseURI();
    return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : "";
}
2 Likes

Your contract had a lot of weird stuff, like memory in int types or half-done arrays.

I'll pass you a code that compiles. But I recommend you to do the tutorial step by step to understand what you are doing.

Copying and pasting is very sweet but you won't learn anything. When you get an error again you will be in the same situation.

I would do the tutorial step by step and not try to run.

// SPDX-License-Identifier: GPL-3.0


pragma solidity >=0.7.0 <0.9.0;

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

contract NFT is ERC721Enumerable, Ownable {
using Strings for uint256;

string public baseURI;
string public baseExtension = ".json";
uint256 public cost = 0.05 ether;
uint256 public maxSupply = 10000;
uint256 public maxMintAmount = 20;
bool public paused = false;
bool public revealed = false;
string public notRevealedUri;
mapping(address => bool) public whitelisted;

constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) Ownable(msg.sender) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
mint(msg.sender, 20);
}

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

// public
function mint(address _to, uint256 _mintAmount) public payable {
uint256 supply = totalSupply();
require(!paused);
require(_mintAmount > 0);
require(_mintAmount <= maxMintAmount);
require(supply + _mintAmount <= maxSupply);

if (msg.sender != owner()) {
    if(whitelisted[msg.sender] != true) {
      require(msg.value >= cost * _mintAmount);
    }
}

for (uint256 i = 1; i <= _mintAmount; i++) {
  _safeMint(_to, supply + i);
}
}

function walletOfOwner(address _owner)
public
view
returns (uint[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}

function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
ownerOf(tokenId) != address(0);


if(revealed == false) {
    return notRevealedUri;
}

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

//only owner
function reveal() public onlyOwner {
revealed = true;
}

function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}

function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}

function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}

function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}

function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
baseExtension = _newBaseExtension;
}

function pause(bool _state) public onlyOwner {
paused = _state;
}

function whitelistUser(address _user) public onlyOwner {
whitelisted[_user] = true;
}

function removeWhitelistUser(address _user) public onlyOwner {
whitelisted[_user] = false;
}

function withdraw() public payable onlyOwner {
// This will pay HashLips 5% of the initial sale.
// You can remove this if you want, or keep it in to support HashLips and his channel.
// =============================================================================
(bool hs, ) = payable(0x943590A42C27D08e3744202c4Ae5eD55c2dE240D).call{value: address(this).balance * 5 / 100}("");
require(hs);
// =============================================================================

// This will payout the owner 95% of the contract balance.
// Do not remove this otherwise you will not be able to withdraw the funds.
// =============================================================================
(bool os, ) = payable(owner()).call{value: address(this).balance}("");
require(os);
// =============================================================================
}
}
1 Like

Wow Them There's no error in The Code You send To me Thank you so much

Brother When I try to verify The contract he show me When I upload contract file .sol

Compilation error: ["ParserError: Source "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol" not found: File not found. Searched the following locations: "".\n --> AfroAngels.sol:6:1:\n |\n6 | import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n", "ParserError: Source "@openzeppelin/contracts/access/Ownable.sol" not found: File not found. Searched the following locations: "".\n --> AfroAngels.sol:7:1:\n |\n7 | import "@openzeppelin/contracts/access/Ownable.sol";\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n", "ParserError: Source "@openzeppelin/contracts/utils/Strings.sol" not found: File not found. Searched the following locations: "".\n --> AfroAngels.sol:8:1:\n |\n8 | import "@openzeppelin/contracts/utils/Strings.sol";\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n"]

You had many errors in the code. You should check your shared file with mine to discover them. As I told you, you are going too fast and that is not good.

1 Like

You cannot verify contracts with direct imports from the openzeppelin library. Again, you are going too fast. See the tutorials that exist in this community for verifying contracts. You will have to flatten the contract or use hardhat for the deploy and subsequent verification through an API scan.

1 Like

Ok Sir Thank you for reply

1 Like