Multichain多链|2.Getting Started入门

原文地址:http://www.multichain.com/getting-started/

上一篇说的是基本的下载和安装,这一篇要做最基本的入门了。

翻译注:自己尝试翻译,如果有错希望大神们指正。源地址可能会有更新,一切以源地址发布的命令为主。有机会我也会继续更新。

凡是原文的命令全部都用框框标识出来了。命令是不翻译的。本文的两个服务器第一台是WINDOWS第二台LINUX,截图里面有一些是WINDOWS的界面。LINUX机子全部跟着默认命令就好。不需要受到截图内容的影响。

Create and deploy your first private blockchain in minutes 

在几分钟内创建并部署您的第一个私有块链

This tutorial requires two server nodes. If you have not done so already, please download and install MultiChain on each server. If you are using MultiChain on Windows, please read the Windows notes in the README.txt file to adapt the instructions below.

本教程需要两个服务器节点。 如果您还没有这样做,请在每个服务器上快速下载并安装MultiChain(翻译版本看这里)。 如果您在Windows上使用MultiChain,请阅读README.txt文件中的Windows注释,以适应以下说明。

1. Creating a blockchain 创建一个区块链

First we will create a new blockchain named chain1. On the first server, run this command:

首先我们要创建一个名为chain1的新区块链。在第一个服务器上运行以下命令:

multichain-util create chain1

View the blockchain’s default settings (these can also be modified but we recommend using the defaults for now): 查看该区块链的默认设置(这些也可以修改,但我们建议现在使用默认设置):

cat ~/.multichain/chain1/params.dat

Initialize the blockchain, including mining the genesis block:初始化区块链,包括挖出源区块

multichaind chain1 -daemon

You should be told that the server has started and then after a few seconds, that the genesis block was found. You should also be given the node address that others can use to connect to this chain.你应该被告知服务器已经启动,然后几秒钟后,源区块挖掘成功。你会被赋予节点地址,其他人可以用这个地址来连接到你的区块链上。


运行之后的样例,需要记下来的就是黄色高亮的IP和port


地址格式如下:chain1@[ip-address]:[port]

翻译注:这步产生的地址可以记下来,下面会用到

2. Connecting to a blockchain 链接到一个区块链

Now we’ll connect to this blockchain from elsewhere. On the second server, run the following:现在我们将从其他地方连接到这个blockchain。在第二台服务器上,运行以下命令:

multichaind 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.你会被告知区块链接成功初始化,但你没有连接的权限。您应该还会看到一条包含属于节点的钱包的地址的消息。复制该地址。

Back on the first server, add connection permissions for this address: 回到第一台服务器,为这个地址(第二台服务器的地址)添加连接许可

multichain-cli chain1 grant [第二台服务器地址] connect

翻译注:地址很长,可以发个邮件什么的把这个地址送回第一天服务器。

Now try reconnecting again from the second server: 现在再回到第二台服务器试一试以下命令。

multichaind chain1 -daemon

You should be shown a message that the node was started, and it should display this second node’s address. 你会收到提示信息指示节点已启动,并显示该第二个节点的地址。(node started)

3. Some commands in interactive mode 交互模式下的命令

Before we proceed, let’s enter interactive mode so we can issue commands without typing multichain-cli chain1 every time. On both servers: 在我们继续之前,让我们进入交互模式,这样我们每次发出命令就不需要输入multichain-cli chain1了。 在两个服务器上都运行:

multichain-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


翻译注:原文应该是在LINUX 系统下测试的结果,windows系统下交互模式还不可以用 需要输入完整的内容。 比如windows下输入(下面所有的命令同理,需要完整): 

multichain-cli chain1 getinfo

官方给出的给WINDOWS用户的临时解决方案是这样的:

Use the Linux version of multichain-cli inside Docker to communicate with a node running on Windows (or indeed on Linux). 在运行WINDOWS的节点上装个Docker,然后跑LINUX版本的multichain-cli(其实这样还是相当于跑在LINUX上了)

Rename the multichain-cli executable to m (it doesn'tcare) and use a one-letter blockchain name like c so you just need to write m c before each line instead. 将multichain-cli可执行文件重命名为m(或者什么都可以不影响),并使用一个单字母的区块名称,如c,因此您只需要在每一行之前写入m c ...... 就行了。

以下继续基于LINUX的正文翻译。用WINDOWS机器的亲自行加一下前面的内容。


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 onparams.datfile): 获取此区块链的参数(基于params.datfile):

getblockchainparams

For each node, get a list of connected peers: 在每个节点上,尝试获取连接的对等节点的列表:

getpeerinfo

4. Using native assets

If you only interested in blockchains for data storage and retrieval, rather than representing asset transactions, skip straight to section 6. 如果您只对用区块链做数据存取感兴趣,而不是用区块链表示资产交易,请直接跳到第6节。

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 

翻译注:这步要复制产生的地址[address1] 下面要用

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: 现在我们将在这个节点上创建一种有1000个单位的新资产,每个单位可以再细分为100个部分,发送给自己:

issue [address1] asset1 1000 0.01

翻译注:[address1]是第一台上面一步产生的地址

On both servers, verify that the asset namedasset1is listed: 在两个服务器上,验证名为"asset1“的资产是否列出:

listassets

Now check the asset balances on each server. The first should show a balance of1000, and the second should show no assets at all: 现在检查每个服务器上的资产余额。第一个服务器应该显示拥有1000的余额,第二个服务器应该显示没有资产:

gettotalbalances

On the first server, now try sending 100 units of the asset to the second server’s wallet: 现在在第一台服务器上,尝试将100个新资产发送到第二台服务器的钱包:

sendasset [address2] asset1 100

翻译注:[address2]是第二台服务器的地址


错误信息的例子


You should see an error that the address does not have receive permissions. So it’s time to add receive and send permissions: 您应该看到地址没有接收权限的错误。所以现在是添加接收和发送权限的时候了:

grant [address2] receive,send

翻译注:[address2]是第二台服务器的地址(上面第二步的时候获取的地址),用第一台服务器修改第二台的权限


成功的话就不会有错误信息,会有一串ID

Now try sending the asset again, and it should go through:现在再试一次发送资产,应该可以通过了(成功的话会看到一串新的ID):

sendasset [address2] asset1 100

翻译注:[address2]是第二台服务器的地址

Now check the asset balances on each server, including transactions with zero confirmations. They should be900and100respectively: 现在检查每个服务器上的资产余额,包括零确认的交易。他们应该分别是是900(第一台)和100(第二台):

gettotalbalances 0

You can also view the transaction on each node and see how it affected their balances:您还可以查看每个节点上的交易,并查看它们是如何影响其余额

listwallettransactions 1

翻译注:这里的1就代表你要看最近的一笔交易。如果你多做几次交易操作,想看到更多的,可以更换这个数值。

5. Transaction metadata 交易元数据

In this section we’ll create a transaction that sends 125 units of asset1 along with some metadata. On the first server, run: 在本节中,我们将创建一个交易,发送125个单位的asset1(上文创建的新资产)以及一些元数据(后面那一串数字)。在第一台服务器上运行:

sendwithdata [address2] '{"asset1":125}' 48692066726f6d204d756c7469436861696e21

这一步会产生一个交易序列号(transaction ID),要存下来

翻译注:[address2]是第二台服务器的地址,489...这些数据就是元数据(必须是hex string) 可以用这个网站来转换普通的字符串 http://string-functions.com/string-hex.aspx

翻译注2:WINDOWS用户要注意ESCAPE CHARACTER的问题,改用以下两种命令格式:

sendwithdata [address2] {\"asset1\":125} 48692066726f6d204d756c7469436861696e21

sendwithdata [address2] {"""asset1""":125} 48692066726f6d204d756c7469436861696e21

Now this transaction can be examined on thesecond serveras below: 现在可以在下面的第二个服务器上检查此交易:

getwallettransactiona [transaction ID]

需要输入上一步产生的交易序列号

In the output from this command, you should see the balance field showing the incoming 125 units of asset1 and the data field containing the hexadecimal metadata that was added. 在此命令的输出中,您应该看到余额栏(balance field)显示了传入的125个单位的asset1同时数据栏包含了我们添加的十六进制元数据的数据字段。

6. Streams 流

Now let’s create a stream, which can be used for general data storage and retrieval. On the first server: 现在我们创建一个流,流可以用于一般的数据存储和检索。在第一台服务器上输入:

create stream stream1 false

The false means the stream can only be written to by those with explicit permissions. Let’s see its permissions:以上命令中的false表示流只能由具有明确权限的用户写入。让我们查看一下它的权限:

listpermissions stream1.*


listpermission运行结果例子


So for now, only the first server has the ability to write to the stream, as well as administrate it. Let’s publish something to it, with key key1: 所以现在只有第一台服务器有能力写入流,以及管理它。我们用key1来发布一些东西:

publish stream1 key1 73747265616d2064617461

翻译注:stream可以用来存任何key value pair键值对,也就是key1可以用你喜欢的任何关键词,后面的值也可以放自己喜欢的任何值 但是后面这个还是要用hex string

http://string-functions.com/string-hex.aspx 这个页面可以帮忙做转换

The txid of the stream item is returned. Now let’s see that the stream is visible on another node. On the second server: 这个流条目的txid会被返回回来。现在我们看看流在另一个节点上应该是可见的。在第二台服务器上输入

liststreams

(The root stream was in the blockchain by default.) Now we want the second server to subscribe to the stream, then view its contents: (根基流是默认存在区块链中的)现在我们想让第二个服务器订阅流,并查看其内容:

subscribe stream1

liststreamitems stream1

Now we want the second server to be allowed to publish to the stream. On the first server: 现在我们希望允许第二台服务器也发布信息到流上。在第一台服务器上输入:

grant [address2] receive,send 

grant [address2] stream1.write

Note that the address needs both general send/receive permissions for the blockchain, as well as permission to write to this specific stream. Now let’s publish a couple of items on the second server:请注意,该地址需要块的一般发送/接收权限,以及写入此特定流的权限。现在让我们在第二台服务器上发布几个东西:

publish stream1 key1 736f6d65206f746865722064617461

publish stream1 key2 53747265616d732052756c6521

Now let’s query the stream’s contents in many different ways. Back on the first server: 现在让我们用各种不同的方式来查询流的内容。回到第一台服务器上:

subscribe stream1

liststreamitems stream1(should show 3 items)

liststreamkeys stream1(2 keys)

liststreamkeyitems stream1 key1(2 items with this key)

liststreampublishers stream1(2 publishers)

liststreampublisheritems stream11....(2 items by this publisher)

This is just a taste of the ways in which streams can be queried – for more information, please consult the API documentation. 这只是可以查询流的方法的一些例子 - 需要更多信息,请参阅API文档。

7. Round-robin mining 循环挖矿

In this section we’ll start collaborative mining between the nodes. On the first server, run: 在本节中我们将开始在节点之间进行协作挖矿。在第一台服务器上运行:

grant [address2] mine

On the second server, check that two permitted miners are listed: 在第二台服务器上,检查是否列出了两个允许的矿工(第一个是第一台服务器,默认会成为矿工):

listpermissions mine

If you are using MultiChain 1.0 alpha 28 or later, run this on both servers to maximize the degree of miner randomness:

如果您使用的是MultiChain 1.0 alpha 28或更高版本,请在两台服务器上运行以下命令,以最大限度地提高矿工随机性:

setruntimeparam miningturnover 1

Now wait for a couple of minutes, so that a few blocks are mined. (This assumes you left the block time on the default of 15 seconds.) On either server, check the current block height: 现在等待几分钟,以便让几个区块可以成功被挖出。 (假设您的默认时间为15秒。)在任一服务器上,检查当前块的高度:

getinfo

The block height is in the blocks field of the response. Now let’s get information about the last few blocks, beginning with this one:区块高度值位于上述命令返回的的blocks部分中。现在我们来看看最后几个块的信息,用以下命令:

getblock [block-height]

翻译注:上一步拿到的info里面是区块的最大高度,可以填入比最大高度小的任何高度

The address of the miner of each block is in the miner field of the response. In different blocks you should see the two different addresses in this field. 每个矿工的地址会在以上命令返回的miner部分中显示。在不同的区块中,您应该在miner部分中看到两个不同的地址。翻译注:这里多尝试几个不同的区块高度,以验证miner是不是随机的。

8. Now go explore… 基本教程结束,去探索吧~

Congratulations – you have finished the first tutorial! Now you try any of the other tutorials, create blockchains with different parameters or explore the available API commands. You can also install the Explorer or Web Demo to see a graphical interface for your blockchain.

恭喜 - 你已经完成了第一个教程! 现在您可以尝试任何其他教程,创建具有不同参数的区块链,或者探索可用的API命令。 您还可以安装Exploreror 或者 Web Demo 来查看您的区块链的图形界面。

Finally, you may want to subscribe below for updates. And if you have any questions or problems, please ask in the developer Q&A or contact us. 最后,您可能想在下面订阅更新(订阅更新的话到原页面 输入你的邮箱地址)。如果您有任何问题或疑问,请在开发者问答中询问或联系我们。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,088评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,715评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,361评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,099评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 60,987评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,063评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,486评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,175评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,440评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,518评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,305评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,190评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,550评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,880评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,152评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,451评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,637评论 2 335

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,490评论 18 139
  • 在大同,我们游览了云岗石窟,在古城墙上尽兴骑车后,也就刚刚七点的样子,本想简单吃点饭回到宾馆早点休息,计划第二天五...
    春鸣阅读 462评论 0 1
  • 原来我在很久之前就见过你了。
    lamia醒山阅读 159评论 0 0
  • 接叶有多种,开花无异色。含露或低垂,从风时偃仰。 百合刚送来时,有一朵已经盛开,其他几朵还处在含苞待放的状态,每一...
    简的时光阅读 257评论 1 0
  • 快乐就像一个神秘的礼物,人人都追求快乐。谈到快乐你首先想到的是什么?心理学将快乐是一种情绪,是一种精神状态,它指在...
    DQJY阅读 254评论 1 3