快速入门 BeidouChain

本快速入门教程将带你体验基本的BeidouChain功能和操作命令。

学习本教程需要两个独立的“节点”服务器,这两天服务器都下载并安装了BeidouChain可执行程序。

1. 建立一个区块链

首先我们建立一个新的区块链,命名为 chain1,在第一台服务器上,执行以下命令:

beidouchain-util create chain1

命令执行后,将在 /root/.beidouchain 中建立区块链的文件结构。beidouchain文件夹是以隐藏方式存在的。

查看区块链的默认配置:(这些配置可以修改,我们建议用默认值,完成本教程)

cat ~/.beidouchain/chain1/params.dat

初始化区块链,并且“挖出”第一个创始区块:

beidouchaind chain1 -daemon

系统提示区块链服务已经启动,并且在几秒钟后,发现创始区块,并且返回当前节点的地址:

拷贝粘贴节点地址: chain1@[ip-address]:[port]

 

2. 连接到一个区块链

区块链作为一种去中心架构,需要各个节点相互连接。现在我们登陆到第二台服务器,执行:

beidouchaind chain1@[ip-address]:[port]

You should be told that the blockchain was successfully initialized, but you do not have permission to connect. You should also be shown a message containing an address in this node’s wallet.

Copy and paste the wallet address here:

Back on the first server, add connection permissions for this address:

beidouchain-cli chain1 grant 1... connect

Now try reconnecting again from the second server:

beidouchaind chain1 -daemon

You should be shown a message that the node was started, and it should display this second node’s address.

 

3. Some commands in interactive mode

Before we proceed, let’s enter interactive mode so we can issue commands without typing beidouchain-cli chain1 every time. On both servers:

beidouchain-cli chain1

Now that the blockchain is working on two nodes, you can run the commands in this section on either or both. To get general information:

getinfo

See a list of all available commands:

help

Show all permissions currently assigned:

listpermissions

Create a new address in the wallet:

getnewaddress

List all addresses in the wallet:

getaddresses

Get the parameters of this blockchain (based on params.dat file):

getblockchainparams

For each node, get a list of connected peers:

getpeerinfo

 

4. Using native assets

Now we are going to create a new asset and send it between nodes. On the first server, get the address that has the permission to create assets:

listpermissions issue

Copy and paste the displayed address here:

Now we’ll create a new asset on this node with 1000 units, each of which can be subdivided into 100 parts, sending it to itself:

issue 1... asset1 1000 0.01

On both servers, verify that the asset named asset1 is listed:

listassets

Now check the asset balances on each server. The first should show a balance of 1000, and the second should show no assets at all:

gettotalbalances

On the first server, now try sending 100 units of the asset to the second server’s wallet:

sendasset 1... asset1 100

You should see an error that the address does not have receive permissions. So it’s time to add receive and send permissions:

grant 1... receive,send

Now try sending the asset again, and it should go through:

sendasset 1... asset1 100

Now check the asset balances on each server, including transactions with zero confirmations. They should be 900 and 100 respectively:

gettotalbalances 0

You can also view the transaction on each node and see how it affected their balances:

listwallettransactions 1