paint-brush
Deconstructing a confirmed bitcoin transactionby@prahaladbelavadi
6,814 reads
6,814 reads

Deconstructing a confirmed bitcoin transaction

by Prahalad BelavadiMarch 27th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

This article talks about what goes into a bitcoin transaction.&nbsp;<br>I might not be exactly right, but this is based off of tinkering with the <a href="https://github.com/bitcoinjs/bitcoinjs-lib/" target="_blank">bitcoinjs library</a>. Feel free to correct me if I’m wrong.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Deconstructing a confirmed bitcoin transaction
Prahalad Belavadi HackerNoon profile picture


This article talks about what goes into a bitcoin transaction. I might not be exactly right, but this is based off of tinkering with the bitcoinjs library. Feel free to correct me if I’m wrong.


The repository I’ve used for testing is available here. Use this release if you’re trying out stuff from this article.

I’m just logging out stuff that I think can explain something more about how the system works. Not much of a difference from the actual bitcoinjs-lib, but for all production cases use the bitcoinjs-lib repo and that too only stable releases since master branch is used for development.

A list of unconfirmed transactions available in Blockchain.info’s mempool can be viewed here. There are newer and more transactions added each second.

For all purposes of this article,unless otherwise mentioned, we shall examine this transaction.

The agenda for this article is to walk you through the process of verifying the presence of the transaction in the block, contents of the transaction and then creating a similar transaction.

Prerequisites:



$ git clone github.com/prahaladbelavadi/bitcoin-js-testing$ cd ./bitcoin-js-testing$ npm install

  • Navigate into the blocks directory here and run the following command


$ cd ./myTest/blocks$ node blocks.js

It logs out the transaction in its hex format, the input script and the block’s height. Unconfirmed transactions do not have a block height since they haven’t been included in a block (yet).

In the hex format of block 498303, we can confirm that the transaction exists.

Block 498303 in Hex

We shall dissect this transaction.

Transaction Hex: 010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff50037f9a07174d696e656420627920416e74506f6f6c685b205a2b1f7bfabe6d6d36afe1910eca9405b66f97750940a656e38e2c0312958190ff8e98fd16761d220400000000000000aa340000d49f0000ffffffff02b07fc366000000001976a9148349212dc27ce3ab4c5b29b85c4dec643d764b1788ac0000000000000000266a24aa21a9ed72d9432948505e3d3062f1307a3f027a5dea846ff85e47159680919c12bf1e400120000000000000000000000000000000000000000000000000000000000000000000000000

We shall use Blockcypher to decode the transaction.

Take the transaction hex and paste into the decoder.

Coinbase Transaction decoder

The transaction decoder shows that the transaction hex that was relayed to the network contained the following:

  • Transaction input Script in Hex
  • Output address
  • Output script and type

PS: This does not contain an input address since it is a coinbase transaction.

If we take a look at this decoded transaction from block 498303

Valid spend transaction decoded

We can see that it has a previous input address linked to the transaction hash of the previous recorded transaction on the blockchain.

Each output needs to have a corresponding input and its signature to prove that it can indeed spend the bitcoin, unless its a coinbase transaction.

Each explorer displays and keeps track of metrics in its own different way based on their local node or whatever they choose to track.

Random bitcoin transaction decoded on blockchain.info decoder

We can observe in blockchain.info’s decoder, it shows different operations being performed on it as well.

In upcoming articles, I intend to show how to compose your own transactions and relay it to the network.

Since I’ll constantly be trying out new stuff on my fork of bitcoinjs-testing repository and that could conflict with your experimenting, I packaged a release for the sole purpose of this article.

It is available here. It shall contain code at the time of publishing this article.

Feel Free to fork, play around and try out new stuff with it.

References:

Cheers!