Use parity to build proof-of-authority (PoA) Ethereum Chain5 minutes quickly from scratch build Ethereum Alliance chain

Source: Internet
Author: User
Tags builtin json


5 Minute quick build Ethereum Alliance chain from scratch

In the process of developing Ethereum Dapp, a test chain is required, previously using TESTRPC or directly connected to Ethereum testnet (Ropsten), but Testrpc has a variety of pits to deal with and Ropsten Testnet is the need to synchronize and wait chunks, quite annoying. A few days ago saw parity 1.5 version after support to establish proof of authority Chains, can directly solve the above problems, sure enough to try to become a customer.

If you have the following problems, you can set up your own test POA chain company intranet or no external network, unable to synchronize the block to reduce the time to wait for chunks to meet the TESTRPC various pits

PoA chain characteristics are different from the POW (proof-of-work) need to solve mathematical problems to produce BLOCK,POA is dependent on the preset good authority nodes, responsible for generating blocks. The number of authority node can be set according to the requirement. You can specify the time at which the block will be generated, such as block after 5 seconds of receiving the transaction. The general Ethereum node can also be connected to POA Chain, which normally initiates transactions, contracts and so on. This text is basically written according to the parity Demo PoA Tutorial.

Parity is a performance-focused Ethereum client-side software 1. Install parity (1.5.0 or later)

Please install it on your own parity website, support UBUTNU, OSX, Docker, Windows 2. Set Chain spec

PoA chain need to set up a Genesis block

{"Name": "Demopoa", "engine": {"Authorityround": {"params": {"Gaslimitboun
                Ddivisor ":" 0x400 "," Stepduration ":" 5 "," validators ": {" list ": [] }}}, "params": {"maximumextradatasize": "0x20", "Mingaslim
                It ":" 0x1388 "," Networkid ":" 0x2323 "}," Genesis ": {" seal ": {" Authorityround ": { "Step": "0x0", "signature": "0x0000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000 "}}," difficulty ":" 0x2 0000 "," gaslimit ":" 0x5b8d80 "}," accounts ": {" 0x0000000000000000000000000000000000000001 ": {" ba Lance ":" 1 "," builtin ": {" name ":" Ecrecover "," pricing ": {" linear ": {" base ": +," word ": 0}}}," 0x000000 0000000000000000000000000000000002 ": {" balance ":" 1 "," builtin ": {" name ":" sha256 "," pricing ": {" linear ": {" base ": $," word ": 12}}}, "0x0000000000000000000000000000000000000003": {"balance": "1", "builtin": {"name": "ripemd160", "pricing": {"linea  R ": {" base ": $," word ": +}}}," 0x0000000000000000000000000000000000000004 ": {" balance ":" 1 "," BUILTIN ":

 {"Name": "Identity", "pricing": {"linear": {"base": $, "word": 3}}}}}
Stepduration set to 5 seconds to generate a block validators set authority place, currently empty, followed by the account after the return to fill in

Save the above data as Demo-spec.json 3. Set two node

This teaching will run two node on the same machine, so some parity will have conflicting settings, and two node will need to set a different value for each one. -D Specify the directory to store the data and account--dport specify parity's network port, which can be used to make other node connections--jsonrpc-port This is the JSON RPC port, which is required when using Web3.js Ui-port Parity provides web-based UI port Dapps-port Parity Dapps using the port

You can start parity node with the following command

Parity--chain demo-spec.json-d/tmp/parity0--port 30300--jsonrpc-port 8540--ui-port 8180--dapps-port 8080--jsonrpc- APIs web3,eth,net,personal,parity,parity_set,traces,rpc,parity_accounts

In addition to playing a long list of instructions, parity also provides a more concise config file setting, using--config to reference the profile.

Node0 Use the following profiles node0.toml

[Parity]
Chain = "Demo-spec.json"
base_path = "/tmp/parity0"
[network]
port = 30300
[RPC]
port = 8540
APIs = ["Web3", "ETH", "net", "personal", "parity", "Parity_set", "Traces", "rpc", "parity_accounts"]
[UI]
port = 8180
[Dapps]
port = 8080

Node1 Use the following profiles node1.toml

[Parity]
Chain = "Demo-spec.json"
base_path = "/tmp/parity1"
[network]
port = 30301
[RPC]
port = 8541< C17/>apis = ["Web3", "ETH", "net", "personal", "parity", "Parity_set", "Traces", "rpc", "parity_accounts"]
[ui]
  port = 8181
[Dapps]
port = 8081
4. Set Account

We have a total of 3 accounts: 2 Authority and 1 user accounts. Step 1, first start node0:parity--config node0.toml

Then open the webpage http://localhost:8180

I don't know how to skip the welcome operation, so just follow the instructions to create an account, and then delete the xd

A new user account is added, using the recover account from recovery phrase function, in order to demonstrate consistency, use user as pass phrase

Select the second item

Enter user

Complete user Account

Add authority account, same as using recover account from recovery phrase function, for demonstration consistency, use NODE0 as pass phrase

Select the second item

Input Node0

Finally, you will see the user and Node0 (authority) account

This completes the NODE0 account setting Authority account:0x00bd138abd70e2f00903268f3db08f2d25677c9e User accounts: 0x004ec07d2329997267ec62b4166639513386f32e Step 2, then to set the Node1 account, start parity--config node1.toml, the same steps, connected to http:// localhost:8181, pass phrase use Node1

Start Parity Node1

Input Node1

Complete Authority Account

This completes the Node1 Account setting Authority ACCOUNT:0X00AA39D30F0D20FF03A22CCFC30B7EFBFCA597C2 Step 3, write the Authority accounts Demo-spec.json file

"validators": {
    "list": [
        "0x00bd138abd70e2f00903268f3db08f2d25677c9e",
        " 0x00aa39d30f0d20ff03a22ccfc30b7efbfca597c2 "
    ]
}

Add the user account to accounts and give some balance, which you can use later

"0x004ec07d2329997267ec62b4166639513386f32e": {"balance": "10000000000000000000000"}

After the completion of the Demo-spec.json as follows

{"Name": "Demopoa", "engine": {"Authorityround": {"params": {"Gaslimitboun
                        Ddivisor ":" 0x400 "," Stepduration ":" 5 "," validators ": {" list ": [ "0x00bd138abd70e2f00903268f3db08f2d25677c9e", "0x00aa39d30f0d20ff03a22ccfc30 B7efbfca597c2 "]}}}," params ": {" maximumextr Adatasize ":" 0x20 "," Mingaslimit ":" 0x1388 "," Networkid ":" 0x2323 "}," Genesis ": {" Seal " : {"Authorityround": {"Step": "0x0", "signature": "0x00000000000000000000000 
        00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 "} }, "difficulty": "0x20000", "Gaslimit": "0x5b8d80"}, "accounts": {"0x0000000000 000000000000000000000000000001 ": {" balance ":" 1 "," builtin ": {" name ":" Ecrecover "," pricing ": {" linear ": {" base ": $," word ": 0}}},  "0x0000000000000000000000000000000000000002": {"balance": "1", "builtin": {"name": "sha256", "pricing": {"linear": {"Base": $, "word": 12}} }}, "0x0000000000000000000000000000000000000003": {"balance": "1", "builtin": {"name": "ripemd160", "pricing": {"linear": {"base": $, "word": 120}} }, "0x0000000000000000000000000000000000000004": {"balance": "1", "builtin": {"name": "Identity", "pricing": {" Linear ": {" base ": $," word ": 3}}}," 0x004ec07d2329997267ec62b4166639513386f32e ": {" balance ":" 100000000000

 00000000000 "}}}
5. Start Authority node

In order to start authority node to generate chunks, we must set up the signer responsible for generating the block, respectively Node0 and Node1 account Step 1, open a Node.pwds file, write node0 and Node1 PASSW Ord, the content is as follows

Node0
Node1
Step 2, add the [account] and [mining] settings in the profile node0.toml, as follows
[Parity]
Chain = "Demo-spec.json"
base_path = "/tmp/parity0"
[network]
port = 30300
[RPC]
port = 8540
APIs = ["Web3", "ETH", "net", "personal", "parity", "Parity_set", "Traces", "rpc", "parity_accounts"]
[UI]
Port = 8180
[Dapps]
port = 8080
[Account]
password = ["Node.pwds"]
[mining]
Engine_ Signer = "0x00bd138abd70e2f00903268f3db08f2d25677c9e"
Reseal_on_txs = "None"
Step 3, NODE1.TOML is also the same, as follows
[Parity]
Chain = "Demo-spec.json"
base_path = "/tmp/parity1"
[network]
port = 30301
[RPC]
port = 8541
APIs = ["Web3", "ETH", "net", "personal", "parity", "Parity_set", "Traces", "rpc", "parity_accounts"]
[UI]
port = 8181
[Dapps]
port = 8081
[Account]
password = ["Node.pwds"]
[mining]
Engine_signer = " 0x00aa39d30f0d20ff03a22ccfc30b7efbfca597c2 "
Reseal_on_txs =" None "
Step 4, start each of the two node

Parity--config NODE0.TOML

Parity--config node1.toml 6, connect two node

Use Postman to test Step 1, post the following JSON data to http://localhost:8540 to obtain NODE0 Enode data through JSON RPC

{
 "JSONRPC": "2.0",
 "method": "Parity_enode",
 "params": [],
 "id": 0
}

Get Enode Connection Information
Step 2, add node0 enode to Node1, post the following JSON data to Node1 (http://localhost:8541)

{
 "JSONRPC": "2.0",
 "method": "Parity_addreservedpeer",
 "params": ["enode:// 6c4f53fc8536553c8f151516b7ee17f4b0719d21abe8fdd273588419cf467e3deafb414cd8efa331e4ad55fd7c2820a303a160895129e142a4306e7c3 367d67c@172.20.160.80:30300 "],
 " id ": 0
}

Your IP address will be different, 172.20.160.80.

Successfully joined

Finally to the Node1 console screen, you will see 0/1/25 peers, it means that it has been connected.

7. Send Transaction

The web-based UI provided by parity can be easily sent transaction, which is not discussed here. add: Share with other people in the area network

At development time, node is usually run on the server, allowing others to use the JSON RPC port connection, as long as the [INTERFAC] is added to CONFIG.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.