Realtime Sync on Rinkeby - from address

I managed to sync these events


Only thing different from the youtube vid was the “Topic” field… i used the event name not the function that the event was emitted from…

and to catch the event in my cloud fxs via

Moralis.Cloud.afterSave('Shipped', (request) => {
  console.log('afterSaved Shipped console', JSON.stringify(request))
  log('afterSaved Shipped', JSON.stringify(request))
  const query = new Moralis.Query('Shipped')
  query.startsWith('transaction_hash', request.object.get('transaction_hash').substr(0, 6))
  query.find().then(function (ShippedFlipTx) {
    log('flipped Tx', JSON.stringify(ShippedFlipTx))
    .catch(function (error) {
      console.error('FlipShipped Sync error ' + error.code + ' : ' + error.message)

but i don’t quite understand why the sync system is saving the to: field of the tx/event (which is always the contract) instead of from?

Sorry I don’t understand what you’re asking. Please provide more details about what you’re trying to accomplish and how things are different than you expect- include screen shots and code where applicable.

The Shipped(uint256) event does not have from or to properties… so this is rather confusing.

Thanks @mayjer for your reply!

So, I guess we could add the from address to the emit, but the tx has from and to
but the address on the record that is added to Moralis data table is the contract address:

This is a waste of storage space and uninformative (as that is the address that we are listening to)

I did manage to get the ‘from’ address via:

Moralis.Cloud.afterSave('Shipped', async (request) => {
  const config = await Moralis.Config.get({ useMasterKey: true })
  const CHAIN_ID = config.get('CHAIN_ID')
  const web3 = Moralis.web3ByChain(CHAIN_ID)
  // log(`afterSaved Shipped: ${JSON.stringify(request, null, 2)}`)
  const query = new Moralis.Query('Shipped')
  const txHash = request.object.get('transaction_hash')
  query.startsWith('transaction_hash', txHash.substr(0, 8))
  query.find().then(async ([ShippedFlipRecord]) => {
    log(`${ShippedFlipRecord.get('transaction_hash').substr(0, 8)} - Shipped Record : ${JSON.stringify(ShippedFlipRecord, null, 2)}`)
    const txObj = await web3.eth.getTransaction(txHash)
    log(`${txObj.from} - flipped Tx :${JSON.stringify(txObj, null, 2)}`)

but what i am asking is: can Moralis take care of that internally and already add this ‘from’ address to the data record instead of the contract address.

What he’s asking for is to add the transaction sender/initiator to the available fields.
It’s not really about the event itself.

This is correct implementation where you ask web3 for tx details.
Events only have events info.
It’s important to keep these things modular.

ok (we added the from field to our emit),
but why bloat the db with the contract address string in every record?

can we avoid that in a beforeSave handler somehow?

Experiment with beforeConsume. You can decide exactly what you want to put into DB.

can do… will do…

and what is your opinion about the bloat concerns?

is the event parameter mutable?

seems to be:

Moralis.Cloud.beforeConsume('Shipped', (event) => {
  // TODO remove unwanted columns from table definition automatically
  // for now it is done manually in dashboard browser
  if (!event.confirmed) return false
  delete event.address
  delete event.confirmed
  delete event.block_hash
  log(`beforeConsume - ${event}`)
  return true
1 Like

Ok perfect that it works
Closing topic
Good luck!