Hi, I’m following patrick’s course in this link
https://www.youtube.com/watch?v=gyMwXuJrbJQ&t=88772s
This is my addEvents.js
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
const contractAddress = contractAddresses[chainId]["NftMarketplace"]
const serverUrl = process.env.NEXT_PUBLIC_SERVER_URL
const appId = process.env.NEXT_PUBLIC_APP_ID
const masterKey = process.env.masterKey
async function main() {
await Moralis.start({ serverUrl, appId, masterKey })
console.log("working with contract address")
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: "nftAddress",
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,
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: "nftAddress",
type: "address",
},
{
indexed: true,
internalType: "uint256",
name: "tokenId",
type: "uint256",
},
{
indexed: false,
internalType: "uint256",
name: "price",
type: "uint256",
},
],
name: "ItemBought",
type: "event",
},
tableName: "ItemBought",
address: contractAddress,
}
let itemCancelledOptions = {
chainId: moralisChainId,
sync_historical: true,
topic: "ItemCancelled(address,address,uint256)",
abi: {
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "seller",
type: "address",
},
{
indexed: true,
internalType: "address",
name: "nftAddress",
type: "address",
},
{
indexed: true,
internalType: "uint256",
name: "tokenId",
type: "uint256",
},
],
name: "ItemCancelled",
type: "event",
},
tableName: "ItemCancelled",
address: contractAddress,
}
const listedResponse = await Moralis.Cloud.run("watchContractEvent", itemListedOptions, {
useMasterKey: true,
})
console.log(listedResponse)
const boughtResponse = await Moralis.Cloud.run("watchContractEvent", itemBoughtOptions, {
useMasterKey: true,
})
console.log(boughtResponse)
const cancelledResponse = await Moralis.Cloud.run("watchContractEvent", itemCancelledOptions, {
useMasterKey: true,
})
console.log(cancelledResponse)
if (listedResponse.success && boughtResponse.success && cancelledResponse.success) {
console.log("success")
} else {
console.log("wrong")
}
}
main()
.then(() => process.exit(0))
.catch((error) => console.error(error))
This is my mint-and-list.js
const { ethers, network } = require("hardhat")
// const { moveBlocks } = require("../utils/move-blocks")
const PRICE = ethers.utils.parseEther("0.1")
async function mintAndList() {
const nftMarketplace = await ethers.getContract("NftMarketplace")
const randomNumber = Math.floor(Math.random() * 2)
let basicNft
//if (randomNumber == 1) {
// basicNft = await ethers.getContract("BasicNftTwo")
//} else {
basicNft = await ethers.getContract("BasicNft")
//}
console.log("Minting NFT...")
const mintTx = await basicNft.mintNft()
const mintTxReceipt = await mintTx.wait(1)
const tokenId = mintTxReceipt.events[0].args.tokenId
console.log("Approving NFT...")
const approvalTx = await basicNft.approve(
nftMarketplace.address,
tokenId
)
await approvalTx.wait(1)
console.log("Listing NFT...")
const tx = await nftMarketplace.listItem(
basicNft.address,
tokenId,
PRICE
)
await tx.wait(1)
console.log("NFT Listed!")
if (network.config.chainId == 31337) {
// Moralis has a hard time if you move more than 1 at once!
// await moveBlocks(1, (sleepAmount = 1000))
}
}
mintAndList()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
My mint-and-list and addEvents are working and 3 events are registered in the event sync status but when I run mint-and-list ItemListed is not updating
this is my app id and server url
https://ifpiwjursnbp.usemoralis.com:2053/server
xKQoVvCYv5u8oBm5jWNqPltGPNlrBVuerdtIRS7x
I appreciate the help! Thanks!