How to display transaction status efficiently?

Hi am trying to build an app that shows live status of the crypto transfers (Only cryptos not NFTs). Like if one transaction gets initiated it should show Transaction pending and once the transaction gets completed/ verified in the block it should update the status from pending to completed.

I know live queries does this job but in this case it’s not possible to use it?

I also know that we can monitor the transactions from SYNC. Well in that case how may I add the public address to sync for every other users of my app ? is there any code for this to automate ?

Yes. I can think of doing this only through live query subscriptions.

For logged-in users you can query the EthPendingBalance / EthTransactions class in database to track the transaction.

For non-loggedin users, you can add an address to sync through code and then query the synced data from the database.

Yes there is a way to sync addresses through code.
https://docs.moralis.io/moralis-dapp/automatic-transaction-sync/historical-transactions#monitoring-non-authenticated-address

1 Like

Okay so you mean that using sync address thorough code I can fetch and display the token transfer history for the respective logged in users right ?

Should I paste the public address in the sync tab in the server details section ? If so it becomes like pasting x number of my app user’s public addresses ! :woozy_face:

why paste - do from code https://docs.moralis.io/moralis-dapp/automatic-transaction-sync/historical-transactions#watch-address-from-code

1 Like

Hmm got it. So I need to run
const results = await Moralis.Cloud.run("watchBscAddress", { address: "0x..." , sync_historical: true, }); //sample code once for each new user ? or should I re- run this code for each time after login ?

What if I link new account for a user. Should I run the watch code again for that address too ?

It says invalid function “watchEthAddress” :frowning:. Even the code copied from the docs isn’t working …

@cryptokid Please help me

1 Like

this is an example that works, I tested it today:

        const results = await Moralis.Cloud.run("watchEthAddress", {address: address, sync_historical: false}, {useMasterKey: true})

but you can not run it in front end, you could run it in cloud code, as it requires master key.

if a user authenticates with metamask, then you don’t have to add that particular eth address to watch because it will be synced automatically

Moralis.Cloud.define("watchAddress", async(request)=>{
  const logger = Moralis.Cloud.getLogger();
  logger.info("watchAddress called from front end")
  const address = request.params.address;
  
  if(!address) throw Error("no address provided");
   const result = await Moralis.Cloud.run("watchEthAddress",{address: address, sync_historical: false}, {useMasterKey:true});
  return result ;
});

This is the code is use as cloud function and when I pass the address from the front end it says invalid function “watchEthAddress” .
As you said “if a user authenticates with metamask, then you don’t have to add that particular eth address to watch because it will be synced automatically”. so you mean that I don’t need to run the above code for every individual user if the use metamask login to access my app ?

  1. I have been using Metamask login for past one month but I couldn’t get the transaction history !

  2. Is it available only for the paid version ?

My computer science degree is in your hands :slight_smile: am building my final semester project using moralis. :+1:

that functionality is available for every server.

what is the server url?

did you update the server recently and it is a nitro server with coreservices plugin?

https://exboijyxfajc.usemoralis.com:2053/server

Server url above…

Nitro server ???

yes, that is a nitro server, and it seems to be updated

what evms/chains did you enable for that server? you can find that information in admin interface

Poylgon mumbai and avax testnet

try to enable also an eth chain if you want to add to watch an address on eth

That’s okay but the problem is that the cloud functions says watchXxxAddress is invalid
(irrespective of any chains)

you tried with other chains too?

This is what I get :frowning:

you tried with watchEthAddress only here?

:slight_smile:

`Moralis.Cloud.define(“watchAddress”, async(request)=>{
const logger = Moralis.Cloud.getLogger();
logger.info(“watchAddress called from front end”)
const address = request.params.address;

if(!address) throw Error(“no address provided”);
const result = await Moralis.Cloud.run(“watchXxxAddress”,{address: address, sync_historical: false}, {useMasterKey:true});
return result ;
});`

that is not how it should work, you have to replace watchXxxAddress with the chain where you want to add that watch, for example on eth is watchEthAddress