[SOLVED] Accessing Moralis.Units in Cloud function returns undefined

Im trying to make use of the Moralis.Units utility functions from within a cloud function but I get an undefined error.

Error: {“message”:“Cannot read properties of undefined (reading ‘FromWei’)”,“code”:141}

Moralis.Cloud.afterSave("WatchedEthAddress", async (request) => {
    const logger = Moralis.Cloud.getLogger();
 	const address = request.object.get("address");
  logger.info("afterSave triggered for address " + address);
    const options = { chain: "eth", address: address};
	const {balance} = await Moralis.Web3API.account.getNativeBalance(options);
  	const ethBalance = Moralis.Units.FromWei(balance)
  	logger.info("afterSave balance response " + ethBalance);
	request.object.set("eth_balance", ethBalance);
	await request.object.save(null,{useMasterKey:true});

there is a different syntax for units in cloud code: https://docs.moralis.io/moralis-server/cloud-code/cloud-functions#units

1 Like

thank you I updated and it seems to work.