使用Parity建立ProofofAuthority PoA Ethereum Chain5分钟快速从无到有建立Ethereum联盟链.docx
- 文档编号:12181737
- 上传时间:2023-04-17
- 格式:DOCX
- 页数:5
- 大小:17.09KB
使用Parity建立ProofofAuthority PoA Ethereum Chain5分钟快速从无到有建立Ethereum联盟链.docx
《使用Parity建立ProofofAuthority PoA Ethereum Chain5分钟快速从无到有建立Ethereum联盟链.docx》由会员分享,可在线阅读,更多相关《使用Parity建立ProofofAuthority PoA Ethereum Chain5分钟快速从无到有建立Ethereum联盟链.docx(5页珍藏版)》请在冰豆网上搜索。
使用Parity建立ProofofAuthorityPoAEthereumChain5分钟快速从无到有建立Ethereum联盟链
使用Parity建立Proof-of-Authority(PoA)EthereumChain5分钟快速从无到有建立Ethereum联盟链
?
fidelhl使用Parity建立Proof-of-Authority(PoA)EthereumChain5分钟快速从无到有建立Ethereum联盟链发表于2017/2/1916:
42:
192803人阅读分类:
以太坊/ethereum区块链/Blockchain以太坊Solidity文档5分钟快速从无到有建立Ethereum联盟链开发EthereumDapp的过程中,需要一个测试用的chain,之前是使用testrpc或直接连到Ethereumtestnet(Ropsten),不过testrpc有各种坑需要处理,而Ropstentestnet则是需要同步与等待区块,相当的烦人。
前几天看到Parity1.5版以后支持建立ProofofAuthorityChains,可以直接解决上述的问题,果然一试成主顾。
若你有下列困扰,可以建立自己测试用的PoAchain公司内网或无对外网路,无法同步区块降低测试时等待区块的时间不想碰到testrpc各种坑PoAChain特点有有别于PoW(Proof-of-Work)需要解数学难题来产生block,PoA是依靠预设好的Authoritynodes,负责产生block。
可依照需求设定Authoritynode数量。
可指定产生block的时间,例如收到交易的5秒后产生block。
一般的Ethereumnode也可以连接到PoAChain,正常发起transactions,contracts等。
这篇教学文基本上是照著ParityDemoPoA教程来撰写。
Parity是一个注重效能的EthereumClient端软体1.安装Parity(1.5.0以上版本)请自行到Parity官网安装,支持Ubutnu,OSX,Docker,Windows2.设定chainspecPoAchain需要设定一个创世区块{"name":
"DemoPoA","engine":
{"authorityRound":
{"params":
{"gasLimitBoundDivisor":
"0x400","stepDuration":
"5","validators":
{"list":
[]}}}},"params":
{"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}}}}}}stepDuration设定成5秒产生一个区块validators设定Authority的地方,目前先空著,后续产生account之后再回来填入将上述资料存成demo-spec.json3.设定两个node此教学会在同一台机器上跑两个node,因此有些Parity原生的设定参数会有衝突,两个node需要分别设定不同值。
-d指定储存资料与帐号的目录--dport指定Parity的networkport,可用来让其他node连接--jsonrpc-port这是JSONRPCport,使用web3.js时会需要ui-portParity提供的Web-basedUIportdapps-portParityDapps使用的port可以用下列指令启动Paritynodeparity--chaindemo-spec.json-d/tmp/parity0--port30300--jsonrpc-port8540--ui-port8180--dapps-port8080--jsonrpc-apisweb3,eth,net,personal,parity,parity_set,traces,rpc,parity_accounts除了打一长串的指令外,Parity也提供更为简洁的config档案设定方式,使用--config即可引用设定档。
node0使用如下设定档node0.toml[parity]chain="demo-spec.json"base_path="/tmp/parity0"[network]port=30300[rpc]port=8540apis=["web3","eth","net","personal","parity","parity_set","traces","rpc","parity_accounts"][ui]port=8180[dapps]port=8080node1使用如下设定档node1.toml[parity]chain="demo-spec.json"base_path="/tmp/parity1"[network]port=30301[rpc]port=8541apis=["web3","eth","net","personal","parity","parity_set","traces","rpc","parity_accounts"][ui]port=8181[dapps]port=80814.设定帐号(Account)我们总共要开3个帐号:
2个Authority跟1个user帐号。
步骤1、首先启动node0:
parity--confignode0.toml接著开启网页http:
//localhost:
8180我不知道怎么略过WELCOME操作,所以先跟著指示随便建立一个account,然后再删除XD接著新增一个useraccount,使用Recoveraccountfromrecoveryphrase功能,为了示范的一致性,使用user当作passphrase选择第二项输入user完成Useraccount新增Authorityaccount,一样使用Recoveraccountfromrecoveryphrase功能,为了示范的一致性,使用node0当作passphrase选择第二项输入node0最后要看到User与Node0(Authority)account这样就完成node0的帐号设定Authorityaccount:
0x00Bd138aBD70e2F00903268F3Db08f2D25677C9eUseraccount:
0x004ec07d2329997267Ec62b4166639513386F32E步骤2、再来设定node1的帐号,启动parity--confignode1.toml,步骤相同,连接到http:
//localhost:
8181,passphrase使用node1启动Paritynode1输入node1完成Authorityaccount这样就完成node1的帐号设定Authorityaccount:
0x00Aa39d30F0D20FF03a22cCfc30B7EfbFca597C2步骤3、将Authorityaccount写入demo-spec.json档案"validators":
{"list":
["0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e","0x00Aa39d30F0D20FF03a22cCfc30B7EfbFca597C2"]}再将useraccount加入accounts,并给一些balance,后续可以使用"0x004ec07d2329997267Ec62b4166639513386F32E":
{"balance":
"10000000000000000000000"}完成后的demo-spec.json如下{"name":
"DemoPoA","engine":
{"authorityRound":
{"params":
{"gasLimitBoundDivisor":
"0x400","stepDuration":
"5","validators":
{"list":
["0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e","0x00Aa39d30F0D20FF03a22cCfc30B7EfbFca597C2"]}}}},"params":
{"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}}}},"0x004ec07d2329997267Ec62b4166639513386F32E":
{"balance":
"10000000000000000000000"}}}5.启动Authoritynode为了启动Authoritynode来产生区块,我们必须设定负责产生block的signer,分别是node0与node1account步骤1、开启一个node.pwds档案,写入node0与node1的password,内容如下node0node1步骤2、在设定档node0.toml加入[account]及[mining]设定,如下[parity]chain="demo-spec.json"base_path="/tmp/parity0"[network]port=30300[rpc]port=8540apis=["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"步骤3、node1.toml也一样,如下[parity]chain="demo-spec.json"base_path="/tmp/parity1"[network]port=30301[rpc]port=8541apis=["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"步骤4、分别启动两个nodeparity--confignode0.tomlparity--confignode1.toml6、连接两个node使用Postman透过JSONRPC来测试步骤1、Post下列JSON资料至http:
//localhost:
8540以取得node0的enode资料{"jsonrpc":
"2.0","method":
"parity_enode","params":
[],"id":
0}取得enode连接资讯步骤2、将node0的enode加入node1,Post下列JSON资料至node1(http:
//localhost:
8541){"jsonrpc":
"2.0","method":
"parity_addReservedPeer","params":
["enode:
//6c4f53fc8536553c8f151516b7ee17f4b0719d21abe8fdd273588419cf467e3deafb414cd8efa331e4ad55fd7c2820a303a160895129e142a4306e7c3367d67c@172.20.160.80:
30300"],"id":
0}你的IP地址会不一样,172.20.160.80成功加入最后到node1的console画面,会看到0/1/25peers,就表示已经连接上。
7.发送transaction通过Parity提供的web-basedUI可以很容易发送transaction,这边就不赘述了。
补充:
分享给区网内其他人使用在开发时通常会将node跑在server上,让其他人可以透过JSONRPCport连接上去使用,此时只要在config里面加入[interface]设定即可。
假设serverip为192.168.1.1,将node0.toml修改如下:
[parity]chain="demo-spec.json"base_path="/tmp/parity0"[network]port=30300[rpc]port=8540apis=["web3","eth","net","personal","parity","parity_set","traces","rpc","parity_accounts"]interface="192.168.1.1"[ui]port=8180[dapps]port=8080[account]password=["node.pwds"][mining]engine_signer="0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e"reseal_on_txs="none"同样node1.toml修改如下:
[parity]chain="demo-spec.json"base_path="/tmp/parity1"[network]port=30301[rpc]port=8541apis=["web3","eth","net","personal","parity","parity_set","traces","rpc","parity_accounts"]interface="192.168.1.1"[ui]port=8181[dapps]port=8081[account]password=["node.pwds"][mining]engine_signer="0x00Aa39d30F0D20FF03a22cCfc30B7EfbFca597C2"reseal_on_txs="none"本文转自台湾以太坊社区:
00上一篇下一篇
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 使用Parity建立ProofofAuthority PoA Ethereum Chain5分钟快速从无到有建立Ethereum联盟链 使用 Parity 建
![提示](https://static.bdocx.com/images/bang_tan.gif)
链接地址:https://www.bdocx.com/doc/12181737.html