I tried adding ownable.sol to my code and it says Identifier already declared on this line at the top
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
This is my full code below
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "./Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
// Prevents re-entrancy attacks
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract NFTMarketPlace is ReentrancyGuard {
using Counters for Counters.Counter;
Counters.Counter private _itemIds; //Total number of item created
Counters.Counter private _itemsSold; // Total number of items sold
// owner of the smart contract
address payable owner;
//people have to pay to put their NFT on this MarketPlace
function setlistingPrice(uint256 price)
external onlyOwner() {
_listingPrice = price;
}
constructor (){
owner = payable(msg.sender);
}
struct MarketItem {
uint itemId;
address nftContract;
uint256 tokenId;
address payable seller;
address payable owner;
uint256 price;
bool sold;
}
//a way to access value of the MarketItem struct above by passing an integer ID
mapping(uint256 => MarketItem) private idMarketItem;
//Log messages (when item is sold)
event MarketItemCreated (
uint indexed itemId,
address indexed nftContract,
uint256 indexed tokenId,
address seller,
address owner,
uint256 price,
bool sold
);
/// @notice function to get listingPrice
function getlistingPrice() public view returns (uint256) {
return listingPrice;
}
/// @notice function to create MarketItem
function createMarketItem(
address nftContract,
uint256 tokenId,
uint256 price) public payable nonReentrant{
require(price > 0, "Price must be above zero");
require(msg.value == listingPrice,
"Price must be equal to listing Price");
_itemIds.increment(); // add 1 to the total number of item created
uint256 itemId = _itemIds.current();
idMarketItem[itemId] = MarketItem(
itemId,
nftContract,
tokenId,
payable(msg.sender), // address of the seller putting NFT for sale
payable(address(0)), //no owner yet (set owner to empty address)
price,
false
);
// transfer ownership of the nft to the contract itself
IERC721(nftContract).transferFrom(msg.sender, address(this), tokenId);
//Log this transaction
emit MarketItemCreated(
itemId,
nftContract,
tokenId,
msg.sender,
address(0),
price,
false);
}
/// @notice function to create a sale
function createMarketSale(
address nftContract,
uint256 itemId)
public
payable nonReentrant{
uint price = idMarketItem[itemId].price;
uint tokenId = idMarketItem[itemId].tokenId;
require(msg.value == price, "Please submit the asking price in order to complete purchase");
// pay the seller the amount
idMarketItem[itemId].seller.transfer(msg.value);
// transfer ownership of the nft from the contract itself to the buyer
IERC721(nftContract).transferFrom(address(this), msg.sender, tokenId);
idMarketItem[itemId].owner = payable(msg.sender); // mark buyer as new owner
idMarketItem[itemId].sold = true; // mark that it as been sold
_itemsSold.increment(); // increment the total number by items sold by 1
payable(owner).transfer(listingPrice); // Pay owner of the contract the listing price
}
/// @notice total number of Items unsold displayed on the dashboard
function fetchMarketItems() public view returns (MarketItem[] memory){
uint itemCount = _itemIds.current(); //Total number of item created on our MarketPlace
uint unsoldItemCount = _itemIds.current() - _itemsSold.current();
}
}