Teach you to create a blockchain starting from 0 in Python


The " three o'clock blockchain " has undoubtedly become the source of anxiety for everyone during the Spring Festival, and the "blockchain" is destined to be an industry-focused hot topic that will continue to be discussed and followed in 2018.

On March 1st, Zhu Xiaohu fired again at the tumbling blockchain boom. In a circle of friends drawing a full blockchain application, Zhu Xiaohu questioned: How many live users are all these applications added together? "The Internet bubble in 2000 at least had an eyeball. What else does the blockchain today have in addition to speculation?"

Prior to this, Zhu Xiaohu passed an article on satirical blockchain investment fever in a circle of friends. He came to drink the chicken chicken soup in this blockchain chain! "" and stated: "Do not pull me into any group of 3 o'clock, some fans would rather miss, some money would rather not earn, we take care of the evening." Zhu Xiaohu also said that ICO is a Ponzi scheme is insulting the Ponzi scheme.

As a programmer you do not understand this technology, 2018 may be eliminated! Let's start the blockchain with ten pieces of humor from the bottom of the block!

01 Laughing spray! Ten blockchain sub-collections

1. If you are a woman, every time your boyfriend talks to you with a nauseating word or promises to buy something for you, you're going to burn it and send it to you and all his girlfriends, classmates, colleagues, and various Group and friends circle, so that he can no longer be denied, this is called the blockchain.

2. Mahjong is a traditional blockchain project in China: A group of four miners who first collided with a 13-digit correct hash value could obtain the right to book and be rewarded. Can not be tampered with. Because convincing the other three people consumes too much hard power and physical strength.

3. There are several similarities between the young lady who plays the nightclub and the little brother who plays the virtual currency:

They are all smart people

It's all silly to be making money.

I know a lot of big brothers

I understand a lot of truth

Are waiting for their own price increases or their own virtual currency prices have been accepted by others

4, blockchain is a serious technology, various currencies are not seriously do not know.

5. Wu Sangui’s anger at Shanhaiguan's rushing crown is essentially to compete for the power to sleep and round. The big brothers' mutual ambivalence on the block link is essentially to compete for power to cut the leeks.

6. At the beginning of the new semester, my son asked Dad, “What should I do to fill my dad's work column? Is it a currency?” Dad hesitated and said, “Write a list of listed company shareholders.”

7, recent digital currency is very hot, many cottage coins are several times the growth of several times. A lot of speculation began to sway, and clamored for "one coin, one tender mold." A friend asked me if I wanted to follow? My point of view is very simple: The gold rush, gold rushes, risk is great. So, let them call "a coin and a tender mold". Let's not follow the blind speculation. We should earn their money - to be a tender model! When the tender mode! Tender mode!

8. I met a coin friend yesterday and asked him: "What happened to the recent drop in the currency market and the quality of sleep?"

He said: "Okay, sleeping like a baby!"

I said, "Envious."

He said: "I slept for an hour, woke up, then we cried for an hour, then we slept for another hour and we cried for another hour."

9. The old LGBT earnestly said to 80 and 90: "Don't play those bitcoins, those virtual gadgets, and do some practical things in Beijing to buy a house and take a wife. How nice!" After 90, he replied: "You all Thousands of thousands of dollars in the cost of the house to 10 million square meters. We do not find another way out, to do a string of 100,000 numbers sold to you, what we can afford to buy a house ah?"

10. First of all, I would like to thank the company for taking out 1 million bitcoins as a reward for employees. Secondly, I feel very lucky that I can get this 950,000 reward. Then I think I still have to plan the use of 860,000. After all, 700,000 is not a small sum of money. I intend to give 200,000 to my parents. The remaining 360,000 people have not yet thought about how to use it. In short, I would like to thank the company for a reward of 300,000 bitcoins. Thank you, I wish everyone the same. Can get this 150,000 reward.

02 Graphic: Knowing the blockchain is a trick?

1. what is blockchain

"Blockchain is just a technology," and "Bitcoin" is just an application of blockchain technology. It's like, a person can use the technology of cooking, but he can use his cooking skills to make " Kung-pao chicken, fish-flavored pork, and other dishes.

So, what exactly is "blockchain"? Here we use a more popular piece of the Internet to show it in graphic form to everyone.

We can abstract “Bitcoin” into “Photos of a Rong” as shown above. If many users on the Internet want to get a photo of Rong, they need to search on a fixed website.

Of course, you have no other place to go, so well, this certain website will pop up every day to you, ah, small window, you have to endure, no way, because this place can get it.

Moreover, this website was suddenly blocked by the police uncle? Or power off? Disconnected? Whatever he is, anyway, the server crashes, and then the 2,100 photos that the tragedy fans of “Ao Rong” loved will all lose their place to provide resources.

This is the "centralization" of the new word circulating on the Internet. His drawbacks are that resources are concentrated and the risk resistance and fault tolerance are weak. Resources are easily lost.

So, how to solve this problem? Let's imagine, can we allow each "Rong" fan to own the 2100 photos? For example:

In this case, it looks like you don't need to rely on that "Pomegranate" website. Even if a certain fan suddenly crashes, he just finds another fan to get the 2100 photos. It's no time.

Later, an avatar named "Some Satoshi" provided a photo sharing folder with an agreement that the user can obtain photos from, but must follow the agreement.

In this way, each fan can get the 2100 photos of Zhang Mourong from this folder, but all the fans he has to follow must follow an agreement, which is of course an agreement defined by someone.

"You can't copy, modify, or share any of the photos in your document. Fans will record any activity in the shared folder and record it according to time!"

Fans love a certain rong so much, and do not need to go for a certain durian to obtain, of course, have joined enthusiastically already ~

Suddenly, one day, the naughty Little One wants to go against the rules and delete the photo with a number between 1 and 100 at 12 noon on January 15, 2018.

According to the agreement, this behavior will be recorded and broadcast to other fans.

Was the photo deleted? Of course not, because Xiao Lu has photos in her hand. She can immediately restore the deleted photos in the shared folder after receiving the broadcast. Little One never tries to modify the shared folder, and all actions are recorded simultaneously. On other users' computers.

This is blockchain, data storage, decentralization. Broadcast all the behaviors by time stamp, unable to modify, destroy the data source or counterfeit.

Unless one million users' computers are blown up at the same time, or if the Internet disappears or the world is destroyed... otherwise the data will always exist ~~

How to increase the resources of blockchain protection? "A certain cong" came again. He said that you can add a photo of Rong in the document, but do you all have to achieve some "consensus"? The "consensus" is the rule that we all recognize.

Is that a consensus? Ah, Little One and Xiaolu immediately understood the meaning of a certain Satoshi. In the time specified each year, as soon as possible, 100 photos of Miki Miki were taken, so that they could be added to the "A Mori Shared Folder". Our resources It was expanded.

However, the good times are not long. A certain Satoshi found a large number of photographs, before the impact of 100, that will be achieved soon, there will be no difficulty in taking pictures.

Moreover, the quality of the photos is still poor, as if anyone can easily add photo resources, so as not to guarantee the quality of a certain Rong photo. As a result, a certain Satoshi came again and increased the difficulty of taking pictures.

Little One and Xiao Lu as loyal fans, how can we give up, they bought a high-end camera, let a Rong pose in various positions, spend a lot of time and sweat to complete high-quality photos, of course, their own very hard.

This high-quality photo can be added to the folder of a certain Rong.

2. What is ICO?

Little One thinks: Each photo is not falsifiable, so it has uniqueness. There is a separate number. Each photo is valued. Is it not worth the money? Just like the famous paintings that cannot be copied in the real world!

Little One constructed the corresponding “Yong Rong Coin” of the previous Rong photo, of course, this behavior is similar to our government's issue of the equivalent RMB via the state treasury's gold amount.

The valuation, of course, is what Little One said. People are the owners of the photos.

In order to prove that there is a 5W block in one of the Rongco coins, the Little One first purchased 1,100 of the 2,100, and the rest was distributed to the melons. We have already bought one at 5W, indicating that he has already paid the price, leaving 1,000. Let's buy it together.

In this case, if 2,100 of them are fully subscribed, 2,100 of them can have a valuation of 105 million pieces. This process of financing through digital currency is ICO.

According to the meaning of this chart, if Little One and Xiaolu are trustworthy institutions or public figures, they can still trust them. Of course, there will be many criminals who maliciously issue currency to cash out.

This is also the reason why our country prohibits the issuance of ICOs because there is no sound ICO regulation that can guarantee the trustworthiness of institutions that issue currency and regulate them legally. Therefore, people who eat melons must take risks themselves and find a credible one. Institutions.

In this way, 2,100 Rong coins were fully subscribed and the fund was established. This is ICO. Of course, people who eat melons can continue to take pictures to create a certain currency, which is a bit difficult.

Now that you understand what a blockchain and ICO are, here's how to create a blockchain in the Python language.

03 Creating a blockchain starting from 0 in Python

We are new to the rise of digital currency and want to know the technology behind it - how blockchains are implemented. This article builds a blockchain through Python to deepen the understanding of the blockchain.

1. Preparation

This article requires readers to have a basic understanding of Python, can read and write basic Python, and need to have a basic understanding of HTTP requests.

We know that the blockchain is an immutable, ordered chain structure made up of records of blocks. Records can be transactions, files, or any data you want. It is important that they are linked by hashes. of.

If you don't know much about hashing yet, check out this article https://learncryptography.com/hash-functions/what-are-hash-functions.

(1) Environmental preparation:

Prepare the environment and ensure that Python 3.6+, pip, Flask, and requests are installed.

(2) Installation method:

Pip install Flask==0.12.2 requests==2.18.4

You also need an HTTP client, such as Postman, cURL, or other clients.

Reference source code (the original code could not be run during my translation, I forked one, fixed the bug, and added translations, thanks to star).

2. Start to create Blockchain

Create a new file blockchain.py, all of the code in this article is written in this file, you can refer to the source code at any time.

(1) Blockchain class

First create a Blockchain class and create two lists in the constructor, one for storing blockchains and one for storing transactions.

The following is the framework of the Blockchain class:

Class Blockchain ( object ): def __init__ ( self ) : self .chain = [] self .current_transactions = [] def new_block ( self ) : # Creates a new Block and adds it to the chain pass def new_transaction ( self ) : # Adds a new transaction to the list of transactions pass @staticmethod def hash (block) : # Hashes a Block pass @property def last_block ( self ) : # Returns the last Block in the chain pass

The Blockchain class is used to manage the chain, it can store transactions, add new blocks, etc. Let's further refine these methods.

(2) Block structure

Each block contains attributes: index, Unix timestamp, transactions, workload proof (explained later), and the hash value of the previous block.

The following is the structure of a block:

Block = { 'index' : 1, 'timestamp' : 1506057125.900785, 'transactions' : [ { 'sender' : "8527147fe1f5426f9dd545de4b27ee00" , 'recipient' : "a77f5cdfa2934df3954a5c7c7da5df1f" , 'amount' : 5, } ], 'proof' : 324984774000, 'previous_hash' : "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824" }

The concept of blockchain is clear here. Each new block contains the Hash of the previous block. This is the key point. It guarantees the immutability of the blockchain.

If an attacker destroys a previous block, the Hash of all subsequent blocks will become incorrect. If you don't understand it, slowly digest it. You can refer to {% post_link whatbc Blockchain Technology Principles}.

(3) Join the transaction

Next we need to add a transaction to perfect the next new_transaction method:

Class Blockchain (object) : ... def new_transaction (self, sender, recipient, amount) : """ Generates new transaction information and the information is added to the next block to be dug :param sender: Address of the Sender :param recipient: Address of the Recipient :param amount: Amount :return: The index of the Block that will hold this transaction """ self.current_transactions.append({ 'sender' : sender, 'recipient' : recipient, 'amount' : amount, }) return self.last_block[ 'index' ] + 1

The method adds a transaction record to the list and returns the index of the block to which the record will be added (the next block to be mined), which is useful when the user submits the transaction.

(4) Create new block

When the Blockchain is instantiated, we need to construct a Genesis block (the first block without the previous block) and add a workload proof to it. Each block requires proof of workload, commonly known as mining, and will continue to be explained later.

To construct the creation block, we also need to perfect the new_block(), new_transaction() and hash() methods:

Import hashlib import json from time import time class Blockchain (object) : def __init__ (self) : self.current_transactions = [] self.chain = [] # Create the genesis block self.new_block(previous_hash= 1 , proof= 100 ) def New_block (self, proof, previous_hash=None) : """ Generate new block :param proof: The proof given by the Proof of Work algorithm :param previous_hash: (Optional) Hash of previous Block :return: New Block """ block = { 'index' : len(self.chain) + 1 , 'timestamp' : time(), 'transactions' : self.current_transactions, 'proof' : proof, 'previous_hash' : previous_hash or self .hash(self.chain[ -1 ]), } # Reset the current list of transactions self.current_transactions = [] self.chain.append(block) return block def new_transaction (self, sender, recipient, amount) : "" " Generate new transaction information, the information will be added to the next block to be excavated: param sender: Address of the Sender :param recipient: Address of the Recipient :param amount: Amount :return: The index of the Block that will hold this transaction """ self.current_transactions.append({ 'sender' : sender, 'recipient' : recipient, 'amount' : amount, }) return self.last_block[ 'index' ] + 1 @property def last_block (self) : return self.chain[ -1 ] @staticmethod def hash (block) : """ SHA-256 hash value of the generated block :param block: Block :return: """ # We must make sure that the Dictionary is Ordered, or we'll have inconsistent hashes block_string = json.dumps(block, sort_keys= True ).encode() return hashlib.sha256(block_string).hexdigest()

Through the above code and comments can have an intuitive understanding of the blockchain, then we look at how the block was dug out.

(5) Understanding Workload Proof

The new block relies on a workload proof algorithm (PoW) to construct. The goal of PoW is to find a number that meets certain conditions. This number is difficult to calculate but easy to verify. This is the core idea of ​​proof of workload.

For ease of understanding, for example:

Assume that the hash value of the product of one integer x times another integer y must end with 0, that is, hash(x * y) = ac23dc...0. Let the variable x = 5, find the value of y?

With Python as follows:

From hashlib import sha256x = 5 y = 0 # y unknown while sha256( f' {x*y} ' .encode()).hexdigest()[ -1 ] != "0" : y += 1 print( f' The solution is y = {y} ' )

The result is: y = 21 because:

Hash(5 * 21) = 1253e9373e...5e3600155e860

In Bitcoin, a workload proof algorithm called Hashcash is used, which is very similar to the above problem in that the miners vie for calculations in order to compete for the right to create a block.

Usually, the calculation difficulty is proportional to the number of specific characters that the target string needs to satisfy. After the miner calculates the result, it will receive a bitcoin reward. Of course, it is very easy to verify this result on the Internet.

(6) Achieve proof of workload

Let's implement a similar PoW algorithm. The rule is to find a number p such that the hash value of the string concatenated with the proof of the previous block starts with 4 zeros.

Import hashlib import json from time import time from uuid import uuid4 class Blockchain (object) : ... def proof_of_work (self, last_proof) : """ Simple proof of work: - Find a p' such that hash(pp') 4 starts with 0 - p is the proof of the previous block, p' is the current proof: param last_proof: :return: """ proof = 0 while self.valid_proof(last_proof, proof) is False : proof += 1 return proof @staticmethod def valid_proof (last_proof, proof) : """ Validation Proof: Whether hash(last_proof, proof) is 4 0 at the beginning? :param last_proof: Previous Proof :param proof: Current Proof :return: True if correct, False if not. """ guess = f' {last_proof}{proof} ' .encode() guess_hash = hashlib.sha256(guess).hexdigest() return guess_hash[: 4 ] == "0000"

The way to measure the complexity of an algorithm is to modify the number of zeros at the beginning. Using 4 zeros for the demonstration, you will find that one more zero will greatly increase the time required to calculate the result.

Now that the Blockchain class is almost complete, use HTTP requests to interact.

2. Blockchain as an API interface

We will use the Python Flask framework, a lightweight web application framework that facilitates mapping web requests to Python functions. Now let's have Blockchain run on Flask Web.

We will create three interfaces:

/transactions/new creates a transaction and adds it to the block

/mine tells the server to mine new blocks

/chain Returns the entire blockchain

(1) Create a node

Our "Flask server" will act as a node in the blockchain network. Let's add some framework code first:

Import hashlib import json from textwrap import dedent from time import time from uuid import uuid4 from flask import Flask class Blockchain (object) : ... # Instantiate our Node app = Flask(__name__) # Generate a globally unique address for this node node_identifier = Str(uuid4()).replace( '-' , '' ) # Instantiate the Blockchain blockchain = Blockchain() @app.route('/mine', methods=['GET']) def mine () : return " We'll mine a new Block" @app.route('/transactions/new', methods=['POST']) def new_transaction () : return "We'll add a new transaction" @app.route('/ Chain', methods=['GET']) def full_chain () : response = { 'chain' : blockchain.chain, 'length' : len(blockchain.chain), } return jsonify(response), 200 if __name__ == '__main__' : app.run(host= '0.0.0.0' , port= 5000 )

Simply explain the above code:

Line 15: Create a node.

Line 18: Create a random name for the node.

Line 21: Example Blockchain class.

Lines 24–26: Create the /mine GET interface.

Lines 28–30: Create the /transactions/new POST interface to send transaction data to the interface.

Lines 32–38: Create the /chain interface and return the entire blockchain.

Lines 40–41: The service is running on port 5000.

(2) Send transactions

The transaction data structure sent to the node is as follows:

{ "sender" : "my address" , "recipient" : "someone else's address" , "amount" : 5 }

There have been methods for adding transactions before, adding transactions based on interfaces is straightforward:

Import hashlib import json from textwrap import dedent from time import time from uuid import uuid4 from flask import Flask, jsonify, request... @app.route('/transactions/new', methods=['POST']) def new_transaction ( ) : values ​​= request.get_json() # Check that the required fields are in the POST'ed data required = [ 'sender' , 'recipient' , 'amount' ] if not all(k in values for k in required): Return 'Missing values' , 400 # Create a new Transaction index = blockchain.new_transaction(values[ 'sender' ], values[ 'recipient' ], values[ 'amount' ]) response = { 'message' : f'Transaction will Be added to Block {index} ' } return jsonify(response), 201

(3) Mining

Mining is the magic of it. It is simple and it does the following three things:

Calculate workload proof PoW.

Grant a miner (own) a coin by adding a transaction.

Construct a new block and add it to the chain.

Import hashlib import json from textwrap import dedent from time import time from uuid import uuid4 from flask import Flask, jsonify, request... import hashlib import json from time import time from uuid import uuid4 from flask import Flask, jsonify, request... @app.route('/mine', methods=['GET']) def mine () : # We run the proof of work algorithm to get the next proof... last_block = blockchain.last_block last_proof = last_block[ 'proof ' ] proof = blockchain.proof_of_work(last_proof) # Give a reward for the node for the proof of work. # The sender is "0" to indicate the newly dug out currency blockchain.new_transaction(sender= "0" , recipient=node_identifier, amount= 1 , ) # Forge the new Block by adding it to the chain block = blockchain.new_block(proof) response = { 'message' : "New Block Forged" , 'index' : block[ 'index' ], 'transactions' : Block[ 'transactions' ], 'proof' : block[ 'proof' ], 'previous_hash' : block[ 'previous_hash' ], } return jsonify(response), 200

Note that the recipient of the transaction is our own server node, and most of the work we do is only interacting around the Blockchain class methods. At this point, even if our blockchain is completed, we can actually run it.

(4) Run blockchain

You can use cURL or Postman to interact with the API.

Start the server:

$ python blockchain.py* Runing on http: //127.0.0.1:5000/ (Press CTRL+C to quit)

Let's do the mining by requesting http://localhost:5000/mine:

Add a new transaction by post request:

If you are not using Postman, the same is true with the following cURL statement:

$ curl -X POST -H "Content-Type: application/json" -d '{ "sender" : "d4ee26eee15148ee92c6cd394edd974e" , "recipient" : "someone-other-address" , "amount" : 5}' "http: //localhost:5000/transactions/new"

After digging the mine twice, there are 3 blocks. All the block information can be obtained by requesting http://localhost:5000/chain.

{ "chain" : [ { "index" : 1 , "previous_hash" : 1 , "proof" : 100 , "timestamp" : 1506280650.770839 , "transactions : [] }, { "index" : 2 , "previous_hash" : "c099bc...bfb7" , "proof" : 35293 , "timestamp" : 1506280664.717925 , "transactions" : [ { "amount" : 1 , "recipient" : "8bbcb347e0634905b0cac7955bae152b" , "sender" : "0" } ] } , { "index" : 3 , "previous_hash" : "eff91a...10f2" , "proof" : 35089 , "timestamp" : 1506280666.1086972 , "transactions" : [ { "amount" : 1 , "recipient" : "8bbcb347e0634905b0cac7955bae152b " , "sender" : "0" } ] } ], "length" : 3 }

3. Consistency (consensus)

We already have a basic blockchain that can accept transactions and mining, but blockchain systems should be distributed.

Since it is distributed, then what exactly do we guarantee that all nodes have the same chain? This is the consistency problem. If we want to have multiple nodes on the network, we must implement a consistent algorithm.

(1) Registration node

Before implementing a consensus algorithm, we need to find a way for a node to know its neighboring nodes.

Each node needs to keep a record of other nodes in the network, so let's add a few more interfaces:

/nodes/register Receives a list of new nodes in the form of URLs.

/nodes/resolve Performs a consistency algorithm that resolves any conflicts and ensures that the nodes have the correct chain.

We modify the blockchain's init function and provide a method for registering nodes:

... from urllib.parse import urlparse... class Blockchain (object) : def __init__ (self) : ... self.nodes = set() ... def register_node (self, address) : """ Add a New node to the list of nodes :param address: Address of node. Eg. 'http://192.168.0.5:5000' :return: None """ parsed_url = urlparse(address) self.nodes.add(parsed_url.netloc)

We use set to store nodes, which is an easy way to avoid duplicate nodes.

(2) Implement consensus algorithm

As mentioned earlier, conflict refers to different nodes having different chains. To solve this problem, the longest and most effective chain is the final chain. In other words, the longest effective chain in the network is the actual chain.

We use the following algorithm to achieve the consensus in the network:

...import requests class Blockchain ( object ) ... def valid_chain ( self , chain) : """ Determine if a given blockchain is valid :param chain: A blockchain :return: True if valid, False if not """ last_block = chain[ 0 ] current_index = 1 while while current_index < len(chain): block = chain[current_index] print(f '{last_block}' ) print(f '{block}' ) print( "-----------" ) # Check that the hash of the block is correct if block[ 'previous_hash' ] != self .hash(last_block): return False # Check that the Proof Of Work is correct if not self .valid_proof(last_block[ 'proof' ], block[ 'proof' ]): return False last_block = block current_index += 1 return True def resolve_conflicts ( self ) : """ The consensus algorithm resolves conflicts using The longest chain in the network. :return: True if the chain is replaced, otherwise False """ neighbours = self .nodes new_chain = None # We're only looking for chains longer than ours max_length = len( self .chain) # Grab and verify the chains from all the nodes in Our network for node in neighbours: response = requests.get(f 'http://{node}/chain' ) if response.status_code == 200 : length = response.json()[ 'length' ] chain = response. Json()[ 'chain' ] # Check if the length is longer and the chain is valid if length > max_length and self .valid_chain(chain): max_length = length new_chain = chain # Replace our chain if we discovered a new, valid chain Longer than ours if new_chain: self .chain = new_chain return True return False

The first method valid_chain() is used to check if it is a valid chain and iterates through each block to verify the hash and proof.

The second method resolve_conflicts() is used to resolve conflicts, iterates over all neighbor nodes, and uses the previous method to check the validity of the chain. If a valid longer chain is found, it replaces its own chain.

Let's add two routes, one to register the node and one to resolve the conflict.

@app.route( '/nodes/register' , methods=[ 'POST' ]) def register_nodes () : values ​​= request.get_json() nodes = values.get( 'nodes' ) if nodes is None: return "Error : Please supply a valid list of nodes" , 400 for node in nodes: blockchain.register_node(node) response = { 'message' : 'New nodes have been added' , 'total_nodes' : list(blockchain.nodes), } return Jsonify(response), 201 @app.route( '/nodes/resolve' , methods=[ 'GET' ]) def consensus () : replaced = blockchain.resolve_conflicts() if replaced: response = { 'message' : 'Our Chain was replaced' , 'new_chain' : blockchain.chain } else: response = { 'message' : 'Our chain is authoritative' , 'chain' : blockchain.chain } return jsonify(response), 200

You can run nodes on different machines, or open different network ports on a machine to simulate a multi-node network.

Here opens a different port demo on the same machine. Running the following commands on different terminals starts two nodes:

Http://localhost:5000

Http://localhost:5001

Pipenv run python blockchain .py pipenv run python blockchain .py -p 5001

Then dig two blocks on node 2 to ensure that it is a longer chain, and then access the interface /nodes/resolve on node 1. At this time, the chain of node 1 will be replaced by the chain of node 2 through the consensus algorithm.

Well, you can invite friends to test your blockchain together.

Privacy Screen Protector

The ultra-thin precision cutting of the Anti-Peep Screen Protector means that you can enjoy a perfect touch screen experience without allowing anything on the screen to be peeped. Whether you place your phone horizontally or vertically, Privacy Screen Protector can protect your personal Information and sensitive information are protected from harm by strangers. People around you cannot see the contents of your phone, so your details are safe.

The use of soft TPU material can really cover the entire screen.

With self-healing function, it can automatically repair bubbles and scratches within 24 hours.

The 0.14mm Ultra-Thin Protective Film can maintain the sensitivity of the touch screen to accurately respond to your touch.

The oleophobic and waterproof coating prevents fingerprints, oil stains and other substances from adhering to it and keeps the screen clean.

If you want to know more about Privacy Screen Protector products, please click Product Details to view the parameters, models, pictures, prices and other information about Privacy Screen Protector products.

Whether you are a group or an individual, we will try our best to provide you with accurate and comprehensive information about Privacy Screen Protector!

Anti-Spy Hydrogel Screen Protector, Privacy Protection Film, Protection Film, Privacy Film, Privacy Screen Protective Film, Soft Film

Shenzhen Jianjiantong Technology Co., Ltd. , https://www.jjtphonesticker.com