P78 、1-内容介绍
什么情况下建立自己测试用的PoA chain?
PoA chain特点有
大纲
1、Parity钱包下载安装
2、设置chain spec
3、设置两个节点
4、设置账号(Account)
5、启动Authority node
6、连接两个节点
7、发送交易
8、分享给其它节点
P79 、2-Parity钱包下载安装
钱包有:Mist钱包、Metamask、myetherwallet钱包。
Parity钱包下载安装:https://www.parity.io/ethereum/
https://github.com/paritytech/parity-ethereum/releases/tag/v2.2.9
ubuntu安装parit教程:https://github.com/paritytech/parity-ethereum
https://wiki.parity.io/Setup
后来摸索着步骤:
1、ubuntu安装Homebrew:https://blog.csdn.net/Cocoa_vip/article/details/74395285
步骤:
将如下代码粘贴到终端,如果没有安装ruby,使用apt-get install ruby安装:
ruby -e "$(wget -O- https://raw.github.com/Homebrew/linuxbrew/go/install)"
2、增加parity到你的Homebrew ‘keys’中,首先ubuntu安装好 linuxbrew-wrapper,
apt install linuxbrew-wrapper
brew tap paritytech/paritytech
3、安装parity
brew install parity --stable
brew install parity
brew install parity --master
brew update && brew upgrade parity
或者
brew reinstall parity
4、查看安装版本
parity --version
https://www.cnblogs.com/sumingk/articles/9097996.html
P80 、3-demo-spec 配置文件
PoA chain 需要设置一个创世区块。
{
"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
}
}
}
}
}
}
将上面的文件保存到桌面的一个文件中,保存为demo-spec.json。
P81 、4-POA Node创建的两种方法
我们在同一台电脑设置两个节点,在私链建立中,如果在同一台电脑设置两个节点,需要将rpcport和port设置为不同的值,否则就会发生冲突,POA chain中也是一样,需要将一些参数设置为不同的值。
可以使用下列指令启动Parity node。
parity --chain demo-spec.json -d parity0 --port 30300 --ui-port 8180 --jsonrpc-port 8540 --jsonrpc-apis web3,eth,net,personal,parity,parity_set,traces,rpc,parity_accounts
浏览器输入:
localhost:8180
访问联盟链的UI界面。
除了打一长串的指令外,Parity也提供更为简洁的config档案设定方式,使用--config即可引用配置文件。
[parity]
chain = "demo-spec.json"
base_path = "parity0"
[network]
port = 30300
[rpc]
port = 8540
apis = ["web3", "eth", "net", "personal", "parity", "parity_set", "traces", "rpc", "parity_accounts"]
cors = ["*"]
[ui]
port = 8180
[websockets]
port = 8456
[parity]
chain = "demo-spec.json"
base_path = "parity1"
[network]
port = 30301
[rpc]
port = 8541
apis = ["web3", "eth", "net", "personal", "parity", "parity_set", "traces", "rpc", "parity_accounts"]
cors = ["*"]
[ui]
port = 8181
[websockets]
port = 8457
P82 、5-node0 & node1 配置以及账号创建
我们总共需要设置三个账号,两个Authority 和一个 user 账号。
node0
: parity --config node0.toml
打开网页http://localhost:8180,按照步骤创建一个用户账号。
Authority account
,使用Restore
功能,为了示范一致性,我们使用 node0
当作 pass phrase
。到目前为止我们已经完成node0
的账号设置。
0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e
0x0064B0999c0142eE99aB0ceC054BAb53fe0a3EcC
node1
的账号,启动parity --config node1.toml
。步骤相同,连接到 http://localhost:8181 ,pass phrase
使用 node1
。这样就完成了node1
的账号设置。
0x00F9B30838ca40c8A53c672840acbDec6fCDb180
"validators": {
"list": [
"0x00F9B30838ca40c8A53c672840acbDec6fCDb180",
"0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e"
]
}
再将user account
加入accounts
,並给一些balance
,后续可以使用。
"0x0064B0999c0142eE99aB0ceC054BAb53fe0a3EcC": {
"balance": "10000000000000000000000"
}
完成后的demo-spec.json
如下:
{
"name": "DemoPoA",
"engine": {
"authorityRound": {
"params": {
"stepDuration": "5",
"validators": {
"list": [
"0x00F9B30838ca40c8A53c672840acbDec6fCDb180",
"0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e"
]
}
}
}
},
"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
}
}
}
},
"0x0064B0999c0142eE99aB0ceC054BAb53fe0a3EcC": {
"balance": "10000000000000000000000"
},
"0x0000000000000000000000000000000000000004": {
"balance": "1",
"builtin": {
"name": "identity",
"pricing": {
"linear": {
"base": 15,
"word": 3
}
}
}
}
}
}
为了启动Authority node
来产生区块,我们必须设定负责产生block
的signer
,分別是 node0
和 node1 account
。
node.pwds
文件,写入node0
与node1
的password
,内容如下:node0
node1
[parity]
chain = "demo-spec.json"
base_path = "parity0"
[network]
port = 30300
[rpc]
port = 8540
apis = ["web3", "eth", "net", "personal", "parity", "parity_set", "traces", "rpc", "parity_accounts"]
cors = ["*"]
[ui]
port = 8180
[account]
password = ["node.pwds"]
[mining]
engine_signer = "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e"
reseal_on_txs = "none"
[parity]
chain = "demo-spec.json"
base_path = "parity1"
[network]
port = 30301
[rpc]
port = 8541
apis = ["web3", "eth", "net", "personal", "parity", "parity_set", "traces", "rpc", "parity_accounts"]
cors = ["*"]
[ui]
port = 8181
[websockets]
port = 8457
[account]
password = ["node.pwds"]
[mining]
engine_signer = "0x00F9B30838ca40c8A53c672840acbDec6fCDb180"
reseal_on_txs = "none"
parity --config node0.toml
parity --config node1.toml
P83 、6-多节点连接、交易、互通
使用Postman
透过JSON RPC
来测试。
{
"jsonrpc":"2.0",
"method":"parity_enode",
"params":[],
"id":0
}
获取到的数据如下:
{
"jsonrpc": "2.0",
"result": "enode://cfb3af513da3a7a8138450f0dc01fa38cb2ac837744dc645038940287f4dce3f416f0e7e17fd10619a263c360d9324fd2dcd8753c4500fcc54cf84e076b39cd6@192.168.10.101:30300",
"id": 0
}
"enode://cfb3af513da3a7a8138450f0dc01fa38cb2ac837744dc645038940287f4dce3f416f0e7e17fd10619a263c360d9324fd2dcd8753c4500fcc54cf84e076b39cd6@192.168.10.101:30300"
是node0
的标识。下一步中我们将将它加入到node1
中以实现两个节点之间的连接。
{
"jsonrpc":"2.0",
"method":"parity_addReservedPeer",
"params":["enode://cfb3af513da3a7a8138450f0dc01fa38cb2ac837744dc645038940287f4dce3f416f0e7e17fd10619a263c360d9324fd2dcd8753c4500fcc54cf84e076b39cd6@192.168.10.101:30300"],
"id":0
}
返回的数据如下,result
为true,说明连接成功:
{
"jsonrpc": "2.0",
"result": true,
"id": 0
}
再切换到node1
的终端,会看到下面的数据:
1/25 peers 13 KiB chain 11 KiB db 0 bytes queue 10 KiB sync RPC: 0 conn, 0 req/s, 24 µs
如上图所示,表示连接成功。
在我们这个案例中,我们一个创建了三个账号,一个用户账号,两个POA
账号,刚开始的时候我们为用户账号初始化了10000 ETH
。如下图所示,账号与账号之间可以相互转账。
在开发时通常会将node跑在server上,让其他人可以通过JSON RPC port
连接上去使用,此时只要在config
文件里面加入 [interface]
设置即可。
假设server ip
为192.168.1.5
,将 node0.toml
修改如下:
[parity]
chain = "demo-spec.json"
base_path = "parity0"
[network]
port = 30300
[rpc]
port = 8540
apis = ["web3", "eth", "net", "personal", "parity", "parity_set", "traces", "rpc", "parity_accounts"]
interface = "192.168.1.5"
[ui]
port = 8180
[account]
password = ["node.pwds"]
[mining]
engine_signer = "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e"
reseal_on_txs = "none"
node1.toml
修改如下:
[parity]
chain = "demo-spec.json"
base_path = "parity1"
[network]
port = 30301
[rpc]
port = 8541
apis = ["web3", "eth", "net", "personal", "parity", "parity_set", "traces", "rpc", "parity_accounts"]
interface = "192.168.1.5"
[ui]
port = 8181
[websockets]
port = 8457
[account]
password = ["node.pwds"]
[mining]
engine_signer = "0x00F9B30838ca40c8A53c672840acbDec6fCDb180"
reseal_on_txs = "none"