Lesson 15: Moralis database is not updating with the event details #1291
-
I can see there are already couple of question related to this and I also confirm this problem. I have reset the local chain as suggested by @PatrickAlphaC . But still running My const Moralis = require("moralis/node");
require("dotenv").config();
const contractAddresses = require("./constants/networkMapping.json");
let chainId = process.env.chainId || "31337";
let moralisChainId = chainId == "31337" ? "1337" : chainId; // Moralis consider localchain at 1337.
/* Moralis init code */
const serverUrl = process.env.NEXT_PUBLIC_MORALIS_SERVER_URL;
const appId = process.env.NEXT_PUBLIC_MORALIS_APP_ID;
const masterKey = process.env.moralisMasterKey;
async function main() {
await Moralis.start({ serverUrl, appId, masterKey });
const contractAddress = contractAddresses[chainId]["NftMarketplace"][0];
console.log(`Working with contract address: ${contractAddress}`);
//events logging
let itemListedOptions = {
chainId: moralisChainId,
address: contractAddress,
sync_historical: true,
topic: "ItemListed(address,address,uint256,uint256)",
abi: {
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "seller",
type: "address",
},
{
indexed: true,
internalType: "address",
name: "marketplaceAddress",
type: "address",
},
{
indexed: true,
internalType: "uint256",
name: "tokenId",
type: "uint256",
},
{
indexed: false,
internalType: "uint256",
name: "price",
type: "uint256",
},
],
name: "ItemListed",
type: "event",
},
tableName: "ItemListed",
};
let itemBoughtOptions = {
chainId: moralisChainId,
address: contractAddress,
sync_historical: true,
topic: "ItemBought(address,address,uint256,uint256)",
abi: {
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "buyer",
type: "address",
},
{
indexed: true,
internalType: "address",
name: "marketplaceAddress",
type: "address",
},
{
indexed: true,
internalType: "uint256",
name: "tokenId",
type: "uint256",
},
{
indexed: false,
internalType: "uint256",
name: "price",
type: "uint256",
},
],
name: "ItemBought",
type: "event",
},
tableName: "ItemBought",
};
let listingCancelledOptions = {
chainId: moralisChainId,
address: contractAddress,
sync_historical: true,
topic: "ListingCancelled(address,uint256,address)",
abi: {
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "marketplaceAddress",
type: "address",
},
{
indexed: true,
internalType: "uint256",
name: "tokenId",
type: "uint256",
},
{
indexed: false,
internalType: "address",
name: "seller",
type: "address",
},
],
name: "ListingCancelled",
type: "event",
},
tableName: "ListingCacelled",
};
let itemUpdatedOptions = {
chainId: moralisChainId,
address: contractAddress,
sync_historical: true,
topic: "ItemUpdated(address,address,uint256,uint256)",
abi: {
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "seller",
type: "address",
},
{
indexed: true,
internalType: "address",
name: "marketplaceAddress",
type: "address",
},
{
indexed: true,
internalType: "uint256",
name: "tokenId",
type: "uint256",
},
{
indexed: false,
internalType: "uint256",
name: "newPrice",
type: "uint256",
},
],
name: "ItemUpdated",
type: "event",
},
tableName: "ItemUpdated",
};
const listedRespo = await Moralis.Cloud.run("watchContractEvent", itemListedOptions, {
useMasterKey: true,
});
const boughtRespo = await Moralis.Cloud.run("watchContractEvent", itemBoughtOptions, {
useMasterKey: true,
});
const cancelledRespo = await Moralis.Cloud.run(
"watchContractEvent",
listingCancelledOptions,
{ useMasterKey: true }
);
const updateRespo = await Moralis.Cloud.run("watchContractEvent", itemUpdatedOptions, {
useMasterKey: true,
});
if (
listedRespo.success &&
boughtRespo.success &&
cancelledRespo.success &&
updateRespo.success
) {
console.log(
"Updated! You should now be able to see these tables in your database. \n Note: You won't be able to see the events on the `sync` tab of the UI though."
);
} else {
console.log(
"Something went wrong uploading events... Try manually importing for a better error code. "
);
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
}); and the events // Events
event ItemListed(
address indexed seller,
address indexed marketplaceAddress,
uint256 indexed tokenId,
uint256 price
);
event ItemBought(
address indexed buyer,
address indexed marketplaceAddress,
uint256 indexed tokenId,
uint256 price
);
event ListingCancelled(
address indexed marketplaceAddress,
uint256 indexed tokenId,
address seller
);
event ItemUpdated(
address indexed seller,
address indexed marketplaceAddress,
uint256 indexed tokenId,
uint256 newPrice
); |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 12 replies
-
Can you make a repo and link it here? I will look into it. |
Beta Was this translation helpful? Give feedback.
-
Ok, Issue is fixed. The issue was from Moralis side. They had some problem with hardhat. They have fixed it after my conversation with them. So to use it, you guys have to delete old server and create a new one. |
Beta Was this translation helpful? Give feedback.
-
I still got the same error, no updates on the events listed. After creating a fresh server in moralis. I am not sure that it was needed to be done in order for it to work. But it does make sense, since we are updating or listing our nft in the database. |
Beta Was this translation helpful? Give feedback.
-
I was facing the same issue , now solved @yersel500 I was making the mistake in hardhat.config.js file
I was forking the hardhat local chain , now i commented 😇 |
Beta Was this translation helpful? Give feedback.
Ok, Issue is fixed. The issue was from Moralis side. They had some problem with hardhat. They have fixed it after my conversation with them. So to use it, you guys have to delete old server and create a new one.
Check the thread on Moralis forum
https://forum.moralis.io/t/event-is-not-logging-in-moralis-database-on-devchain/17848/14
@krakxn @CodeLikeLisa @opeseyi @Rishi860 @PatrickAlphaC