Get balance of specific Address

Hello again :slight_smile:

I’m interested in making a little script that gets the actual balance of a Cardano wallet, by their address.

I’ve achieved to get transactions the following command:

cardano-cli query utxo --address ${ADDRESS} --mainnet

  TxHash                                 TxIx        Amount
ADDRESS                              4               1500000 lovelace

As of today, I’ve only made one transaction. I sent 1.5 ADA to this account. So getting the balance it’s easy.

But what about if this transactions ends up getting up to thousands of transactions. Is this the only method of getting the balance? By adding/deducting in/out transactions and get the final add-up of all the math done.

Or is there an easier command-line tool to get the full transaction of an address?

Thanks in advance.


Hey there :grinning:

Hopefully this isn’t too late or will help someone else.

I am doing something similar and this is what I used

text="$(cardano-cli query utxo --address $address --mainnet | grep lovelace)"
IFS=’ ’
read -A strarr <<< “$text”
echo $txhash
echo $txix
echo $funds

Basically grep the output and save it as a variable. Then use IFS and read array to split the text. I’m using zsh so the read command needs a capital A. Here’s the link for reference.

1 Like

Hi guys,

I use the following one-liner :slight_smile:

cardano-cli query utxo --mainnet --address $(cat /path/to/address ) | awk ‘{sum+= $3} END {print sum}’

Good luck!

1 Like