Need help on Marketplace Smart Contract

Hi, i’m following Cloning Rarible youtube tutorial and it works great. i am trying to added some function; charge listing fee for each item listed on marketplace in smart contract and create function to set Listing Fee by marketplace contract owner. However when i write code to set listingfee it become error.
“message”: “Referenced declaration is neither modifier nor base class.”,

pragma solidity ^0.8.0;

contract MarketContract{
    struct AuctionItem {
        uint256 id;
        address tokenAddress;
        uint256 tokenId;
        address payable seller;
        uint256 askingPrice;
        bool isSold;
    address payable owner;
    uint256 listingFee = 0.001 ether;
    AuctionItem[] public itemsForSale;
    mapping (address => mapping (uint256 => bool)) activeItems;

    event itemAdded(uint256 id, uint256 tokenId, address tokenAddress, uint256 askingPrice);
    event itemSold(uint256 id, address buyer, uint256 askingPrice);

    modifier OnlyItemOwner(address tokenAddress, uint256 tokenId){
        IERC721 tokenContract = IERC721(tokenAddress);
        require(tokenContract.ownerOf(tokenId) == msg.sender);

    modifier HasTransferApproval(address tokenAddress, uint256 tokenId){
        IERC721 tokenContract = IERC721(tokenAddress);
        require(tokenContract.getApproved(tokenId) == address(this));

    modifier ItemExists(uint256 id){
        require(id < itemsForSale.length && itemsForSale[id].id == id, "Could not find item");

    modifier IsForSale(uint256 id){
        require(itemsForSale[id].isSold == false, "Item is already sold!");

    /* Returns the listing fee of the contract */
    function getListingFee() public view returns (uint256) {
        return listingFee;

     function addItemToMarket(uint256 tokenId, address tokenAddress, uint256 askingPrice) OnlyItemOwner(tokenAddress,tokenId) HasTransferApproval(tokenAddress,tokenId) external returns (uint256){
        require(activeItems[tokenAddress][tokenId] == false, "Item is already up for sale!");
        uint256 newItemId = itemsForSale.length;
        itemsForSale.push(AuctionItem(newItemId, tokenAddress, tokenId, payable(msg.sender), askingPrice, false));
        activeItems[tokenAddress][tokenId] = true;

        assert(itemsForSale[newItemId].id == newItemId);
        emit itemAdded(newItemId, tokenId, tokenAddress, askingPrice);
        return newItemId;

    function buyItem(uint256 id) payable external ItemExists(id) IsForSale(id) HasTransferApproval(itemsForSale[id].tokenAddress,itemsForSale[id].tokenId){
        require(msg.value >= itemsForSale[id].askingPrice, "Not enough funds sent");
        require(msg.sender != itemsForSale[id].seller);

        itemsForSale[id].isSold = true;
        activeItems[itemsForSale[id].tokenAddress][itemsForSale[id].tokenId] = false;
        IERC721(itemsForSale[id].tokenAddress).safeTransferFrom(itemsForSale[id].seller, msg.sender, itemsForSale[id].tokenId);

        emit itemSold(id, msg.sender,itemsForSale[id].askingPrice);
    function setListingFee (uint256 ListingFee) external owner() { - error in here!!)
        listingFee = ListingFee;

Can someone help me to fix this error.

I think that the problem is related to owner() in function setListingFee (uint256 ListingFee) external owner() { that is defined previously as a variable: address payable owner;.

1 Like

Hey @Shahril

I guess you want to create onlyOwner modifier:

address private _owner;

constructor () internal {
        _owner = msg.sender;

modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");

And then you can use it:

 function setListingFee (uint256 ListingFee) external onlyOwner { 
        listingFee = ListingFee;
1 Like

done fix. thanks for the help

1 Like