Skip to content

Instantly share code, notes, and snippets.

@tumf
Last active July 11, 2020 07:37
Show Gist options
  • Save tumf/70882949e523d297e6a5a1e93d10276c to your computer and use it in GitHub Desktop.
Save tumf/70882949e523d297e6a5a1e93d10276c to your computer and use it in GitHub Desktop.
#!/bin/bash
# UTXO checker for Bitcoin mainnet
api=https://blockstream.info/api
function usage()
{
cat <<-EOF
usage: $(basename $0) tx_id index
EOF
}
commands='jq curl'
for c in $commands; do
hash $c || { echo "install $c"; exit 255; }
done
tx=$1
index=$2
[ -n "$tx" ] || { usage; exit 255; }
[ -n "$index" ] || { usage; exit 255; }
result=$(curl -s "${api}/tx/$tx/outspends" | jq ".[${index}].spent")
[ "$result" = "null" ] && { echo 'invalid'; exit 255; }
value=$(curl -s "${api}/tx/$tx" | jq ".vout[${index}].value")
[ "$result" = "false" ] && { echo "$value unspent"; exit 0; }
[ "$result" = "true" ] && { echo "$value spent"; exit 1; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment