I am trying to make a Node.js bot, so I found a module, installed it and tried out its example code.
Now, I have an async function that loads some text from an API. This is the code:
(async () => {
// Display user's balance
balance = kraken.api('Balance');
console.log(await balance);
})();
{
error: [],
result: { A: '2.0', BC: '0.005', BCA: '111' }
}
console.log(await balance.result.A)
(node:6604) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'A' of undefined
(node:6604) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
You habe to put your await statement in parentheses, like this:
console.log((await balance).result.A);
This will fetch the balance asynchronously, then log the result property.