What is bitcoin

When we talk about bitcoin, it actually means different things in different contexts.

Bitcoin is first and foremost a digital cryptocurrency that allows users to transfer bitcoin or settle goods over the Bitcoin network, just like traditional money:

But bitcoin is a cryptographic-based virtual currency that has no entity and is only implicit in transactions from sender to receiver, who must use the key they hold to spend the coins they receive.

Bitcoin represents an epoch-making digital cryptocurrency system, including communication protocols, incentive mechanisms, implementation codes and host networks.

In fact, bitcoin is the culmination of decades of cryptography, distributed computing and other fields. It is not the first digital currency to emerge, but it is undoubtedly the most successful, a virtual product that offers insights into human nature.

Blockchain structure

Bitcoin is a dedicated database that only keeps records of one type of data — transactions, such as three to Four coins, or four to five coins:

When it comes to money, everyone is cautious. Therefore, the transaction records should be technically guaranteed not to be tampered with, so that problems can be turned over the old accounts, which requires that the books must be trustworthy.

Bitcoin uses a special data structure, the Blockchain, to ensure the imtamability of transactions. Each block contains a batch of transaction data, but also contains the fingerprint of the previous block:

In Bitcoin, the fingerprint of a block is implemented using hash functions common in cryptography. A hash function can compress a large chunk of data into a simplified representation and ensure that if the simplified representation is different, the original data is also different.

12 # block is in the diagram above, for example, if an attacker tampered with, then it will is different from the result of the hash of the 13 # block stored in its original fingerprint, which makes the recognition of tampering with block this task is very easy, or said tampering with difficulty, the attacker must change at the same time to ensure that all of the blocks after 12 # fingerprint verification success.

On the other hand, if an attacker were to tamper with block 14# directly (we assume this is the last block), it would obviously be feasible, since it would lack the protection of subsequent blocks. This introduces a concept often used in Bitcoin: confirmation of transactions /Confirms of transactions.

Once a transaction is confirmed and packaged into a block, its confirmation count is 1, and then it increases by 1 for each additional block. For example, in the case of the labeled transaction shown above, the number of confirmations for the transaction is 3 as the chain grows to 14# blocks.

Obviously, the more confirmations a transaction has, the less likely an attacker is to tamper with the transaction. In bitcoin applications, the recipient of a transaction typically needs six confirmations before the transaction can be considered successful.

Decentralization mechanism

Unlike any fiat currency currently in circulation, Bitcoin is decentralized and there is no central authority to manage the issuance and circulation of Bitcoin, so the Bitcoin network is a typical P2P network with complete blockchain data on each (full) node:

In such a distributed computing environment, how to ensure the consistent update of new transactions in each node blockchain is a classic distributed consistency problem — each node may submit a new transaction, and the transaction submitted by different nodes may be different, which node shall prevail?

The classic way to solve this problem is to (dynamically) elect a decision maker, and other nodes copy the decision maker’s behavior to avoid inconsistencies between nodes. COINS of solution, too, but it takes a similar to the mechanism of vies to answer first wins to dynamically select nodes, the winning node is responsible for the block and package deal – all nodes are solving the same problem at the same time, the first to get the results node and get a winning piece of rights, the other nodes is to solve the next piece of the problem:

The problem given by bitcoin cannot be solved by analytical method, and nodes must try to solve it violently among all possible results. Since the winning node can get bitcoin reward, the motivation and behavior of nodes are quite similar to cowboy gold panning, so this solving process is called Mining /Mining.

Theoretically, each node has a chance of winning, but it’s clear that the computationally powerful node will make more attempts than the others in the same amount of time, and therefore have a greater chance of winning — in this first-answer mechanism, computation replaces intelligence, The consensus algorithm that relies on violence to solve problems to achieve node consistency is called Proof Of Work.

Course content

This course is suitable for PHP engineers who want to develop bitcoin applications. It covers the basic concepts of Bitcoin, working principles, application development interface, offline key management, hierarchical deterministic wallet, naked transaction and many key knowledge points.

Chapter 1 Overview of Bitcoin

This paper mainly introduces the basic concept and core working principle of Bitcoin.

Chapter 2 Hi, Bitcoin

This chapter mainly introduces how to use existing software for bitcoin operations, such as address creation, transfer, balance query, block browsing, etc. At the same time, it introduces the core concepts of Bitcoin applications, such as wallet, transaction, UTXO, etc.

Chapter 3 Using RPC to access the Bitcoin network

This chapter mainly introduces how to use RPC API interface of node software in the program code to access bitcoin network, conduct transfer, address creation, balance query and other operations, and gives a simple scheme to support bitcoin payment in the website.

Chapter 4 Manage key and address by oneself

This chapter focuses on how to manage keys and addresses offline, and details the script in Bitcoin and its relationship to addresses and authentication. If you want to add a wallet-like feature to your app, this section will pay off.

Chapter five uses layered deterministic wallets

This chapter introduces the widely used hierarchical deterministic wallet and explains how to apply it in program code. Layered deterministic wallets should be helpful if you need to manage a large number of keys and addresses.

Chapter 6: Off-line construction of naked trading

This chapter focuses on what naked trading does and how to create it in program code. If you need to use third-party nodes to broadcast your Bitcoin transactions, naked transactions are your only option.

PHP Bitcoin development tutorial