Iโm having trouble reading token balance, incrementing it, and storing it back as a string.
Whenever I try out some function, the IDE (here VS Code) tells me that function is not available.
Currently, this is the code I use:
class PlayerReward extends Moralis.Object {
constructor() {
super("PlayerReward");
}
incrementRewards() {
const rewardToAdd = Moralis.Cloud.units({
method: "toWei", value: REWARD_PER_SIGNAL
});
const accumulatedReward = Moralis.Cloud.units({
method: "toWei", value: this.get(KEY_ACCUMULATED_REWARD)
});
const newAccumulatedReward = Moralis.Cloud.units({
method: "fromWei", value: accumulatedReward.plus(rewardToAdd).toString()
});
this.set(KEY_ACCUMULATED_REWARD, newAccumulatedReward);
}
}
Moralis.Object.registerSubclass("PlayerReward", PlayerReward);
Obviously, it throws errors, such as this one:
2022-01-14T14:43:34.993Z - Error: Moralis units - Missing property `value`
at Object.units (/moralis-server/lib/cloud-code/units.js:27:11)
at PlayerReward.incrementRewards (eval at customUserPlugin (/moralis-server/cloud/main.js:140:21), <anonymous>:1:307)
at Moralis.Cloud.define.fields (eval at customUserPlugin (/moralis-server/cloud/main.js:140:21), <anonymous>:1:1653)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
2022-01-14T14:43:34.991Z - Failed running cloud function putWalletWasActiveInInterval for user TMxzXlbYaRxsQ1u3jT0uLkP4 with:
Input: {"signal":true}
Error: {"message":"Moralis units - Missing property `value`","code":141}
Most Cloud functions are not recognised in Typescript:
So itโs impossible to solve the problem without the IDE acting as a crutch.
Any assistance will be truly appreciated!