Avalanche testnet

Hi there.

I’m new to use Moralis, so I ask you not to kick me)

Is it possible to use Moralis nodes with web3Js for use something like subscribes for transactions of specified addresses in the Avalanche testnet? So I put some addresses and create subscribe for a new transactions.

On the one hand, on the main page found an interesting code:

Moralis.Web3();
binanceWallet = "0x...";

// create query
Moralis.Query("EthTransactions");
query.equalTo("to_address", binanceWallet);

// subscribe for real-time updates
query.subscribe();
subscription.on("create", function(data)
{
	web3.utils.fromWei(data.attributes.value);
	
	console.log(`${amountEth} deposited to Binance`);
});

But, he does not quite suit me … On the other hand, I found it in the documentation: Events.

  • onWeb3Enabled
  • onWeb3Deactivated
  • onChainChanged
  • onAccountChanged
  • onConnect (fired from the EIP1193 provider)
  • onDisconnect (fired from the EIP1193 provider)

This is also not exactly what I need (((

So for example I see code like this:

Moralis.Web3();
avalancheWallet = "0x...";

// create query
Moralis.Query("<????>");
query.equalTo("to_address", avalancheWallet);

// subscribe for real-time updates
query.subscribe();
subscription.on("Transfer", function(tx)
{
    console.log(`${tx}`);
});

I will be grateful for any useful information.

Thanks.

what exactly do you need?

I need get transactions by address at the Avalanche testnet in real-time.

first step could be to add that address to watch address on your server, so what you get those transactions in your server db

Wow! Cool! How I can do it? And how I can fired event when tx is come?

first step is to get that data synced, https://docs.moralis.io/moralis-server/automatic-transaction-sync/historical-transactions#watch-address-from-code

after that you can use beforeSave, or afterSave hooks, or read directly from db, or live queries, or run a job periodically on server

Am I right that I need at first add my addresses to the server (Servers -> Choose server -> View Details -> SYNC -> Sync and Watch Address). Then you send me the link https://docs.moralis.io/moralis-server/automatic-transaction-sync/historical-transactions#chain-prefixes for use code:

const results = await Moralis.Cloud.run("watchBscAddress", {address: "0x..."})

The Sync and Watch Address plugin calls a Cloud Function called watchXxxAddress under the hood, where “Xxx” are the chain names here. These cloud functions can also be called directly from your own code!

But there is no chain name (Xxx) for Avalanche testnet or I need use something else?

Thanks.

you can try Avx for avalanche, you will also need to use master key to make that work from cloud code or from node js, you can add an address to watch from the interface initially, from that Sync and Watch Address that you mentioned

You mean:

const results = await Moralis.Cloud.run("watchAvxAddress", {address: "0x..."})

Found this: https://c2n.me/4eXAez8.png, so may be it’s:

const results = await Moralis.Cloud.run("watchAvaxAddress", {address: "0x..."})

How and where? Could you please provide me with some code examples or links for documentation?

How and where? Could you please provide me with some code examples or links for documentation?

Thanks.

The interface is not with code, in admin interface in server info in sync tab.
You should be able to find examples with master key on forum in other posts.

Now I see. I already do it. What I need to do next?

Ok. Thanks. I will try … But for now can you provide me with the next steps after I was added addresses for sync. What next?

Thanks a lot for your attention!

After that, it depends on what you want to do, now you should read the data from database, or use a hook like beforeSave. It depends on your intended use case.

Now you can look in dashboard to see how data gets synced in a table.

I want to subscribe for a new tx for each address. If it’s possible to do with NodeJs like this:

Moralis.Web3();
arAvalancheWallet = [
    "0x...",
    "0x...",
    "0x...",
    "0x...",
    "0x...",
    ...
];

// create query
Moralis.Query("<???>"); - what I need write there? May be AvaxTransactions (from Dashboard)
query.equalTo("to_address", arAvalancheWallet[0]);

// subscribe for real-time updates
query.subscribe();
subscription.on("<???>", function(tx) - what I need write there? 
{
    // code for fired tx
});

Or may be I can setup webhook which will be sent tx for my side? Is it possible?

Ouch … I see there is a lot of tx. But how I can subscribe for this, for example from NodeJs?

Thanks a lot for your attention!

You can connect directly to db from nodejs too, I think that you can also use live query

First try to make a simple query

I think you still don’t understand me, and what I need. I don’t need to make requests to the database or wherever, I need that I receive notifications for certain events at the specified address. In my case, this is when a new transaction is created for the address I am added.

In the case of the code - I launched the code, and, it is waiting for a new transaction as soon as the new transaction appears on the specified address - I receive notifications about it within the subscription block in code. This is what I need.
In the case of a web hook (which is more convenient for me) - the situation is the same: I subscribed to new transactions for certain addresses, and, in the event of a new transaction, I also receive a notice of it.

So I explained - what do I need?

Thanks a lot for your attention!

You can try a hook like beforeSave, afterSave, or a webhook directly, if you want notification in nodejs, you would have to use live query, you can read in documentation about all of the above.

Already prepare some domain for it …

What u mean?

Already searching but didn’t find anything about transactions ((( Can u provide me with that (not for common docs but for subscribe for transactions)?

Thanks!

Try live query in general for a database table, it doesn’t matter what is the table.

What u mean? I see this doc but there is no events like transactions / transfers. So I didn’t understand how it can help me.

Thanks.

You subscribe to the contents of a table, it doesn’t matter what is in that table. First step was to sync in a table what you need.