top of page

BTC Blockchain Transactions

Transacting on the BitCoin Blockchain consists of executing two scripts that are concatenated together.

Traditionally, the scripts are referred to as ScriptSig and ScriptPubKey.

The scripting language is specific to BitCoin;  It is a stack based language that is comprised of a relatively small set of instructions, but those instructions include support for cryptographic functions such as key generation and signature verification.  

The total value of the inputs is always consumed in a transaction.  If there is an amount of value that is desired to be returned to the original owner of an input, there should be an output added to ScriptPubKey to return the unspent output.

This page has an intermediate level explanation of a transaction, including an example of what the stack looks like as operations are pushed and popped.   https://en.bitcoin.it/wiki/Transaction

As a matter of illustration, the following shows an example of writing arbitrary data into the BitCoin Blockchain. 

In this example, we run the bitcoin core daemon and execute the commands from the command line.  

We execute the following steps:

1.) Check the unspent outputs from a valid address to which we rightfully have the keys to sign

2.) Define a message to be written to the BTC Blockchain;  Convert the message from Ascii to Hexadecimal

3.) Create a transaction by specifying our valid input address in ScriptSig and our Hexadecimal message in ScriptPubKey;  additionally add a return address to ScriptPubKey, specifying the value that should be returned to this address.

4.) Sign the entire transaction

5.) Broadcast the transaction

6.) Wait for about an hour.  The hour allows for ~6 blocks to be confirmed which is generally considered adequate for a transaction to be permanently part of the blockchain.

7.) Use the transaction ID to view the immutable transaction which is now forever in the BitCoin BlockChain!

The above is the English explanation of the process.  Below are the commands as executed from the command line, along with the responses generated by either the shell or the Bitcoin Core Daemon.  The commands as typed on the command line are given in Bold, the response that is echo'd back to the terminal is given Purple.  The Red arrows and comments are inserted manually in attempt to make the illustration as clear as possible.

1.) Check Unspent Outputs of a prior transaction, using a wallet address as the input.

 bitcoin-cli listunspent 0 999999 '["3DrqMYC6hTyT54pSJdsZJTkAhhPWixMkgZ"]'
[
 
{
   "txid": "b95e4844b462a4bd7d653132e511c769a13238b2245657f7062b23955a8c0684",
   "vout": 0,
   "address": "3DrqMYC6hTyT54pSJdsZJTkAhhPWixMkgZ",

    "label": "Send to Normal Address instead of Bech32",
   "redeemScript": "0014dfb8c89344de200fa13f3c0cc311ef16f986f990",
   "scriptPubKey": "a914857cd8af0a7d62608d52b105b3ae0eac3a089a0e87",
   "amount": 0.00128330,
   "confirmations": 409,
   "spendable": true,
   "solvable": true,
   "safe": true

}
  

2.) Define a message to be written to the Blockchain;  Convert the message from Ascii to Hexadecimal

     echo "Building Blocks Technologies Says HELLO to the World..." | xxd -ps -c 200

4275696c64696e6720426c6f636b7320546563686e6f6c6f6769657320536179732048454c4c4f20746f2074686520576f726c642e2e2e0a

3.) Create a transaction

     bitcoin-cli createrawtransaction '[{"txid":"b95e4844b462a4bd7d653132e511c769a13238b2245657f7062b23955a8c0684", "vout":0}]'               '{"data":"4275696c64696e6720426c6f636b7320546563686e6f6c6f6769657320536179732048454c4c4f20746f2074686520576f726c642e2e2e0a",              "3DrqMYC6hTyT54pSJdsZJTkAhhPWixMkgZ":0.0010833}'

    In the above command, we have the following:

    txid --> The transaction ID that was returned from the listunspent command

    vout --> Output Number, also from the listunspent command

    data --> Hexadecimal representation of our message,

                  "Change address" where the change from the transaction will be returned.  In this case .00128330 - .0002, which is the original amount of the unspent output minus the transaction fee, where the transaction fee was chosen as .0002 by currently accepted convention.

And, this is the response:

020000000184068c5a95232b06f7575624b23832a169c711e53231657dbda462b444485eb90000000000ffffffff0200000000000000003a6a384275696c64696e6720426c6f636b7320546563686e6f6c6f6769657320536179732048454c4c4f20746f2074686520576f726c642e2e2e0a2aa701000000000017a914857cd8af0a7d62608d52b105b3ae0eac3a089a0e8700000000
 

4.) Sign the entire transaction

bitcoin-cli signrawtransaction "020000000184068c5a95232b06f7575624b23832a169c711e53231657dbda462b444485eb90000000000ffffffff0200000000000000003a6a384275696c64696e6720426c6f636b7320546563686e6f6c6f6769657320536179732048454c4c4f20746f2074686520576f726c642e2e2e0a2aa701000000000017a914857cd8af0a7d62608d52b105b3ae0eac3a089a0e8700000000"

 

In the above, the big string in quotes is the hexadecimal output that was generated from the createtransaction step above.

 

And, this is the response:

{
  "hex": "0200000000010184068c5a95232b06f7575624b23832a169c711e53231657dbda462b444485eb90000000017160014dfb8c89344de200fa13f3c0cc311ef16f986f990ffffffff0200000000000000003a6a384275696c64696e6720426c6f636b7320546563686e6f6c6f6769657320536179732048454c4c4f20746f2074686520576f726c642e2e2e0a2aa701000000000017a914857cd8af0a7d62608d52b105b3ae0eac3a089a0e87024730440220125e788d606bf64b5f1b59411bd51677ac56164be7a4c6b0213e47b4c42a92280220165fdf39f39bd80c6db7c974efc6834274238327b2095c8822e2fd04919974880121032c5fa0704eee8301cfbbac03b85528f47f72ddedcbf775e99950708beaa9a25300000000",
  "complete": true
}

 

5.) Broadcast the Transaction

bitcoin-cli sendrawtransaction "0200000000010184068c5a95232b06f7575624b23832a169c711e53231657dbda462b444485eb90000000017160014dfb8c89344de200fa13f3c0cc311ef16f986f990ffffffff0200000000000000003a6a384275696c64696e6720426c6f636b7320546563686e6f6c6f6769657320536179732048454c4c4f20746f2074686520576f726c642e2e2e0a2aa701000000000017a914857cd8af0a7d62608d52b105b3ae0eac3a089a0e87024730440220125e788d606bf64b5f1b59411bd51677ac56164be7a4c6b0213e47b4c42a92280220165fdf39f39bd80c6db7c974efc6834274238327b2095c8822e2fd04919974880121032c5fa0704eee8301cfbbac03b85528f47f72ddedcbf775e99950708beaa9a25300000000"
 

In the above, the big string in quotes is the hexadecimal output that was generated from the signtransaction step above.

And the result is a transaction ID:

75cfab263a0412eaecee4f64509520e0f693af1442531d30e2fc7a43f2df818c

 

6.) Wait for about an hour.  Go have a cup O joe!

 

7.) Check the transaction which has now been recorded into perpetuity on the BitCoin BlockChain!


bitcoin-cli gettransaction 75cfab263a0412eaecee4f64509520e0f693af1442531d30e2fc7a43f2df818c

 

The following is the result with some of the fields that can be traced back to the work above bolded.

Below this output, the hex data field is converted to Ascii and the message that we wrote into the Bitcoin Blockchain will be Human Readable!


{
  "amount": 0.00000000,
  "fee": -0.00020000,
  "confirmations": 437,
  "blockhash": "00000000000000000012f6350353702518832f3535c9c4a6a66f491c4bd8038c",
  "blockindex": 75,
  "blocktime": 1571422368,
  "txid": "75cfab263a0412eaecee4f64509520e0f693af1442531d30e2fc7a43f2df818c",
  "walletconflicts": [
  ],
  "time": 1571422167,
  "timereceived": 1571422167,
  "bip125-replaceable": "no",
  "details": [
    {
      "category": "send",
      "amount": 0.00000000,
      "vout": 0,
      "fee": -0.00020000,
      "abandoned": false
    },
    {
      "address": "3DrqMYC6hTyT54pSJdsZJTkAhhPWixMkgZ",
      "category": "send",
      "amount": -0.00108330,
      "label": "Send to Normal Address instead of Bech32",
      "vout": 1,
      "fee": -0.00020000,
      "abandoned": false
    },
    {
      "address": "3DrqMYC6hTyT54pSJdsZJTkAhhPWixMkgZ",
      "category": "receive",
      "amount": 0.00108330,

      "label": "Send to Normal Address instead of Bech32",
      "vout": 1
    }
  ],
  "hex": "0200000000010184068c5a95232b06f7575624b23832a169c711e53231657dbda462b444485eb90000000017160014dfb8c89344de200fa13f3c0cc311ef16f986f990ffffffff0200000000000000003a6a384275696c64696e6720426c6f636b7320546563686e6f6c6f6769657320536179732048454c4c4f20746f2074686520576f726c642e2e2e0a2aa701000000000017a914857cd8af0a7d62608d52b105b3ae0eac3a089a0e87024730440220125e788d606bf64b5f1b59411bd51677ac56164be7a4c6b0213e47b4c42a92280220165fdf39f39bd80c6db7c974efc6834274238327b2095c8822e2fd04919974880121032c5fa0704eee8301cfbbac03b85528f47f72ddedcbf775e99950708beaa9a25300000000"
}

 

LASTLY, Let's convert the Hex Data field into Ascii and see our Message to the world, which is now recorded into perpetuity!

echo "0200000000010184068c5a95232b06f7575624b23832a169c711e53231657dbda462b444485eb90000000017160014dfb8c89344de200fa13f3c0cc311ef16f986f990ffffffff0200000000000000003a6a384275696c64696e6720426c6f636b7320546563686e6f6c6f6769657320536179732048454c4c4f20746f2074686520576f726c642e2e2e0a2aa701000000000017a914857cd8af0a7d62608d52b105b3ae0eac3a089a0e87024730440220125e788d606bf64b5f1b59411bd51677ac56164be7a4c6b0213e47b4c42a92280220165fdf39f39bd80c6db7c974efc6834274238327b2095c8822e2fd04919974880121032c5fa0704eee8301cfbbac03b85528f47f72ddedcbf775e99950708beaa9a25300000000" |  xxd -ps -r
��Z�#+�WV$�82�i��21e}��b�DH^�߸ȓD� �?<
                                              ����������:j8B
uilding Blocks Technologies Says HELLO to the World...
*���|د
}b`�R������G0D ^x�`k�K_YA�w�VK��ư!>G��*�( _�9���
                                                         m��t�ƃBt#�'�    \�"����t�!,_�pN��ϻ��U(�r����u��Pp�ꩢS

 

bottom of page