Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
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:
- Install Nodejs, Git Bash and any text editorĀ (Atom)
- Clone this repository
- Change directory and installĀ packages
$ 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.
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!
Deconstructing a confirmed bitcoin transaction was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.