OpenZeppelin / openzeppelin-contracts

OpenZeppelin Contracts is a library for secure smart contract development.
https://openzeppelin.com/contracts
MIT License
24.8k stars 11.77k forks source link

File not found: ERC721URIStorage #5064

Closed Ajinkya-kamble7 closed 3 months ago

Ajinkya-kamble7 commented 4 months ago

πŸ’» Environment

πŸ“ Details

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

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

contract MyNft is ERC721URIStorage, Ownable{

    using Counters for Counters.Counter;

    Counter.Counter private _tokenIds;
    constructor() ERC721("MY Nft","CRE"){}
    function mintnft(address recipient,string memory tokenURI)public onlyOwner returns(uint264){
      _tokenIds.increment();
    }

}

Error: [{ "resource": "/D:/NFT/contracts/MyNft.sol", "owner": "solidity-language-server", "code": "6275", "severity": 8, "message": "Source \"@openzeppelin/contract/token/ERC721/extensions/ERC721URIStorage.sol\" not found: File not found. Searched the following locations: \"\".", "source": "solidity", "startLineNumber": 8, "startColumn": 1, "endLineNumber": 8, "endColumn": 78 }]

πŸ”’ Code to reproduce bug

cairoeth commented 4 months ago

@ajinkyablockchain there are a few typos in your imports. should be:

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

You also need to inherit ERC721, asides from ERC721URIStorage and Ownable. You should check out our Wizard tool, which will make it easier to get a working implementation: https://wizard.openzeppelin.com/#erc721