Real Time Transactions

Default

Realtime ETH Transfers (Default)

This plugin will connect to our ethereum node and broadcast any new ETH transactions to your Moralis.EthTransactions subclass

Realtime Token Transfers (Default)

This plugin will connect to our ethereum node and broadcast any new ERC20 and ERC721 transactions to your Moralis.EthTokenTransfers subclass

Ethereum Real-Time and Historic Transactions - Web3 Programming

Sync and Watch Contract Events

This plugin will allow you to get all historical events from a specific smart contract topic and at the same time listen to new events in realtime. In order to set up this plugin you will need the following information:

  • description : This is a short description for you to keep track of the events more easily.

  • topic: The topic you will listen to, this could either be a definition or sha3:

    • bet(address,uint256,bool)

    • 0x20d932006281d267f137cd3921b707c2097e1f041b1291181cc3d0e86f449ebb

  • abi: If you provide the abi for this event, Moralis will automatically parse all the fields and populate the schema accordingly.

  • address: The address you will listen to for this event.

  • tableName: The name of the subclass that will be created in your Moralis database.

if you do not provide the abi the following schema will be used :

{
"objectId": String,
"block_hash": String,
"topic0": String,
"topic1": String,
"block_timestamp": Date,
"ACL": ACL,
"data": String,
"updatedAt": Date,
"transaction_hash": String,
"transaction_index": Number,
"address": String,
"log_index": Number,
"createdAt": Date,
"block_number": Number
}

This is an example of a valid abi:

{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "bet",
"type": "uint256"
},
{
"indexed": true,
"internalType": "bool",
"name": "win",
"type": "bool"
},
{
"indexed": false,
"internalType": "uint8",
"name": "side",
"type": "uint8"
}
],
"name": "bet",
"type": "event"
}

If the abi provided contains an "id" input will be parsed to "uid" due to field "id" being reserved in the Moralis.Object

Sync and Watch Address

By default only the transaction data for registered users will appear in the EthTransactions collection. To watch a specific address- like a Centralized Exchange hot wallet- add a new Sync and Watch Address plugin, enter the Address then click the "Add Plugin" button.

This starts a sync job and adds an entry to the WatchedEthAddress collection. Once the transactions are synced they can be queried like any other transactions, including Live Queries.

const web3 = new Moralis.Web3();
const binanceWallet = "0x...";
// create query
const query = new Moralis.Query("EthTransactions");
query.equalTo("to_address", binanceWallet);
// subscribe for real-time updates
const subscription = await query.subscribe();
subscription.on("create", function(data) {
const amountEth = web3.utils.fromWei(data.attributes.value);
console.log(`${amountEth} deposited to Binance`);
});

Keep in mind that watching an address with with a lot of transaction volume will result in a lot of data being stored. See the Cloud Functions and Live Query sections for more details.

Casing

When syncing addresses from smart contracts, Moralis will normalize them to lowercase in order to make it possible to make queries against them in the database. When comparing an address that comes from outside the Moralis database (for example your Metamask wallet), make sure to convert it to lowercase when running queries against addresses stored in the Moralis database.

// Lets say that this address is taken from outside Moralis (Note the mixed cases)
let address = '0xEDe998b7BdE2467732b748613a1Aab4e5528dE15';
// In order to make queries mased on the address you can convert it to lowercase
address = address.toLowerCase();
// Now we can use the address in our queries
const query = new Moralis.Query("EthTokenBalance");
query.equalTo("owner_of", address);