Hi!
I’m following/adapting Patrick Collin’s tutorial to create a NFT Marketplace using Moralis for the server.
I’ve successfully connected my dApp to the server, Server Status: Connected
is displayed in the Devchain Proxy Server, and I can see the eth_blockNumber
calls progressing.
Yet, when I run node addEventsMoralis.js
, no event listeners are set up in the database, and no specific reason is given
Here is my addEventsMoralis.js
:
const Moralis = require("moralis-v1/node")
require("dotenv").config()
const contractAddresses = require("./constants/networkMappings.json")
let chainId = process.env.chainId || "31337"
//moralis understands that localchainid is 1337, so there's a need to convert it
let moralisChainId = chainId == "31337?" ? "1337" : chainId
const contractAddressesArray = contractAddresses[chainId]["MarsKetplace"]
const contractAddress = contractAddressesArray[contractAddressesArray.length - 1]
const serverUrl = process.env.NEXT_PUBLIC_SERVERURL
const appId = process.env.NEXT_PUBLIC_APPID
const masterKey = process.env.MORALIS_MASTERKEY
async function main() {
await Moralis.start({ serverUrl, appId, masterKey })
console.log(`Working with ${contractAddress}`)
let NFTListedOptions = {
chainId: moralisChainId,
address: contractAddress,
sync_historical: true,
topic: "NFTListed(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: "NFTListed",
type: "event",
},
tableName: "NFTListed",
}
let NFTBoughtOptions = {
chainId: moralisChainId,
address: contractAddress,
sync_historical: true,
topic: "NFTBought(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: "NFTBought",
type: "event",
},
tableName: "NFTBought",
}
let NFTDeletedOptions = {
chainId: moralisChainId,
address: contractAddress,
sync_historical: true,
topic: "NFTDeleted(address,uint256)",
abi: {
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "nftAddress",
type: "address",
},
{
indexed: true,
internalType: "uint256",
name: "tokenId",
type: "uint256",
},
],
name: "NFTDeleted",
type: "event",
},
tableName: "NFTDeleted",
}
const listedResponse = await Moralis.Cloud.run("watchContractEvent", NFTListedOptions, {
useMasterKey: true,
})
console.log(listedResponse)
const boughtResponse = await Moralis.Cloud.run("watchContractEvent", NFTBoughtOptions, {
useMasterKey: true,
})
console.log(boughtResponse)
const deletedResponse = await Moralis.Cloud.run("watchContractEvent", NFTDeletedOptions, {
useMasterKey: true,
})
console.log(deletedResponse)
console.log("Working on it...")
if (listedResponse.success && boughtResponse.success && deletedResponse.success) {
console.log("Database successfully updated with watching events!")
} else {
console.log("Something went wrong... and I won't show you what.")
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
and here is the result of running node addEventsMoralis.js
:
node addEventsMoralis.js
Working with 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
{ success: false }
{ success: false }
{ success: false }
Working on it...
Something went wrong... and I won't show you what.
The logs on the DataBase :
Ran cloud function watchContractEvent for user undefined with:
Input: {"chainId":"31337","address":"0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512","sync_historical":true,"topic":"NFTDeleted(address,uint256)","abi":{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nftAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"NFTDeleted","type":"event"},"tableName":"NFTDeleted"}
Result: {"success":false}
Things that I’ve tried :
- verified that the abi for each event were correct, they were.
- verified that the master key in my
.env
was correct, it was. -
Reset Local Devchain
hit in Networks on the admin dashboad, didn’t change. - Tried with another instance of the contract, didn’t change.
The entire repo is here if you need : https://github.com/AnneCh/FrontEndMarsKetplace
Thanks in advance!