Cardano-cli-js Wallet.balance() is very slow

Hi
I want to get balance of my wallet with this code:

wallet.balance().value.lovelace

But this code takes time about 3 seconds!
How can I improve it?

Since cardanocli-js is just a wrapper around cardano-cli and that one has no efficient away to query the balance of a wallet, it is very possible that there simply is no faster way.

cardano-cli query utxo is also very slow and to get the balance of a wallet that has to be done for all addresses of the wallet.

You maybe want to look into other possibilities like using the blockfrost.io or koios.rest APIs (with the added benefit that you do not need to run a node).

2 Likes

Thank you
So, koios.rest how is fast?!
How can I fast like koios.rest?
@HeptaSean

You could install cardano-db-sync (https://github.com/input-output-hk/cardano-db-sync) in parallel to the cardano-node. It extracts the information from the blocks of the blockchain into a Postgres database that you can then query pretty fast.

CNCLI (https://github.com/cardano-community/cncli) synchronises into a SQLite database, but it is more targeted to node operators and I don’t know if all transactions and balances are available in that database.

Both will require a considerable amount of disk space in addition to the soon to be 100 GiB that the node itself already needs.

1 Like