联盟链创建-实操篇

知识库 勿悔
  • 时间:
  • 浏览:

版权声明:转载请注明出处呦!编程的一休本教程适用Ubuntu16.04系统

联盟链简介:

联盟链,只针对特定某个群体的成员和有限的第三方,内部指定多个预选的节点为记账人,每个块的生成由所有的预选节点共同决定。

一.  下载Parity(钱包)

www.parity.io

进去之后就能看到下载页面,点击Other installs 下载适合自己系统的版本吧

联盟链创建-实操篇

查询安装版本

输入: parity --version输出:Parity version Parity/v1.9.5-stable-ff821da-20180321/x86_64-linux-gnu/rustc1.24.1Copyright 2015, 2016, 2017, 2018 Parity Technologies (UK) LtdLicense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law.By Wood/Paronyan/Kotewicz/Drwięga/Volf Habermeier/Czaban/Greeff/Gotchac/Redmann

当出现这样的输出结果的适合,就证明已经安装成功了

二.  配置文件

创建创世区块文件

在桌面创建一个我们项目的文件夹POA

cdPOA路径下面创建我们的创世区块demo-spec.json文件

cd POA/touch demo-spec.jsonvi demo-spec.json

以上是vi的书写方式将下面的代码写入demo-spec.json中并保存

{ "name": "DemoPoA", "engine": { "authorityRound": { "params": { "stepDuration": "5", "validators": { "list": [ } ] } } }, "params": { "gasLimitBoundDivisor": "0x0400", "maximumExtraDataSize": "0x20", "minGasLimit": "0x1388", "networkID": "0x2323" }, "genesis": { "seal": { "authorityRound": { "step": "0x0", "signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" } }, "difficulty": "0x20000", "gasLimit": "0x5B8D80" }, "accounts": { "0x0000000000000000000000000000000000000001": { "balance": "1", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } }, "0x0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } }, "0x0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } }, "0x0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } } }}

创建节点

POA文件夹中创建两个节点文件

touch node0.tomltouch node1.toml

将下面配置内容写入node0.toml

[parity]chain = "demo-spec.json"base_path = "parity0"[network]port = 30300[rpc]port = 8540apis = ["web3", "eth", "net", "personal", "parity", "parity_set", "traces","rpc", "parity_accounts"][ui]port = 8180[websockets]port = 8456

将下面的配置内容写入node1.toml

[parity]chain = "demo-spec.json"base_path = "parity1"[network]port = 30301[rpc]port = 8541apis = ["web3", "eth", "net", "personal", "parity", "parity_set", "traces","rpc", "parity_accounts"][ui]port = 8181[websockets]port = 8457

POA项目下创建node.pwds文件,写入node0node1password,如下:

node0node1

2.在node0wen文件中加入【mining】的设置,和跨域设置,以及interface

[parity]chain = "demo-spec.json"base_path = "parity0"[network]port = 30300[rpc]port = 8540apis = ["web3", "eth", "net", "personal", "parity", "parity_set", "traces","rpc", "parity_accounts"]cors = ["*"]interface ="你的IP地址"[ui]port = 8180[account]password = ["node.pwds"][mining]engine_signer = "node0的地址"reseal_on_txs = "none"

3.在 node1文件中加入【ming】的设置,同时加上跨域,加上interface

[parity]chain = "demo-spec.json"base_path = "parity1"[network]port = 30301[rpc]port = 8541apis = ["web3", "eth", "net", "personal", "parity", "parity_set", "traces","rpc", "parity_accounts"]cors = ["*"]interface ="你的IP地址"[ui]port = 8181[websockets]port = 8457[account]password = ["node.pwds"][mining]engine_signer = "node1的地址"reseal_on_txs = "none"

写入完毕,保存文件**

三. 启动并且创建账号

先启动节点node0,并且设置账号地址

注意:需要在POA文件夹内执行此命令

parity --config node0.toml

打开网页 以此方法在node0创建两个账号!

至此我们完成了node0的账户创建,

node1的账户创建与node0相同

另外打开一个终端,切换到POA项目路径,启动node1

parity --config node1.toml

然后就按照node0的方法创建账号吧,node1中我们只需要创建一个地址账号就行。

四. 初始化余额

我们创建好账号后,地址里面是没有余额的,下一步我们就来自己

"印币"吧!

在编辑器中打开我们POA项目里面的demo-spec.json文件,这里面承载的是我们创世区块的数据了

"list": [ "node1钱包账户的地址", "node0的钱包账户地址"]

文件中下方

"accounts": {"node0钱包中的另外一个地址": {"balance": "余额后缀加上18个",

cd到桌面POA路径

//启动节点0parity --config node0.toml//启动节点1parity --config node1.toml

在浏览器中输入127.0.0.1:8180 就可以查询漂亮的UI了好了!你的联盟链已经搭建完成,开启新的世界吧!有跑不通的情况,请留言!码字不易,留个赞再走吧!