# Add balances to squid accounts

**URL:** <https://forum.duniter.org/t/add-balances-to-squid-accounts/12782>\
**Category:** Indexers\
**Created:** [14 December 2024 18:10 UTC](https://forum.duniter.org/t/add-balances-to-squid-accounts/12782 "2024-12-14T18:10:58Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)\
**Post date:** [18 December 2024 16:09 UTC](https://forum.duniter.org/t/add-balances-to-squid-accounts/12782/4 "2024-12-18T16:09:10Z")

</div>

> [@vjrj](#):
>
> Currently I have a bug in my development environment and I get zero for all the v2 balance queries

I started a developer documentation ([Duniter | Developer guide](https://duniter.org/wiki/duniter-v2/doc/)) to explain these kind of things, but I have less time ([Je ne suis plus à plein temps!](https://forum.duniter.org/t/je-ne-suis-plus-a-plein-temps/12756)), so it’s moving slowly.

To get the free balance, you have to use `storage.system.account` and not `storage.balances.account`. This does not account for unclaimed UDs.

It is the goal to be able to get balance from indexer ([#11](https://git.duniter.org/nodes/duniter-squid/-/issues/11)) but that’s not an easy task. So for now, it makes sense to ask directly to Duniter and compute unclaimed UDs.

> [@vjrj](#):
>
> Why can we not get the total balance in the indexers too without doing the query to polkadot on-chain?

Because it is not done yet. And it is not done yet because it is not easy. From indexer point of view, to get the balance, you have to handle for every kind of balance change event or directly listen on storage. And if you want to have unclaimed UDs you have to update as many accounts as there are identities at every new UD.

> [@vjrj](#):
>
> I don’t know if this was discussed already.

This “unclaimed UD” optimization was necessary (Duniter side) and discussed here:

- [Production du DU](https://forum.duniter.org/t/production-du-du/8998) (protocol presentation)
- [Implémentation création manuelle du DU et guide pour dev clients/wallet](https://forum.duniter.org/t/implementation-creation-manuelle-du-du-et-guide-pour-dev-clients-wallet/9544) (implementation)

> [@vjrj](#):
>
> Sorry for the newbie question.

If only all “newbies” were developing a full Duniter client 😹

> [@poka](#):
>
> Problème: Ces nouveaux events participeront à augmenter encore la taille de la blockchain.

Due to the nature of blockchain, we have to keep things quite minimal, especially what we want to happen at a high rate (money transfers). That’s the very reason of the UD optimization.

> [@poka](#):
>
> Et je maintiens que ce n’est pas au rôle de l’indexer de gérer des données mutables.

Yes it is. The indexer role is to make app development as easy as possible and to counterbalance the “minimalistic” nature of blockchain by providing as rich features as affordable. See [#36](https://git.duniter.org/nodes/duniter-squid/-/issues/36) for indexer optimizations.

> **read more on pallet balances**
>
> For people who want to read more:
> 
> - [https://paritytech.github.io/polkadot-sdk/master/pallet\_balances/](https://paritytech.github.io/polkadot-sdk/master/pallet_balances/)
> - or [https://doc-duniter-org.ipns.pagu.re/pallet\_balances/](https://doc-duniter-org.ipns.pagu.re/pallet_balances/)
> 
> You have a bit more info on the events in the doc [https://paritytech.github.io/polkadot-sdk/master/pallet\_balances/pallet/enum.Event.html](https://paritytech.github.io/polkadot-sdk/master/pallet_balances/pallet/enum.Event.html).

> [@poka](#):
>
> mais je ne les ai jamais observé pour de vrai en blockchain:

If you want examples:

```auto
> https://squid.gdev.coinduf.eu/v1/graphql
query Events($name: String!) {
  event(where: {name: {_eq: $name}}, limit: 1) {
    id
  }
}
{"name": "Endowed"}

```

And replace `name` by the event you want to test.

> [@poka](#):
>
> Balances.Endowed : An account was created with some free balance.  
> Balances.DustLost : An account was removed whose balance was non-zero but below ExistentialDeposit, resulting in an outright loss.  
> Balances.Transfer : Transfer succeeded.  
> Balances.BalanceSet : A balance was set by root.  
> Balances.Reserved : Some balance was reserved (moved from free to reserved).  
> Balances.Unreserved : Some balance was unreserved (moved from reserved to free).  
> Balances.ReserveRepatriated : Some balance was moved from the reserve of the first account to the second account. Final argument indicates the destination balance type.  
> Balances.Deposit : Some amount was deposited (e.g. for transaction fees).  
> Balances.Withdraw : Some amount was withdrawn from the account (e.g. for transaction fees).  
> Balances.Slashed : Some amount was removed from the account (e.g. for misbehavior).  
> Balances.Minted : Some amount was minted into an account.  
> Balances.Burned : Some amount was burned from an account.  
> Balances.Suspended : Some amount was suspended from an account (it can be restored later).  
> Balances.Restored : Some amount was restored into an account.  
> Balances.Upgraded : An account was upgraded.  
> Balances.Issued : Total issuance was increased by `amount`, creating a credit to be balanced.  
> Balances.Rescinded : Total issuance was decreased by `amount`, creating a debt to be balanced.  
> Balances.Locked : Some balance was locked.  
> Balances.Unlocked : Some balance was unlocked.  
> Balances.Frozen : Some balance was frozen.  
> Balances.Thawed : Some balance was thawed.  
> Balances.TotalIssuanceForced : The `TotalIssuance` was forcefully changed.

TODO check why `UniversalDividend.UdsClaimed` does not come with `Balances.Issued` but `Balances.Deposit`.

I’ll have a look at your MR [!27](https://git.duniter.org/nodes/duniter-squid/-/merge_requests/27). I hope to see unclaimed UD indexing ^^.

---

_[View the full topic](https://forum.duniter.org/t/add-balances-to-squid-accounts/12782)._
