Loading...
            
Loading...
  
Saturday, July 27, 2024
Home » How to Check the Balance of Any Bitcoin Address and See Transaction Details Using bitcoin-cli

How to Check the Balance of Any Bitcoin Address and See Transaction Details Using bitcoin-cli

Understanding the Intricacies of Bitcoin Transactions: A Comprehensive Guide to Using bitcoin-cli for Analyzing Spent and Unspent Outputs on the Blockchain

by BiTux
0 comment

Bitcoin’s decentralized nature allows anyone to inspect transaction details and address balances on the blockchain. For those seeking a more technical and in-depth approach, bitcoin-cli offers powerful tools to achieve this. In this article, we’ll explore how to use bitcoin-cli to check the balance of any Bitcoin address and delve into transaction details, using the example address 397qgNDydQ4Ui6Ah4FurnxmmUDcDHsyJEv.

Checking the Balance of a Bitcoin Address

To check the balance of a Bitcoin address, you can use the scantxoutset command. This command scans the blockchain’s UTXO set for outputs associated with a specific address.

Using scantxoutset

Run the following command to check the balance of address 397qgNDydQ4Ui6Ah4FurnxmmUDcDHsyJEv:

$ bitcoin-cli scantxoutset start '["addr(397qgNDydQ4Ui6Ah4FurnxmmUDcDHsyJEv)"]'

This command returns all UTXOs associated with the address and provides the total balance.

Checking the Balance of a any arbitrary Bitcoin Address with bitcoin-cli

Checking the Balance of a any arbitrary Bitcoin Address with bitcoin-cli. Here we can see transaction ID as well total amount of BTC available

Delving into Transaction Details

Understanding transaction details requires knowing the transaction ID (txid) and the output index (vout).

1. Using getrawtransaction

If you have a transaction ID, use the getrawtransaction command to fetch the transaction’s raw data:

$ bitcoin-cli getrawtransaction "txid" true

Replace “txid” with the actual transaction ID. This command outputs the raw transaction data in a readable JSON format, showing inputs, outputs, amounts, and more. Let’s use the “txid” from the previous output as an example:

$ bitcoin-cli getrawtransaction "8c5cfd8a5a9068501e0901b270a73c9017b7978e2c8987105a1676ae5d73af2d" true
{
  "txid": "8c5cfd8a5a9068501e0901b270a73c9017b7978e2c8987105a1676ae5d73af2d",
  "hash": "2bc272cb95347a08e04dad2a908a14c96fc516cd74ac8729f03965f4303440d1",
  "version": 1,
  "size": 246,
  "vsize": 165,
  "weight": 657,
  "locktime": 0,
  "vin": [
    {
      "txid": "5ef55a3b7e303d3056dfdc1d953bc8c0fda7c7bbe115fe3906a841c9d9c2bd24",
      "vout": 1,
      "scriptSig": {
        "asm": "0014a04c2c26ef49d11a72aae51428fc0ca7563bbca1",
        "hex": "160014a04c2c26ef49d11a72aae51428fc0ca7563bbca1"
      },
      "txinwitness": [
        "3044022029db31efead0515ad9552fc59bcd12b32cf39ea5f9a0384b00eadc2215fa0e67022009bad746eb6bde5bee713aa8db75e26c2c736533f07717aa98df7c70be4f663d01",
        "030373b1fec380338da210dbdacd25024f1182ef91ff482cc27ccea45a6dc2fe2b"
      ],
      "sequence": 4294967293
    }
  ],
  "vout": [
    {
      "value": 1.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 29228f39ef0f3819de68bb913edfaa414b745374",
        "desc": "addr(bc1q9y3g7w00puupnhnghwgnaha2g99hg5m5ul8l68)#eda9fgzt",
        "hex": "001429228f39ef0f3819de68bb913edfaa414b745374",
        "address": "bc1q9y3g7w00puupnhnghwgnaha2g99hg5m5ul8l68",
        "type": "witness_v0_keyhash"
      }
    },
    {
      "value": 437.25916527,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_HASH160 517aba585a3100a500fcdd6c8bcb73fdf00f45f3 OP_EQUAL",
        "desc": "addr(397qgNDydQ4Ui6Ah4FurnxmmUDcDHsyJEv)#rkgyy7ad",
        "hex": "a914517aba585a3100a500fcdd6c8bcb73fdf00f45f387",
        "address": "397qgNDydQ4Ui6Ah4FurnxmmUDcDHsyJEv",
        "type": "scripthash"
      }
    }
  ],
  "hex": "0100000000010124bdc2d9c941a80639fe15e1bbc7a7fdc0c83b951ddcdf56303d307e3b5af55e0100000017160014a04c2c26ef49d11a72aae51428fc0ca7563bbca1fdffffff0200e1f5050000000016001429228f39ef0f3819de68bb913edfaa414b7453746f89442e0a00000017a914517aba585a3100a500fcdd6c8bcb73fdf00f45f38702473044022029db31efead0515ad9552fc59bcd12b32cf39ea5f9a0384b00eadc2215fa0e67022009bad746eb6bde5bee713aa8db75e26c2c736533f07717aa98df7c70be4f663d0121030373b1fec380338da210dbdacd25024f1182ef91ff482cc27ccea45a6dc2fe2b00000000",
  "blockhash": "00000000000000000004c9e55bc79c14918f8f0439d4b11e5929a4c5a0011f5c",
  "confirmations": 20039,
  "time": 1693638398,
  "blocktime": 1693638398
}

The output from the bitcoin-cli getrawtransaction command for the transaction ID 8c5cfd8a5a9068501e0901b270a73c9017b7978e2c8987105a1676ae5d73af2d reveals several key details about the transaction. It includes a unique transaction identifier (txid) and a separate transaction hash (hash), which is especially relevant for SegWit transactions. The version number is shown as 1, and the transaction’s size is listed as 246 bytes, with a virtual size of 165 bytes, reflecting the impact of SegWit on its size. The weight of the transaction, a measure considering SegWit’s influence, is 657, and the locktime is set to 0, indicating that there’s no specific condition on when the transaction can be added to the blockchain.

This transaction comprises one input and two outputs. The input details a previous transaction ID and an output index (which part of that transaction it’s referring to), alongside the unlocking script (ScriptSig) and witness data for SegWit validation. The two outputs specify where the bitcoins are being transferred to: the first output sends 1 BTC to a SegWit (bech32) address, and the second output sends 437.25916527 BTC to a Pay-to-Script-Hash (P2SH) address. The transaction is included in a block (identified by blockhash), confirming it has been validated and added to the Bitcoin blockchain, with over 20,000 confirmations, indicating it’s well-established and irreversible. The time and blocktime fields show the timestamp for when the transaction was included in the block.

2. Decoding Raw Transactions with decoderawtransaction

If you have raw transaction data in hexadecimal format, use decoderawtransaction to decode it:

$ bitcoin-cli decoderawtransaction "raw_transaction_data"

Replace "raw_transaction_data" with the hexadecimal string of the transaction. This command provides a detailed breakdown of the transaction, including each component like inputs and outputs. Once again let;s use the output of the previous command.  As a raw_transaction_data we use hex field:

$ bitcoin-cli decoderawtransaction "0100000000010124bdc2d9c941a80639fe15e1bbc7a7fdc0c83b951ddcdf56303d307e3b5af55e0100000017160014a04c2c26ef49d11a72aae51428fc0ca7563bbca1fdffffff0200e1f5050000000016001429228f39ef0f3819de68bb913edfaa414b7453746f89442e0a00000017a914517aba585a3100a500fcdd6c8bcb73fdf00f45f38702473044022029db31efead0515ad9552fc59bcd12b32cf39ea5f9a0384b00eadc2215fa0e67022009bad746eb6bde5bee713aa8db75e26c2c736533f07717aa98df7c70be4f663d0121030373b1fec380338da210dbdacd25024f1182ef91ff482cc27ccea45a6dc2fe2b00000000"
{
  "txid": "8c5cfd8a5a9068501e0901b270a73c9017b7978e2c8987105a1676ae5d73af2d",
  "hash": "2bc272cb95347a08e04dad2a908a14c96fc516cd74ac8729f03965f4303440d1",
  "version": 1,
  "size": 246,
  "vsize": 165,
  "weight": 657,
  "locktime": 0,
  "vin": [
    {
      "txid": "5ef55a3b7e303d3056dfdc1d953bc8c0fda7c7bbe115fe3906a841c9d9c2bd24",
      "vout": 1,
      "scriptSig": {
        "asm": "0014a04c2c26ef49d11a72aae51428fc0ca7563bbca1",
        "hex": "160014a04c2c26ef49d11a72aae51428fc0ca7563bbca1"
      },
      "txinwitness": [
        "3044022029db31efead0515ad9552fc59bcd12b32cf39ea5f9a0384b00eadc2215fa0e67022009bad746eb6bde5bee713aa8db75e26c2c736533f07717aa98df7c70be4f663d01",
        "030373b1fec380338da210dbdacd25024f1182ef91ff482cc27ccea45a6dc2fe2b"
      ],
      "sequence": 4294967293
    }
  ],
  "vout": [
    {
      "value": 1.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 29228f39ef0f3819de68bb913edfaa414b745374",
        "desc": "addr(bc1q9y3g7w00puupnhnghwgnaha2g99hg5m5ul8l68)#eda9fgzt",
        "hex": "001429228f39ef0f3819de68bb913edfaa414b745374",
        "address": "bc1q9y3g7w00puupnhnghwgnaha2g99hg5m5ul8l68",
        "type": "witness_v0_keyhash"
      }
    },
    {
      "value": 437.25916527,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_HASH160 517aba585a3100a500fcdd6c8bcb73fdf00f45f3 OP_EQUAL",
        "desc": "addr(397qgNDydQ4Ui6Ah4FurnxmmUDcDHsyJEv)#rkgyy7ad",
        "hex": "a914517aba585a3100a500fcdd6c8bcb73fdf00f45f387",
        "address": "397qgNDydQ4Ui6Ah4FurnxmmUDcDHsyJEv",
        "type": "scripthash"
      }
    }
  ]
}

The decoded transaction data from bitcoin-cli decoderawtransaction reveals essential information about a specific Bitcoin transaction. The transaction ID (txid) is 8c5cfd8a5a9068501e0901b270a73c9017b7978e2c8987105a1676ae5d73af2d, and it carries a unique transaction hash (hash) which is particularly important in the context of SegWit transactions. This transaction is of version 1 and has a size of 246 bytes. The virtual size (vsize) is 165 bytes, which is a consideration for SegWit transactions, and it has a weight of 657. The locktime is 0, indicating no specific condition for when the transaction can be added to the blockchain.

The transaction includes one input (vin) and two outputs (vout). The input references a previous transaction ID (5ef55a3b7e303d3056dfdc1d953bc8c0fda7c7bbe115fe3906a841c9d9c2bd24) and includes both a scriptSig, which provides the unlocking script necessary to spend the UTXO, and a txinwitness, indicating the transaction uses SegWit. The two outputs specify the distribution of bitcoins: the first output sends 1 BTC to a bech32 SegWit address (bc1q9y3g7w00puupnhnghwgnaha2g99hg5m5ul8l68), and the second sends 437.25916527 BTC to a Pay-to-Script-Hash (P2SH) address (397qgNDydQ4Ui6Ah4FurnxmmUDcDHsyJEv). This detailed breakdown provides a clear view of the transaction’s flow, from input to outputs, including the addresses and amounts involved.

3. Understanding Output Index with gettxout

To fetch details about a specific UTXO, use the gettxout command with a transaction ID and an output index. The output index (starting from 0) identifies which output of the transaction you’re referring to. For example:

bitcoin-cli gettxout "txid" index

Replace "txid" with the transaction ID and index with the output index. This command gives you details about the specified UTXO, like its value, the owning address, and confirmation status.
Based on the previous output from the bitcoin-cli decoderawtransaction command, we can use the bitcoin-cli gettxout command to get detailed information about a specific unspent transaction output (UTXO) from the transaction.

The transaction ID (txid) from the previous output is 8c5cfd8a5a9068501e0901b270a73c9017b7978e2c8987105a1676ae5d73af2d. The transaction has two outputs, indicated by their output indices (n), which are 0 and 1.

To use the gettxout command, we need the transaction ID and the output index we’re interested in. Let’s say we want to check the second output (which has an index of 1). Here’s how you would structure the command:

$ bitcoin-cli gettxout "8c5cfd8a5a9068501e0901b270a73c9017b7978e2c8987105a1676ae5d73af2d" 1
{
  "bestblock": "00000000000000000003b1ff243c35ad992512a415aff73ed21f9a29052ea000",
  "confirmations": 20043,
  "value": 437.25916527,
  "scriptPubKey": {
    "asm": "OP_HASH160 517aba585a3100a500fcdd6c8bcb73fdf00f45f3 OP_EQUAL",
    "desc": "addr(397qgNDydQ4Ui6Ah4FurnxmmUDcDHsyJEv)#rkgyy7ad",
    "hex": "a914517aba585a3100a500fcdd6c8bcb73fdf00f45f387",
    "address": "397qgNDydQ4Ui6Ah4FurnxmmUDcDHsyJEv",
    "type": "scripthash"
  },
  "coinbase": false
}

This command will return details about the first output of the transaction. It typically includes the amount of Bitcoin in this output, the scriptPubKey, and the number of confirmations.

When the bitcoin-cli gettxout command returns no output for a specific transaction ID and output index, it means that the particular output has already been spent. In Bitcoin, once a transaction output is used as an input in another transaction, it becomes a spent transaction output and is removed from the set of unspent transaction outputs (UTXO). Therefore, the absence of output from this command indicates that the output in question is no longer available as an unspent output on the blockchain.

Conclusion

Using bitcoin-cli to check balances and delve into transaction details of addresses not associated with your wallet offers a deep insight into Bitcoin’s functioning. It’s an invaluable tool for those who want a more technical and comprehensive understanding of Bitcoin transactions. Remember, these commands require a full node, and familiarity with command-line operations is essential for accurate and effective use.

You may also like

Leave a Comment

Contact

TOSID Group Pty Ltd Publishing is a forward-thinking company that specializes in publishing cutting-edge information technology content, providing professionals and enthusiasts with the latest insights and developments in the IT industry.

Latest Articles

Our Mission

We not only facilitate the growth of the blockchain network but also empower and mentor newcomers, fostering a community where learning and participation in the bitcoin ecosystem are highly encouraged.

 

Empowering a Decentralized World with Bitcoin Mining: Championing Financial Freedom, Choice, and Innovation, One Block at a Time.

 

BitcoinMining.zone

@2023 – All Right Reserved. BitcoinMining.zone

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More