Linux下parity联盟链的实现

目录

一、parity的下载

二、parity UI界面配置

三、启动Authority node 

四、连接节点

五、分享给其他节点


一、parity的下载

1.事先打开我们的Linux虚拟机。然后打开我们的文件夹,创建一个PARITY的文件,当然也可以以其他名字命名,这里最好是parity命名。

     2.然后进入PARITY文件夹,在终端打开,在管理员权限下输入:

wget  https://releases.parity.io/ethereum/v1.9.7/x86_64-unknown-linux-gnu/parity

     下载完成以后,输入

chmod 775 parity  修改可执行文件

  接着输入: 

./parity -v   若没有报错,提示parity版本则下载成功。

  3.这一步是配置一些parity的相关信息。 

    1)首先是对创世区块的配置。通过命令 

vim 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
          }
        }
      }
    }
  }
}

接着配置节点信息,node0以及node1。

vim  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"]
cors = ["*"]
[ui]
port = 8180
[websockets]
port = 8456

 接着进入:

vim  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"]
cors = ["*"]
[ui]
port = 8181
[websockets]
port = 8457

二、parity UI界面配置

1.首先在刚才终端输入 ./parity --config node0.toml启动节点0。打开网页http://localhost:8180,按照步骤创建一个用户账号。

        分别创建user,node0的账号,密码分别是123456,方便操作,成功创建后出现下列界面,我的是已经转账过的。

       此时则创建成功。

2.接着在终端输入 ./parity --config node1.toml启动节点1。打开网页http://localhost:8181,按照步骤创建一个用户账号,步骤与1步类似,这一步不用创建user账号,创建成功如下:

3.创建完成以后,我们分别保存这几个节点的地址信息并且作记录,完成以后分别把地址添加到刚才的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 

为了启动Authority node来产生区块,我们必须设定负责产生blocksigner,分別是 node0 和 node1 account

1、第一步,创建一个node.pwds文件,写入node0node1password,内容如下:

vim node.pwds    然后输入竖向输入两个123456

2、第二步,在node0.toml文件中加入[account]及[mining]设置,如下:

[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"  //node0的地址
reseal_on_txs = "none"

3、第三步,在node1.toml文件中加入[account]及[mining]设置,如下: 

[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"   //node1的地址
reseal_on_txs = "none"

4、第四步,Step 4 分別启动两个node 

./parity --config node0.toml
./parity --config node1.toml

四、连接节点

使用Postman透过JSON RPC来测试。

1.下载postman,在官网找到安装包下载安装。将安装包复制到Ubuntu指定目录下,打开Ubuntu终端,输入命令将安装包解压。

sudo tar -xzf Postman-linux-x64-7.2.2.tar.gz
# tar -xzf 是解压命令

       2.进入解压后的Postman文件夹,启动Postman。

./Postman/Postman

3.启动后,点击文件,点击request新建一个请求。

1)Post下列JSON数据至 http://localhost:8540 以取得 node0 的enode资料 

{
 "jsonrpc":"2.0",
 "method":"parity_enode",
 "params":[],
 "id":0
}

获取到的数据如下:

{
    "jsonrpc": "2.0",
    "result": "enode://cfb3af513da3a7a8138450f0dc01fa38cb2ac837744dc645038940287f4dce3f416f0e7e17fd10619a263c360d9324fd2dcd8753c4500fcc54cf84e076b39cd6@192.168.56.130:30300",
    "id": 0
}

"enode://cfb3af513da3a7a8138450f0dc01fa38cb2ac837744dc645038940287f4dce3f416f0e7e17fd10619a263c360d9324fd2dcd8753c4500fcc54cf84e076b39cd6@192.168.56.1302:30300"node0的标识。下一步中我们将将它加入到node1中以实现两个节点之间的连接。 

2)将 node0 的enode加入 node1 ,Post下列JSONs数据至node1 (http://localhost:8541 )

{
 "jsonrpc":"2.0",
 "method":"parity_addReservedPeer",
 "params":["enode://cfb3af513da3a7a8138450f0dc01fa38cb2ac837744dc645038940287f4dce3f416f0e7e17fd10619a263c360d9324fd2dcd8753c4500fcc54cf84e076b39cd6@192.168.56.130:30300"],
 "id":0
}

返回的数据如下,result为true,说明连接成功: 

{
    "jsonrpc": "2.0",
    "result": true,
    "id": 0
}

如图所示位置: 

再切换到node1的终端,会看到下面的数据:

则连接成功。

4.发送交易

       我们一共创建了三个账号,一个用户(USER)账号,两个POA(Node0,Node1)账号,刚开始的时候我们为用户账号初始化了10000 ETH。如下图所示,账号与账号之间可以相互转账。

五、分享给其他节点

在开发时通常会将node跑在server上,让其他人可以通过JSON RPC port连接上去使用,此时只要在config文件里面加入 [interface] 设置即可。

假设server ip192.168.53.110,将 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.53.110"  /*/此处为新增内容
[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"

以上为parity搭建poa的全部过程。如有疑点,请私信我。 

 

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值