Hey @SachaH
Can you take a screenshot of the table with synced info? And what information do you want to receive?
Please provide an address of smartcontract and chain.
Hey @Yomoo
Here are all the informations asked:
- Contract events : https://testnet.bscscan.com/address/0x88683dBDb8E1D25D5dB85D9187437e319B51cA02#events
- The information I which to receive is the input emitted within the event auditorRegistered
-Table with data synced (due to media upload limit for new users, i canāt upload 2 images so i just made a screenshot of the end of the tableās fields as the first one are the regular createdAt/updatedAtā¦ fields)
- See above for the plugin configuration
Hey @SachaH
Try this abi:
{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_audit","type":"address"}],"name":"auditRegistered","type":"event"}
Hey,
I just replaced the abi with the one you gave for my event, Iām still getting the event and its informations, but not the data contained in it within the table
Hey @SachaH
I gave you incorrect abi
And in this case you have to do some code in cloud functions. Iāll provide you an example in 10 minutes
Hey no worries I know how to get back the data from the event I just thought that giving the abi would allow feeding the table with the data contained in the event
I just made an after save trigger on the table given to the plugin then i apply the following logic
const { object: auditorRegisteredEvent } = request
const events = await factoryContract.getPastEvents('auditorRegistered', {
fromBlock: auditorRegisteredEvent.attributes.block_number,
toBlock: auditorRegisteredEvent.attributes.block_number + 1,
});
const foundEvent = events.find(
(event) => event.logIndex === auditorRegisteredEvent.attributes.log_index,
);
const auditorAddress = foundEvent.returnValues._auditor.toLowerCase();
Awesome work!
But for your casse the best solution is to use beforeconsume
trigger.
Is it your contract? Can you please create one more event?
Ah, I can do it by myself
UPDATE: No, I canāt
Hey I didnāt get what you wanted me to do, yes it is my contract, if you want to generate an event just call this method https://testnet.bscscan.com/address/0x5e192b22b5f30efd8a1897699813b7cd022ad0c0#writeContract
Hey @SachaH
There was a problem with name _auditor
. Column names canāt began with symbol _
. So above you can see the solution:
Moralis.Cloud.beforeConsume("TableEventName", (event) => {
const logger = Moralis.Cloud.getLogger();
event.auditor = JSON.stringify(event._auditor);
return event;
});
Let nme know hot it works for you
ABI:
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "_auditor",
"type": "address"
}
],
"name": "auditorRegistered",
"type": "event"
}
Topic name 0x01d541ecc7e468bb4cc2794ffb6b02738b04182d627c19a490155feeaf025e03
Hey @Yomoo ,
The topic have to be hashed ? If so how did you got the topic ? from bscscan ?
Strange enough It doesnāt seem that itās passing in beforeConsume
Moralis.Cloud.beforeConsume('EventSyncAuditorRegistered', async (event) => {
const query = new Moralis.Query('Contract');
query.equalTo('chainId', '0x61');
query.equalTo('name', 'Factory');
const [factoryContractInfos] = await query.find();
const newEvent = {
...event,
auditor: JSON.stringify(event._auditor),
};
await factoryContractInfos.save(
{
test: event,
},
{ useMasterKey: true },
); // This is because my logs page is not working currently (reported in https://forum.moralis.io/t/logs-are-not-working/1315)
return newEvent;
});
You can use not hashed name auditorRegistered(address)
as well. Yes, you can find hashed topic name on bscscan.
Does this code work?
No unfortunately it doesnāt seem the beforeConsume is triggered within my cloud function at all
Can you please try only my code and check the name of the function. You should paste the name from the database object
@Yomoo
Ok Now itās passing in beforeConsume ! But the new field is not created here is whatās returned at the end of beforeconsume hook
{
"transaction_hash": "0x6f27a61df6bb1760fd6f2e9d05fc8b99f8fd21b99f7cd6078b31230de271ef9d",
"log_index": 1,
"_auditor": "0xf07c1080e25cd96cd37951d7893e372128551cfe",
"address": "0x88683dbdb8e1d25d5db85d9187437e319b51ca02",
"block_hash": "0x17892c1e61a24074363c60e723c754f330a24fd3acf23edb4b34b64367451de7",
"block_number": 10958454,
"transaction_index": 4,
"block_timestamp": {
"__type": "Date",
"iso": "2021-07-27T14:35:56.548Z"
},
"auditor": "\"0xf07c1080e25cd96cd37951d7893e372128551cfe\""
}
CODE
Moralis.Cloud.beforeConsume('EventSyncAuditorRegistered', async (event) => {
event.auditor = JSON.stringify(event._auditor);
return event;
});
Why using JSON.stringify since _auditor is already a string ?