Marketplace Contract - Modification

@Shahril

Greetings, with hope of course you are well.

Was wondering if you might assist with the same question you posed in your most recent thread with @cryptokid - regarding setting listing fees in the Marketplace contract, I too have been trying to add this function without success.

Would you mind to be so kind as to share the modified solidity code you used in the end that compiled properly. As each implimentation ive tried generates parse errors, that I cannot resolve, without a little help myself. Would you kindly share - as this would also be a helpful further advancement for others as well and to the improvement of the repo.

Please let me know whenever you have a moment. Regards. and with thanks in advance. Deus

Hey @Shahril

Thank you for sharing the code!

Please take a look at READ BEFORE POSTING - How to post code in the forum

:raised_hands:

1 Like

For set listing fee, it works perfectly well. but i’m still missing the part to implied listing fee when to add NFT to marketplace. still working on it

pragma solidity ^0.8.0;

contract SCOPXMarketContract is Ownable{
    struct AuctionItem {
        uint256 id;
        address tokenAddress;
        uint256 tokenId;
        address payable seller;
        uint256 askingPrice;
        bool isSold;
    }
    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 setListingFee (uint256 ListingFee) external onlyOwner() {
        listingFee = 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;
        payable(owner).transfer(listingPrice);

        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);
        itemsForSale[id].seller.transfer(msg.value);

        emit itemSold(id, msg.sender,itemsForSale[id].askingPrice);
    }
 
}

just from a quick glance, shouldn’t

payable(owner).transfer(listingPrice);

be

payable(owner).transfer(listingFee);

?

Seems there are errors in this as well. Def appreciated sharing in any event.

With hope then that we might have some further assist in a working example in the not to distant future.

Thanks again Shahril.

u can have a look at https://github.com/dabit3/full-stack-ethereum-marketplace-workshop

1 Like