I deleted all rows and modified the code to use the Moralis.units functions. Now the “value” column again doesnt get created and filled in the database.
Moralis.Cloud.afterSave("_AddressSyncStatus", async request => {
try {
logger.info(
"afterSave _AddressSyncStatus " + JSON.stringify(request.object)
);
const balance = await Moralis.Web3API.account.getNativeBalance({
address: request.object.get("address")
});
const ethBalance = await Moralis.Cloud.units({
method: "fromWei",
value: balance["balance"]
});
logger.info(JSON.stringify(ethBalance));
addressObj.set("value", ethBalance);
return await addressObj.save(null, { useMasterKey: true });
} catch (error) {
logger.info(error);
}
});
The log shows the output of the Unit function, but its not getting saved again. Any idea why?
2022-03-20T17:46:43.012Z - Ran cloud function coreservices_getConfig for user undefined with:
Input: {}
Result: {"status":200,"data":{"success":true,"result":{"providers":[{"chain":"Eth","name":"Mainnet","network":"mainnet","exchange":"eth","chainId":"0x1","lookups":["eth","mainnet","0x1"],"token":{"name":"Ether","symbol":"ETH"},"httpProviderUrl":"eth/mainnet","maxRecordsPerCategory":50,"userSync":true}],"addressSyncs":[{"chainId":"0x1","address":"0x25eaff5b179f209cf186b1cdcbfa463a69df4c45","syncHistorical":false,"key":"0x25eaff5b179f209cf186b1cdcbfa463a69df4c45_1"},{"chainId":"0x1","address":"0xa7e4fecddc20d83f36971b67e13f1abc98dfcfa6","syncHistorical":false,"key":"0xa7e4fecddc20d83f36971b67e13f1abc98dfcfa6_1"},{"chainId":"0x1","address":"0xeddf8eb4984cc27407a568cae1c78a1ddb0c2c1b","syncHistorical":false,"key":"0xeddf8eb4984cc27407a568cae1c78a1ddb0c2c1b_1"},{"chainId":"0x1","address":"0xfd898a0f677e97a9031654fc79a27cb5e31da34a","syncHistorical":false,"key":"0xfd898a0f677e97a9031654fc79a27cb5e31da34a_1"}],"eventSyncs":[]}}}
2022-03-20T17:46:42.439Z - undefined
2022-03-20T17:46:42.437Z - "150000"
2022-03-20T17:46:42.354Z - Ran cloud function coreservices_getWeb3ApiToken for user undefined with:
Input: {}
Result: {"status":200,"data":{"success":true,"result":"O148899.1647798402351.0x62afc435a2604665b5d5cafead30091ffa386be89989b80bd7c6b22c87fe4de9"}}
2022-03-20T17:46:42.334Z - afterSave _AddressSyncStatus {"address":"0xeddf8eb4984cc27407a568cae1c78a1ddb0c2c1b","chain":"Eth","updatedAt":"2022-03-20T17:46:42.323Z"}