## A digital currency

From Wikipedia, the free encyclopedia
Bitcoin is a cryptocurrency and a digital payment system invented by an unknown programmer, or a group of programmers, under the name Satoshi Nakamoto.It was released as open-source software in 2009.
The system is peer-to-peer, and transactions take place between users directly, without an intermediary.These transactions are verified by network nodes and recorded in a public distributed ledger called a blockchain. Since the system works without a central repository or single administrator, bitcoin is called the first decentralized digital currency.

## WALLET

You can install a software on your computer or your phone to manage your bitcoins.
As Bitcoin is open source, there is a lot of such software avalaible.
It's called a wallet.
Those softwares are all talking with the same protocol. They are connected to the same network.
But, in fact, your true wallet is your 2 crypt keys : the public and the private one.
Everybody who knows those 2 values can spend your bitcoins.

## Transaction

When Bob is sending 42 to Alice, the bitcoin protocol is creating a transaction.
A transaction is the balance between his Inputs and his Outputs.

- First the network needs to be sure that Bob has got enough in his wallet.
  So Bob will include a list of transactions that he has received before.
  This is the inputs of the transactions.
  For example, previous transaction's amount are 10, 25 and another 10, so total inputs are 45
- As the input's sum is superior to the amount of the transaction, an ouput is added.
  This output is the change to Bob.
  In the example, this 3
- Fees are took by the network to process the transaction.
  Let say it will take 0.5.
  This is another ouput
- So Alice will get only a part of the transaction's amount.
  this the last output, 41.5

So the transaction is a made with :

- Inputs : a list of previous transactions that bob has received
- Outputs : a list of amounts to send to Alice, Bob, and fees
- A timestamp

Then the wallet will broadcast the transaction on the network.
It will be sent to the area called "mempool".
Nodes of the network will validate the transaction by verfying the Inputs and the Ouputs.
A hash of the transaction is computed.
So the transaction is sealed.

## Block

Then the bitcoin protocol is grouping validated transactions in blocks.
So a block is an array of transactions.
A block is made with :

- An array of transactions.
  That's what my script is drawing.
  Running the transactions array, it is computing the sum of each outputs of each transaction.
  Then, it draws a rectangle for each sum.
- A "proof of work".
  The miner is computing a special hash that depends on the array of transaction and that will answer to a constraint.
  This hash is very difficult to compute. In fact it is not really computed, the miner must test every value until he find the solution.
  That why the network will give him a reward.
  This reward is a special transaction that has no inputs.
  As this reward is in bitcoin, this is also a mean to control the money stock.
  The more you use the money, the more there is blocks, the more there is money.

## Blockchain

Each block has a hash and a reference to the ihash of the previous block.
So blocks are chained together.