Moralis marketplace smart contract edition

Hello everyone
i tried to edit the moralis marketplace smart-contract
and i made this :

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

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Counters.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/utils/ERC1155Holder.sol";

contract NFTContract is ERC1155,Ownable,ReentrancyGuard,ERC1155Holder{
    using Counters for Counters.Counter;
    Counters.Counter private _itemIds;
    Counters.Counter private _itemsSold;
   
    constructor() ERC1155("https://xxxxxxxxxx.xxxxxx/{id}.json") {
        //msg.sender is creator of contract in constructor
    }

    //Required by super
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155, ERC1155Receiver) returns (bool) {
        return super.supportsInterface(interfaceId);
    }

    struct MarketItem {
        uint itemId;
        address nftContract;
        uint256 tokenId;
        address payable seller;
        address payable owner;
        uint256 price;
        bool sold;
    }

    mapping(uint256 => MarketItem) private idToMarketItem;

    event MarketItemCreated (
        uint indexed itemId,
        address indexed nftContract,
        uint256 indexed tokenId,
        address seller,
        address owner,
        uint256 price,
        bool sold
    );

    event MarketItemSold (
        uint indexed itemId,
        address owner
    );

    function createMarketItem (
        address nftContract,
        uint256 tokenId,
        uint256 price
    ) public payable nonReentrant { //nonReentrant for security reasons
        require(price > 0, "Price must be greater than 0");

        _itemIds.increment();
        uint256 itemId = _itemIds.current();
        
        idToMarketItem[itemId] = MarketItem(
            itemId,
            nftContract,
            tokenId,
            payable(msg.sender),
            payable(address(0)),
            price,
            false
        );
        
        //from,to,id,amount,data
        _safeTransferFrom(msg.sender, address(this), tokenId, 1, "");
        
        emit MarketItemCreated (
            itemId,
            nftContract,
            tokenId,
            msg.sender,
            address(0),
            price,
            false
        );
    }

    function createMarketItemBatch(
        address nftContract,
        uint256[] memory tokenIds,
        uint256[] memory prices,
        uint256[] memory amounts
    ) public payable nonReentrant {
        require(tokenIds.length == prices.length, "prices & tokens length dont match");

        //Iterating over all tokenIds
        for(uint i=0; i < tokenIds.length; i++){
            //update contract
            _itemIds.increment();
            uint256 itemId = _itemIds.current(); 
            idToMarketItem[itemId] = MarketItem(
                itemId,
                nftContract,
                tokenIds[i],
                payable(msg.sender),
                payable(address(0)),
                prices[i],
                false
            );
            //Emit the event for each item creation
            emit MarketItemCreated (
                itemId,
                nftContract,
                tokenIds[i],
                msg.sender,
                address(0),
                prices[i],
                false
            );
        }
        //Transfer batch
        _safeBatchTransferFrom(
            msg.sender,
            address(this),
            tokenIds,
            amounts,
            ""
        );
    }

    function createMarketSale(
        uint256 itemId
    ) public payable nonReentrant {
        //get item info
        uint price = idToMarketItem[itemId].price;
        uint tokenId = idToMarketItem[itemId].tokenId;
        bool sold = idToMarketItem[itemId].sold;

        //Add validations
        require(msg.value == price, "Please submit the asking price to complete");
        require(sold != true, "Auction already finished");

        //register event
        emit MarketItemSold (itemId, msg.sender);

        //transfer
        idToMarketItem[itemId].seller.transfer(msg.value);
        _safeTransferFrom(address(this), msg.sender, tokenId, 1, "");
        idToMarketItem[itemId].owner = payable(msg.sender);
        _itemsSold.increment();
        idToMarketItem[itemId].sold = true;
    }

    function fetchMarketItems() public view returns (MarketItem[] memory) {
        uint itemCount = _itemIds.current();
        uint unsoldItemCount = _itemIds.current() - _itemsSold.current();
        uint currentIndex = 0;

        MarketItem[] memory items = new MarketItem[](unsoldItemCount);
        for(uint i=0; i < itemCount; i++){
            if(idToMarketItem[i + 1].owner == address(0)){
                uint currentId = i + 1;
                MarketItem storage currentItem = idToMarketItem[currentId];
                items[currentIndex] = currentItem;
                currentIndex += 1;
            }
        }
        return items;
    }

    //Mint several tokens in one transaction to save fee
    function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts) public onlyOwner{
        _mintBatch(to,ids,amounts, "");
    }

    //burn can only be done by owner of token
    function burn(address from, uint256 id, uint256 amount) public onlyOwner {
        require(msg.sender == from);
        _burn(from,id,amount);
    }
}

now i want to add two thing to this code

first : i need to make something that with every NFT Sell , 2.5% of the fee , transfers to owner’s wallet
second : i need a splitter which transfers x% amount of every NFT Sell and every commision received to 2 wallet ids

can anyone help ?

i have this sample code to add to my smart contract
but i have problem using it
can anyone help me ?

        //register event
        emit MarketItemSold (itemId, msg.sender);
        
        uint256 ownerTax = price / 100;
        uint256 otherTax = price * tax / 100; // This is the tax variable to be declared
        uint256 sellerPart = price - ownerTax - otherTax;
        
        // Send money to owner and wallets
        payable(owner()).transfer(ownerTax);
        payable(wallet1).transfer(otherTax / 2);
        payable(wallet2).transfer(otherTax / 2);

        //transfer
        idToMarketItem[itemId].seller.transfer(sellerPart);
        _safeTransferFrom(address(this), msg.sender, tokenId, 1, "");
        idToMarketItem[itemId].owner = payable(msg.sender);
        _itemsSold.increment();
        idToMarketItem[itemId].sold = true;
    }

Hello if you haven’t already, you can post in the #smart-contract-help channel on the Moralis Discord, you can get help with this there as well.

You would just need to transfer a portion of the msgValue passed to the NFT sell function to predefined wallet addresses, does what you’ve tried not work? Start simpler e.g. just do a payment to one wallet first.

is it possible for you to fix my code ?

I am not that familiar with what you’re asking for in Solidity.

but i have problem using it

Can you elaborate? You can also start simpler or wait for help from others.