Thank you @Yomoo for your reply.
I have an event sync already setup on the factory contract so that when a new contract is instantiated, the event is emitted. This is working as expected.
I then setup a trigger as per your suggestion on the event table from the above. Below is the code I did for this in âCloud Functionsâ:
Moralis.Cloud.afterSave("GovernorCreatedEvents", (request) => {
const logger = Moralis.Cloud.getLogger();
logger.info("----> GovernorCreatedEvents.afterSave - START");
const govAddress = request.object.get("govAddress");
logger.info("----> govAddress: " + govAddress);
let options = {
"chainId": "0xA869",
"address": govAddress,
"topic": "ProposalCreated(address, uint256, address, address[], uint[], string[], bytes[], uint256, uint256, string)",
"abi": {
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "govAddress",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "proposalId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
"name": "proposer",
"type": "address"
},
{
"indexed": false,
"internalType": "address[]",
"name": "targets",
"type": "address[]"
},
{
"indexed": false,
"internalType": "uint256[]",
"name": "values",
"type": "uint256[]"
},
{
"indexed": false,
"internalType": "string[]",
"name": "signatures",
"type": "string[]"
},
{
"indexed": false,
"internalType": "bytes[]",
"name": "calldatas",
"type": "bytes[]"
},
{
"indexed": false,
"internalType": "uint256",
"name": "startTime",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "endTime",
"type": "uint256"
},
{
"indexed": false,
"internalType": "string",
"name": "description",
"type": "string"
}
],
"name": "ProposalCreated",
"type": "event"
},
"tableName": "ProposalCreated",
"sync_historical": true
};
Moralis.Cloud.run("watchContractEvent", options, {useMasterKey:true});
logger.info("----> GovernorCreatedEvents.afterSave - FINISH");
});
I ran a test and I can see the following entries in the log:
It looks like the trigger code ran twice. I suspect this is because of the confirmed (true/false) so maybe I need to check for that flag and only run the code if confirmed = true. Is that right?
When I go to the Dashboard, I do see the ProposalCreated table. However, I do not see any of the columns for the event fields. Please see the screen shot below:
So I have two questions:
- How can I see the event fields such as proposalId and proposer, etc.
- If another contract instance is created, the trigger will call âwatchContractEventâ with the new contractâs address, will that interfere with the other contract? i.e. does âwatchContractEventâ work if it is called with the same tableName but different address values?
Thanks!