so i went to the dashboard, selected “BscTokenTransfers” clicked on “add a new column” type string, name usdval, and finally added it.
Did also restart the server, just to be sure.
So once the cloudfunction is running, i am doing some debug. first here the current coding just using for testing the functions to learn:
Moralis.Cloud.afterSave("BscTokenTransfers", async function (request) {
const confirmed = request.object.get("confirmed");
if (confirmed) {
const logger = Moralis.Cloud.getLogger();
logger.info(JSON.stringify(request.object));
logger.info("Token "+request.object.get("token_address"));
logger.info("From "+request.object.get("from_address"));
logger.info("Block "+request.object.get("block_number"));
if(request.object.get("from_address") != "0x0000000000000000000000000000000000000000")
{
const options = {
address: request.object.get("token_address"),
chain: "bsc",
to_block: request.object.get("block_number"),
};
logger.info(options);
const price = await Moralis.Web3API.token.getTokenPrice(options);
logger.info("price "+price.usdPrice);
const BscTransfers = Moralis.Object.extend("BscTokenTransfers");
const query = new Moralis.Query(BscTransfers);
query.equalTo("transaction_hash", request.object.get("transaction_hash"));
const result = await query.first({useMasterKey:true})
logger.info(JSON.stringify(result));
result.set("usdval",price.usdPrice);
result.save();
}
} else {
}
});
The logger infos are working, i get all the datas i need from that request.
But the update of the column does not work (no error also, wich i dont understand)
and thats the log i get from the JSON.stringify(result)
{"from_address":"0x0000000000000000000000000000000000000000","log_index":146,"to_address":"0xa81fc1c50.......","transaction_hash":"0x4b02a30240cc0a5a33.......","createdAt":"2022-04-14T18:16:33.014Z","updatedAt":"2022-04-14T18:17:44.188Z","block_hash":"0x19d873e4740515e4aaf6........","block_number":16945665,"block_timestamp":{"__type":"Date","iso":"2022-04-14T18:16:32.000Z"},"decimal":{"__type":"NumberDecimal","value":"766688888.086156601507948247"},"token_address":"0xc0908ea0b6642a.....","transaction_index":77,"value":"766688888086156601507948247","confirmed":true,"objectId":"WK0l9vrKTmE2HYv4qSkv4v74"}
as you can see, the “usdval” column is not listed … idk if it lists it because its “(undefined)” at the moment
but either way, the function runs through, and the value is still undefined