A shell script to list all wallet transactions

Currently Chia GUI and CLI limit transactions history at 50, I had to write a Bash script to fetch all transactions directly from wallet’s DB. This script must be run on the same machine that has the wallet DB, and must have sqlite3 program installed. It takes a single argument, which is the fingerprint of your wallet.

Example:
chia-show-tx 0123456789

Output:

...
"2021-09-13 08:36:08", IN , 0.010056841884
"2021-09-14 09:47:24", IN , 0.010038899771
"2021-09-14 14:56:57", OUT, 0.005000000000
"2021-09-15 13:09:29", IN , 0.010021268043
"2021-09-15 19:46:12", IN , 0.000000000078
------------------------------------------
Total balance = 0.550163263767
...

Here’s the script:

#!/bin/bash
rm -f /tmp/wallet-txt.csv

sqlite3 -readonly \
    ~/.chia/mainnet/wallet/db/blockchain_wallet_v1_mainnet_$1.sqlite \
    ".mode csv" \
    "SELECT datetime(created_at_time, 'unixepoch', 'localtime'), hex(amount), sent FROM transaction_record WHERE wallet_id = 1" \
    > /tmp/wallet-tx.csv

balance=0
while IFS= read -r line; do
    c=0
    IFS=,
    for v in $line; do
        let c=c+1
        case $c in
            1) time="$v" ;;
            2) amount=$(printf '%0.12f' $(bc -l <<< "scale=12;$((16#$v))/10^12")) ;;
            3)
                if [ ${v::1} -eq 0 ]; then
                    dir="IN "
                    balance=$(bc -l <<< "$balance + $amount")
                else
                    dir="OUT"
                    balance=$(bc -l <<< "$balance - $amount")
                fi
                ;;
        esac
    done
    echo $time, $dir, $amount
done < /tmp/wallet-tx.csv

echo ------------------------------------------
echo Total balance = $(printf '%0.12f' $balance)

rm -f /tmp/wallet-txt.csv
2 Likes

Thank you!
Ppl have been asking for this here.

1 Like

Hi @Tariusagi,

First, thanks for sharing this script. I’m having a hard time understanding where sqlite3 needs to be installed. Does it need to be installed in the same folder as chia.exe? From there, do I simply open a powershell window in that folder and run the script? Thanks again.