How Does a Typical Bitcoin Transaction (P2P) Work?

 

A typical BTC transaction is one between two people or addresses (Peer to Peer). In this example developed in the testnet, we will send funds from:

  • Address: mhWmofYSHLdwvkA3Y51eARqZM1z9YcCS1C

  • To address: n3PUm39rx8SwgFqLmRpKQvCdw997eF7iTp

As a first step, the shipping address must be funded, you can see it in your BTC wallet or consult a BTC blockchain browser (a kind of blockchain browser) on your computer or mobile:

This is equivalent to the BTC protocol querying or requesting the status of the mhWmofYSHLdwvkA3Y51eARqZM1z9YcCS1C address on the BTC testnet blockchain.

The response is the information from that address in JSON format. From the last hashed transaction:

e4a5829dd872187a06d4eaf5e495cc53b51de6ae16fd1f53cf42856661bd270f

In the image below, line 24 indicates that it has a value of 10,000 microBTC.

 

UTXO funds available from a BTC address

Next, the BTC protocol makes a request to the blockchain to structure a JSON called UTXO (Unspent transaction output). This utxo indicates the funds available to be spent by that address or account.

The blockchain returns the utxo in Hexadecimal code.

 

How to build a raw BTC transaction

In the image below we find that:

  • With the utxo information the Input or entrance is constituted.

  • There are two outputs, one output is to whom the funds are destined and the other to return the change if the amount to be sent is less than the Input.

  • In line 40 the transaction is signed with the private key.

  • In line 44, the raw transaction is requested to be returned in hexadecimal code.

Once the previous software is executed, we obtain the raw transaction in hexadecimal format:

 

How a transaction is included in the BTC blockchain

The BTC protocol proceeds to send the raw transaction (in the image below assigned to the variable tx, in the pushtx JSON) from your wallet or computer, pushing the tx to the blockchain located on the full BTC nodes.

Now we have the transaction processed and in JSON format, which returns the BTC protocol to our computer from the blockchain of the node that processed it:

Finally, you can check the balance of the address or account of the recipient of the funds, in the wallet or in the BTC blockchain browser on your mobile or computer.

 
Carlos Sampson