ERC1155 based marketplace - The transaction has been reverted


I'm a newbie to Solidity. I want to build a marketplace based on ERC1155. I have successfully deployed NFTContract.sol and NFTMarket.sol using Remix.

I minted a token with a supply of 100. Then I created a market item. And with a different address, I successfully purchased an item. However, when I try to buy another one, my transaction fails. I don't understand, there should still be 99 items available for sale.

I have the following error message:

transact to NFTMarket.createMarketSale errored: VM error: revert.
The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send should be less than your current balance.

I submitted the exact value to be paid at the time of the transaction.

Thanks for your help.

NFT Contract

contract NFTContract is ERC1155, Ownable {

    address contractAddress;

    //Increment token IDs
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    //Map a token ID to a URI
    mapping (uint256 => string) private _uris;
    constructor(address marketplaceAddress) ERC1155("") {
        contractAddress = marketplaceAddress;

    function mint(uint256 amount, string memory _uri) public returns (uint){
        uint256 newItemId = _tokenIds.current(); 

        _mint(msg.sender, newItemId, amount, "");
        _uris[newItemId] = _uri;
        setApprovalForAll(contractAddress, true);
        return newItemId;

    function uri(uint256 tokenId) override public view returns (string memory) {

Marketplace Contract

contract NFTMarket is ERC1155, ERC1155Holder, ReentrancyGuard {
    using Counters for Counters.Counter;
    Counters.Counter private _itemIds;
    Counters.Counter private _itemsSold;

    address payable owner_; 
    uint256 listingPrice = 0.002 ether;

    constructor() ERC1155("") {
        owner_ = payable(msg.sender);

    struct MarketItem {
        uint itemId; 
        address nftContract;
        uint256 tokenId; 
        address payable seller; 
        address payable owner_; 
        uint256 price; 

    mapping(uint256 => MarketItem) private idToMarketItem;
    event MarketItemCreated (
        uint indexed itemId,
        address indexed nftContract,
        uint256 indexed tokenId,
        address seller,
        address owner_,
        uint256 price

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

    /* Returns the listing price of the contract */
    function getListingPrice() public view returns (uint256) {
        return listingPrice;
    /* Places an item for sale on the marketplace */
    function createMarketItem (
        address nftContract,
        uint256 tokenId, 
        uint256 price,
        address payable[] memory contributorAddresses, 
        uint256[] memory contributorShares
    ) public payable nonReentrant {
        require(price > 0, "Price must be higher than 0");
        require(msg.value == listingPrice, "Price must be equal to listing price");

        uint256 itemId = _itemIds.current(); 

        idToMarketItem[itemId] = MarketItem(

        IERC1155(nftContract).safeTransferFrom(msg.sender, address(this), tokenId, 100, "");

        emit MarketItemCreated (

    /* Creates the sale of a marketplace item */
    /* Transfers ownership of the item, as well as funds between parties */
    function createMarketSale(
        address nftContract,
        uint256 itemId
    ) public payable nonReentrant {

        uint price = idToMarketItem[itemId].price; 
        uint tokenId = idToMarketItem[itemId].tokenId; 

        require(msg.value == price, "Please submit the asking price in order to complete the purchase");


        IERC1155(nftContract).safeTransferFrom(address(this), msg.sender, tokenId, 1, "");

        idToMarketItem[itemId].owner_ = payable(msg.sender);

:computer: Environment


Do you know what statement is reverting?

I can't easily find the error in your code.