Moralis.Cloud.run('watchEthAddress', {
address,
syncHistorical: false,
useMasterKey: true,
});
I’ve tried adding it to the other queries as well below is the whole cloud code:
Moralis.Cloud.define('watchAddress', async (request) => {
const logger = Moralis.Cloud.getLogger();
//Check address has been inputted
if (!request.params.address) {
logger.info('error:missing address param');
}
const address = request.params.address;
if (!address) {
return null;
}
//Check address is not already being watched
const countQuery = new Moralis.Query('WatchedEthAddress', {
useMasterKey: true,
});
countQuery.equalTo('address', address, { useMasterKey: true });
const watchCount = await countQuery.count({ useMasterKey: true });
if (watchCount > 0) {
return null;
}
//Add address to watch list
Moralis.Cloud.run('watchEthAddress', {
address,
syncHistorical: false,
useMasterKey: true,
});
//Fire alert every time there is a new tx
Moralis.Cloud.afterSave('EthTransactions', async (request) => {
//Check address is in watch list
const to_address = request.object.get('to_address');
// Query lsit iof watched addresses
const query = new Moralis.Query('WatchedEthAddress', {
useMasterKey: true,
});
// Check address of tx === to_address
query.equalTo('address', to_address);
const results = await query.find({ useMasterKey: true });
//If results exist fire alert
if (results) {
logger.info('----------------');
logger.info('https://etherscan.io/tx/' + request.object.get('hash'));
logger.info('--🚨ALERT 🚨--');
}
});
return true;
});