Opensea Sync and Watch Contract Events: tableName issue

Hi guys !

i follow the Opensea tutorial, a bit beginner, so sorry by advance if the post are not clean… ( well after few issues there and there) still stuck on creating the tablename on
MarketItems, i made test also with MarketSold but doesn’t change anything,
the table name created are by default without any specific field from the abi.
Any idea where could be the problem ? :slight_smile:


can you paste contract address, abi and topic?
did you select the right chain?

you can see here how to paste formatted code on forum: READ BEFORE POSTING - How to post code in the forum

this is how you add an event to sync: https://docs.moralis.io/moralis-server/automatic-transaction-sync/smart-contract-events#sync-and-watch-contract-events

Hello cryptokid !

Thank you for your reply.
I deploy the contract on mumbai testnet and the chain selected is mumbai also on moralis server.

here the contract address :

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

import "@openzeppelin/contracts/utils/Counters.sol";

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

contract MarketPlace is ReentrancyGuard {

    using Counters for Counters.Counter;

    Counters.Counter private _itemIds;

    Counters.Counter private _itemSold;

    address public owner;

    constructor() {

        owner = msg.sender;

    }

    struct MarketItem {

        uint256 itemId;

        address nftContract;

        uint256 tokenId;

        address payable seller;

        address payable owner;

        uint256 price;

        bool sold;

    }

    mapping(uint256 => MarketItem) private idToMarketItem;

    event MarketItemCreated(

        uint256 indexed itemId,

        address indexed nftContract,

        uint256 indexed tokenId,

        address seller,

        address owner,

        uint256 price,

        bool sold

    );

    event MarketItemSold(uint256 indexed itemId, address owner);

    function createMarketItem(

        address nftContract,

        uint256 tokenId,

        uint256 price

    ) public payable nonReentrant {

        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

        );

        IERC721(nftContract).transferFrom(msg.sender, address(this), tokenId);

        emit MarketItemCreated(

            itemId,

            nftContract,

            tokenId,

            msg.sender,

            address(0),

            price,

            false

        );

    }

    function createMarketSale(address nftContract, uint256 itemId)

        public

        payable

        nonReentrant

    {

        uint256 price = idToMarketItem[itemId].price;

        uint256 tokenId = idToMarketItem[itemId].tokenId;

        bool sold = idToMarketItem[itemId].sold;

        require(

            msg.value == price,

            "Please submit the asking price in order to complete the purchase"

        );

        require(sold != true, "This sale has already finished");

        emit MarketItemSold(itemId, msg.sender);

        idToMarketItem[itemId].seller.transfer(msg.value);

        IERC721(nftContract).transferFrom(address(this), msg.sender, tokenId);

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

        _itemSold.increment();

        idToMarketItem[itemId].sold = true;

    }

    function fetchMarketItem() public view returns (MarketItem[] memory) {

        uint256 itemCount = _itemIds.current();

        uint256 unsoldItemcount = _itemIds.current() - _itemSold.current();

        uint256 currentIndex = 0;

        MarketItem[] memory items = new MarketItem[](unsoldItemcount);

        for (uint256 i = 0; i < itemCount; i++) {

            if (idToMarketItem[i + 1].owner == address(0)) {

                uint256 currentId = i + 1;

                MarketItem storage currentItem = idToMarketItem[currentId];

                items[currentIndex] = currentItem;

                currentIndex += 1;

            }

        }

        return items;

    }

}

And here the abi file import on the provider :

[

    {

      "inputs": [],

      "stateMutability": "nonpayable",

      "type": "constructor"

    },

    {

      "anonymous": false,

      "inputs": [

        {

          "indexed": true,

          "internalType": "uint256",

          "name": "itemId",

          "type": "uint256"

        },

        {

          "indexed": true,

          "internalType": "address",

          "name": "nftContract",

          "type": "address"

        },

        {

          "indexed": true,

          "internalType": "uint256",

          "name": "tokenId",

          "type": "uint256"

        },

        {

          "indexed": false,

          "internalType": "address",

          "name": "seller",

          "type": "address"

        },

        {

          "indexed": false,

          "internalType": "address",

          "name": "owner",

          "type": "address"

        },

        {

          "indexed": false,

          "internalType": "uint256",

          "name": "price",

          "type": "uint256"

        },

        {

          "indexed": false,

          "internalType": "bool",

          "name": "sold",

          "type": "bool"

        }

      ],

      "name": "MarketItemCreated",

      "type": "event"

    },

    {

      "anonymous": false,

      "inputs": [

        {

          "indexed": true,

          "internalType": "uint256",

          "name": "itemId",

          "type": "uint256"

        },

        {

          "indexed": false,

          "internalType": "address",

          "name": "owner",

          "type": "address"

        }

      ],

      "name": "MarketItemSold",

      "type": "event"

    },

    {

      "inputs": [],

      "name": "owner",

      "outputs": [

        {

          "internalType": "address",

          "name": "",

          "type": "address"

        }

      ],

      "stateMutability": "view",

      "type": "function",

      "constant": true

    },

    {

      "inputs": [

        {

          "internalType": "address",

          "name": "nftContract",

          "type": "address"

        },

        {

          "internalType": "uint256",

          "name": "tokenId",

          "type": "uint256"

        },

        {

          "internalType": "uint256",

          "name": "price",

          "type": "uint256"

        }

      ],

      "name": "createMarketItem",

      "outputs": [],

      "stateMutability": "payable",

      "type": "function",

      "payable": true

    },

    {

      "inputs": [

        {

          "internalType": "address",

          "name": "nftContract",

          "type": "address"

        },

        {

          "internalType": "uint256",

          "name": "itemId",

          "type": "uint256"

        }

      ],

      "name": "createMarketSale",

      "outputs": [],

      "stateMutability": "payable",

      "type": "function",

      "payable": true

    },

    {

      "inputs": [],

      "name": "fetchMarketItem",

      "outputs": [

        {

          "components": [

            {

              "internalType": "uint256",

              "name": "itemId",

              "type": "uint256"

            },

            {

              "internalType": "address",

              "name": "nftContract",

              "type": "address"

            },

            {

              "internalType": "uint256",

              "name": "tokenId",

              "type": "uint256"

            },

            {

              "internalType": "address payable",

              "name": "seller",

              "type": "address"

            },

            {

              "internalType": "address payable",

              "name": "owner",

              "type": "address"

            },

            {

              "internalType": "uint256",

              "name": "price",

              "type": "uint256"

            },

            {

              "internalType": "bool",

              "name": "sold",

              "type": "bool"

            }

          ],

          "internalType": "struct MarketPlace.MarketItem[]",

          "name": "",

          "type": "tuple[]"

        }

      ],

      "stateMutability": "view",

      "type": "function",

      "constant": true

    }

  ]

For the provider i put like this, coz got issue with this line :
const [contractABI, setContractABI] = useState (’{contract abi here}’) the ’ ’ was the issue.

import React, { useEffect, useState } from "react";

import { useMoralis } from "react-moralis";

import MoralisDappContext from "./context";

import MarketPlace from "./MarketPlace.json";

function MoralisDappProvider({ children }) {

  const { web3, Moralis, user } = useMoralis();

  const [walletAddress, setWalletAddress] = useState();

  const [chainId, setChainId] = useState();

  const [contractABI, setContractABI] = useState(MarketPlace);

  const [marketAddress, setMarketAddress] = useState("0xa4826089cdcb725dE72aeB666204640593849245");

  useEffect(() => {

    Moralis.onChainChanged(function (chain) {

      setChainId(chain);

    });

    Moralis.onAccountsChanged(function (address) {

      setWalletAddress(address[0]);

    });

    // eslint-disable-next-line react-hooks/exhaustive-deps

  }, []);

  // eslint-disable-next-line react-hooks/exhaustive-deps

  useEffect(() => setChainId(web3.givenProvider?.chainId));

  useEffect(

    () => setWalletAddress(web3.givenProvider?.selectedAddress || user?.get("ethAddress")),

    [web3, user]

  );

  return (

    <MoralisDappContext.Provider value={{ walletAddress, chainId, contractABI, setContractABI, marketAddress, setMarketAddress }}>

      {children}

    </MoralisDappContext.Provider>

  );

}

function useMoralisDapp() {

  const context = React.useContext(MoralisDappContext);

  if (context === undefined) {

    throw new Error("useMoralisDapp must be used within a MoralisDappProvider");

  }

  return context;

}

export { MoralisDappProvider, useMoralisDapp };

what do you mean by topic ?
Thanks to you ! And sorry took a while to update it.

Ah also, on the package.json, i add allow origine: * :

{
  "name": "ethereum-boilerplate",
  "version": "0.1.0",
  "private": true,
  "headers": {
    "Access-Control-Allow-Origin": "*"
  },

can you provide a link to a transaction on chain for that event that you want to sync?

there’s a transaction on mumbai polygonscan :

https://mumbai.polygonscan.com/tx/0x0e72d679198ce2da50e6ccf81fe550ca3dd89aa44eb4201286917af240b068c1

The event was for MarketItems, not for the sold.

I notice on the way an error on metamask 'transaction data . “Transaction decoding is not available for chainId 80001” i don’t know if that matter or not ?

https://mumbai.polygonscan.com/tx/0x0e72d679198ce2da50e6ccf81fe550ca3dd89aa44eb4201286917af240b068c1#eventlog

for that event topic0 is 0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63

Thank you cryptokid !
i’m checking what does that means, don’t understand yet.
so, maybe, i ll try to make again the whole operation with another nft. That will clean up the mess of bunch of fail transfer :slight_smile:

Hi Locha, I have the same issue. Did u find out the solution ?

What is the exact problem that you have?

Hi cryptokid, thanks for your reply.
I am following the opensea tutorial, and when i list (Sell button) an item on the marketplace the table CreateMarketItems made in the Sync contract event is empty.
I am using marketPlaceBoilerPlate.sol and ERC1155 tokens.

So you say that it is a problem on syncing events in db?

Can you share topic, abi, server url?

yes the data dont show up

topic :

MarketItemCreated(uint, address, uint256, address, address, uint256, bool)

here is the event ABI

{
  "anonymous": false,
  "inputs": [
    {
      "indexed": true,
      "internalType": "uint",
      "name": "itemId",
      "type": "uint"
    },
    {
      "indexed": true,
      "internalType": "address",
      "name": "nftContract",
      "type": "address"
    },
    {
      "indexed": true,
      "internalType": "uint256",
      "name": "tokenId",
      "type": "uint256"
    },
    {
      "indexed": false,
      "internalType": "address",
      "name": "seller",
      "type": "address"
    },
    {
      "indexed": false,
      "internalType": "address",
      "name": "owner",
      "type": "address"
    },
    {
      "indexed": false,
      "internalType": "uint256",
      "name": "price",
      "type": "uint256"
    },
    {
      "indexed": false,
      "internalType": "bool",
      "name": "sold",
      "type": "bool"
    }
  ],
  "name": "MarketItemCreated",
  "type": "event"
}

and the entire ABI :

[
	{
		"inputs": [],
		"stateMutability": "nonpayable",
		"type": "constructor"
	},
	{
		"anonymous": false,
		"inputs": [
			{
				"indexed": true,
				"internalType": "uint256",
				"name": "itemId",
				"type": "uint256"
			},
			{
				"indexed": true,
				"internalType": "address",
				"name": "nftContract",
				"type": "address"
			},
			{
				"indexed": true,
				"internalType": "uint256",
				"name": "tokenId",
				"type": "uint256"
			},
			{
				"indexed": false,
				"internalType": "address",
				"name": "seller",
				"type": "address"
			},
			{
				"indexed": false,
				"internalType": "address",
				"name": "owner",
				"type": "address"
			},
			{
				"indexed": false,
				"internalType": "uint256",
				"name": "price",
				"type": "uint256"
			},
			{
				"indexed": false,
				"internalType": "bool",
				"name": "sold",
				"type": "bool"
			}
		],
		"name": "MarketItemCreated",
		"type": "event"
	},
	{
		"anonymous": false,
		"inputs": [
			{
				"indexed": true,
				"internalType": "uint256",
				"name": "itemId",
				"type": "uint256"
			},
			{
				"indexed": false,
				"internalType": "address",
				"name": "owner",
				"type": "address"
			}
		],
		"name": "MarketItemSold",
		"type": "event"
	},
	{
		"inputs": [
			{
				"internalType": "address",
				"name": "nftContract",
				"type": "address"
			},
			{
				"internalType": "uint256",
				"name": "tokenId",
				"type": "uint256"
			},
			{
				"internalType": "uint256",
				"name": "price",
				"type": "uint256"
			}
		],
		"name": "createMarketItem",
		"outputs": [],
		"stateMutability": "payable",
		"type": "function"
	},
	{
		"inputs": [
			{
				"internalType": "address",
				"name": "nftContract",
				"type": "address"
			},
			{
				"internalType": "uint256",
				"name": "itemId",
				"type": "uint256"
			}
		],
		"name": "createMarketSale",
		"outputs": [],
		"stateMutability": "payable",
		"type": "function"
	},
	{
		"inputs": [],
		"name": "fetchMarketItems",
		"outputs": [
			{
				"components": [
					{
						"internalType": "uint256",
						"name": "itemId",
						"type": "uint256"
					},
					{
						"internalType": "address",
						"name": "nftContract",
						"type": "address"
					},
					{
						"internalType": "uint256",
						"name": "tokenId",
						"type": "uint256"
					},
					{
						"internalType": "address payable",
						"name": "seller",
						"type": "address"
					},
					{
						"internalType": "address payable",
						"name": "owner",
						"type": "address"
					},
					{
						"internalType": "uint256",
						"name": "price",
						"type": "uint256"
					},
					{
						"internalType": "bool",
						"name": "sold",
						"type": "bool"
					}
				],
				"internalType": "struct marketPlaceBoilerPlate.MarketItem[]",
				"name": "",
				"type": "tuple[]"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},
	{
		"inputs": [],
		"name": "owner",
		"outputs": [
			{
				"internalType": "address",
				"name": "",
				"type": "address"
			}
		],
		"stateMutability": "view",
		"type": "function"
	}
]

server_url : https://ycdxaxcwwaup.usemoralis.com:2053/server

I think that here you have to use uint256 instead of uint

i tried but it doesnt work

maybe it is because the marketPlaceBoilerPlate.sol allows ERC721 and my tokens are ERC1155 ?

it shouldn’t matter the type of the contract, it may be easier to use the hash version of the topic, you will find it in a block explorer when you look at that event that you want to sync

is that hash version here ?


by using it you mean replace it in the topic input ?

yes, you can use that has from topic 0 instead of the topic that you use now, that one that starts with 0x4d