Hey guys,
This is my first time using Moralis, I’m following the guided tutorial, I’m using a mainnet instance.
here is the CF code:
Moralis.Cloud.define("getAvgGas", async function (request) {
const query = new Moralis.Query("EthTransactions");
const pipeline = [
{
group: {
// group by "from_address"
objectId: "$from_address",
// add computed property avgGas
// get average and convert wei to gwei
avgGas: { $avg: { $divide: ["$gas_price", 1000000000]} },
},
},
{ sort: { avgGas: -1 } }, // sort by avgGas high to low
{ limit: 10 }, // only return top 10 results
];
// the master key is required for aggregate queries
const results = await query.aggregate(pipeline, { useMasterKey: true });
return results;
})
here is the log for when I try and call the CF:
2021-09-11T21:42:11.311Z - Ran cloud function getAvgGas for user ediZ5GI9AlBUXxndYX1mjK06 with:
Input: {}
Result: []
Screenshot of the console logs: