In this article, we will talk about what happened to a transaction from the beginning of its creation until it was successfully added to the block and eventually became part of the blockchain.
Suppose you create a transaction in your wallet. Let’s say you want to send 1btc to your friend’s wallet. What you normally do - no matter which wallet you have - is to enter your friend’s wallet address, determine what amount of BTC you want to send, and at least, click on the send button and after a few, your friend will receive the transferred amount of BTC.
It seems we are done.
But the question is what happened in the background?
To answer this question, get back to the last step. After the send button was clicked and a transaction was created, first, your wallet validates the transaction, then broadcasts it to the Bitcoin Network and finally, it goes into a Mempool (short for Memory Pool).
In the next step, a Miner selects some transactions from the Mempool, including your transaction.
The transaction is validated one more time. This validation is for checking your signature to be correct and avoid performing a double-spend. After all this validation process, the miner gathering the transactions into a block.
In the next step, the miner starts to hash the created block via the SHA-256 algorithm, which is used for bitcoin blockchain and tries to solve the “puzzle”.
Once the puzzle is solved, the block will be added to the chain, after often 6 confirmation from other participants in the network, and the miner receives his/her respective reward. otherwise, the miner attempts to hash the block again and again until finds the right hash and adds the transaction to the blockchain.
After all the above steps, 1btc will be transferred from your wallet to your friend's wallet.
Summery
1- A transaction is created
2- The transaction broadcast to the Bitcoin Network and added to a Mempool
3- A miner pick some transaction among the Mempool’s transactions and built up a block with them
4- The miner starts to hash the block and try to solve the puzzle
5- Whenever the puzzle solved, the block will be added to the blockchain and the created transaction will be completely done
