The code you referenced does not work for me. I get the following error:
await api.query.system.balances.entries(ADDR, (res) => {
^
TypeError: Cannot read properties of undefined (reading 'entries')
You have the correct format for entries. For example:
const referenda = await api.query.referenda.referendumInfoFor.entries();
referenda.forEach(async (referendum) => {
if (referendum[1].toHuman()['Ongoing']) {
const referendumIndex = referendum[0].args[0].toNumber();
console.log("Referendum:", referendumIndex);
console.log(referendum[1].toJSON());
}
});
Depending on your chain, the balances of your accounts are actually stored in FRAME system pallet.
Perhaps this is what you are trying to achieve:
import { ApiPromise, WsProvider } from "@polkadot/api";
export const subscribeBalances = async () => {
const provider = new WsProvider(ENDPOINT);
const api = await ApiPromise.create({ provider });
api.query.system.account(ADDR, (balance) => {
console.log(`Balance for account ${account}: ${balance.data.free}`);
});
};
Or depending on what you're trying to achieve you can also listen for events from the balances pallet. For example: