原文地址:http://www.multichain.com/getting-started/
上一篇說的是基本的下載和安裝漱挚,這一篇要做最基本的入門了榄攀。
翻譯注:自己嘗試翻譯隶债,如果有錯(cuò)希望大神們指正凝赛。源地址可能會(huì)有更新躲履,一切以源地址發(fā)布的命令為主炼幔。有機(jī)會(huì)我也會(huì)繼續(xù)更新鸽心。
凡是原文的命令全部都用框框標(biāo)識(shí)出來了滚局。命令是不翻譯的。本文的兩個(gè)服務(wù)器第一臺(tái)是WINDOWS第二臺(tái)LINUX顽频,截圖里面有一些是WINDOWS的界面藤肢。LINUX機(jī)子全部跟著默認(rèn)命令就好。不需要受到截圖內(nèi)容的影響糯景。
Create and deploy your first private blockchain in minutes?
在幾分鐘內(nèi)創(chuàng)建并部署您的第一個(gè)私有塊鏈
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.
本教程需要兩個(gè)服務(wù)器節(jié)點(diǎn)嘁圈。 如果您還沒有這樣做,請(qǐng)?jiān)诿總€(gè)服務(wù)器上快速下載并安裝MultiChain(翻譯版本看這里)蟀淮。 如果您在Windows上使用MultiChain最住,請(qǐng)閱讀README.txt文件中的Windows注釋,以適應(yīng)以下說明怠惶。
1. Creating a blockchain 創(chuàng)建一個(gè)區(qū)塊鏈
First we will create a new blockchain named chain1. On the first server, run this command:
首先我們要?jiǎng)?chuàng)建一個(gè)名為chain1的新區(qū)塊鏈涨缚。在第一個(gè)服務(wù)器上運(yùn)行以下命令:
multichain-util create chain1
View the blockchain’s default settings (these can also be?modified?but we recommend using the defaults for now): 查看該區(qū)塊鏈的默認(rèn)設(shè)置(這些也可以修改,但我們建議現(xiàn)在使用默認(rèn)設(shè)置):
cat ~/.multichain/chain1/params.dat
Initialize the blockchain, including mining the genesis block:初始化區(qū)塊鏈甚疟,包括挖出源區(qū)塊
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.你應(yīng)該被告知服務(wù)器已經(jīng)啟動(dòng)仗岖,然后幾秒鐘后逃延,源區(qū)塊挖掘成功。你會(huì)被賦予節(jié)點(diǎn)地址轧拄,其他人可以用這個(gè)地址來連接到你的區(qū)塊鏈上揽祥。
地址格式如下:chain1@[ip-address]:[port]
翻譯注:這步產(chǎn)生的地址可以記下來檩电,下面會(huì)用到
2. Connecting to a blockchain 鏈接到一個(gè)區(qū)塊鏈
Now we’ll connect to this blockchain from elsewhere. On the?second server, run the following:現(xiàn)在我們將從其他地方連接到這個(gè)blockchain拄丰。在第二臺(tái)服務(wù)器上,運(yùn)行以下命令:
multichaind chain1@[ip-address]:[port]
翻譯注:這步方括號(hào)里面的內(nèi)容就是剛才上面第一臺(tái)服務(wù)器產(chǎn)生的內(nèi)容俐末×习矗可以手動(dòng)輸入或者發(fā)個(gè)郵件把第一臺(tái)服務(wù)器的地址什么的發(fā)過去。
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.你會(huì)被告知區(qū)塊鏈接成功初始化卓箫,但你沒有連接的權(quán)限载矿。您應(yīng)該還會(huì)看到一條包含屬于節(jié)點(diǎn)的錢包的地址的消息。復(fù)制該地址烹卒。
Back on the first server, add connection permissions for this address: 回到第一臺(tái)服務(wù)器闷盔,為這個(gè)地址(第二臺(tái)服務(wù)器的地址)添加連接許可
multichain-cli chain1 grant [第二臺(tái)服務(wù)器地址] connect
翻譯注:地址很長,可以發(fā)個(gè)郵件什么的把這個(gè)地址送回第一天服務(wù)器旅急。
Now try reconnecting again from the?second server: 現(xiàn)在再回到第二臺(tái)服務(wù)器試一試以下命令逢勾。
multichaind chain1 -daemon
You should be shown a message that the node was started, and it should display this second node’s address. 你會(huì)收到提示信息指示節(jié)點(diǎn)已啟動(dòng),并顯示該第二個(gè)節(jié)點(diǎn)的地址藐吮。(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: 在我們繼續(xù)之前溺拱,讓我們進(jìn)入交互模式,這樣我們每次發(fā)出命令就不需要輸入multichain-cli chain1了谣辞。 在兩個(gè)服務(wù)器上都運(yùn)行:
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: 現(xiàn)在迫摔,區(qū)塊鏈正在兩個(gè)節(jié)點(diǎn)上運(yùn)作,您可以在這兩個(gè)節(jié)點(diǎn)的任意一個(gè)上運(yùn)行本節(jié)中的命令潦闲。獲取一般信息:
getinfo
翻譯注:原文應(yīng)該是在LINUX 系統(tǒng)下測試的結(jié)果攒菠,windows系統(tǒng)下交互模式還不可以用 需要輸入完整的內(nèi)容。 比如windows下輸入(下面所有的命令同理歉闰,需要完整):?
multichain-cli chain1 getinfo
官方給出的給WINDOWS用戶的臨時(shí)解決方案是這樣的:
Use the Linux version of multichain-cli inside Docker to communicate with a node running on Windows (or indeed on Linux). 在運(yùn)行WINDOWS的節(jié)點(diǎn)上裝個(gè)Docker,然后跑LINUX版本的multichain-cli(其實(shí)這樣還是相當(dāng)于跑在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可執(zhí)行文件重命名為m(或者什么都可以不影響)卓起,并使用一個(gè)單字母的區(qū)塊名稱和敬,如c,因此您只需要在每一行之前寫入m c ...... 就行了戏阅。
以下繼續(xù)基于LINUX的正文翻譯昼弟。用WINDOWS機(jī)器的親自行加一下前面的內(nèi)容。
See a list of all available commands:查看所有可用命令的列表:
help
Show all permissions currently assigned: 顯示當(dāng)前分配的所有權(quán)限:
listpermissions
Create a new address in the wallet: 在錢包中創(chuàng)建一個(gè)新地址:
getnewaddress
List all addresses in the wallet: 列出錢包中的所有地址:
getaddresses
Get the parameters of this blockchain (based onparams.datfile): 獲取此區(qū)塊鏈的參數(shù)(基于params.datfile):
getblockchainparams
For each node, get a list of connected peers: 在每個(gè)節(jié)點(diǎn)上奕筐,嘗試獲取連接的對(duì)等節(jié)點(diǎn)的列表:
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. 如果您只對(duì)用區(qū)塊鏈做數(shù)據(jù)存取感興趣舱痘,而不是用區(qū)塊鏈表示資產(chǎn)交易变骡,請(qǐng)直接跳到第6節(jié)。
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: 現(xiàn)在我們要?jiǎng)?chuàng)建一種新的資產(chǎn)并將其在節(jié)點(diǎn)之間發(fā)送芭逝。在第一個(gè)服務(wù)器上塌碌,獲取有權(quán)創(chuàng)建資產(chǎn)的地址:
listpermissions issue?
翻譯注:這步要復(fù)制產(chǎn)生的地址[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: 現(xiàn)在我們將在這個(gè)節(jié)點(diǎn)上創(chuàng)建一種有1000個(gè)單位的新資產(chǎn),每個(gè)單位可以再細(xì)分為100個(gè)部分旬盯,發(fā)送給自己:
issue [address1] asset1 1000 0.01
翻譯注:[address1]是第一臺(tái)上面一步產(chǎn)生的地址
On both servers, verify that the asset namedasset1is listed: 在兩個(gè)服務(wù)器上台妆,驗(yàn)證名為"asset1“的資產(chǎn)是否列出:
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: 現(xiàn)在檢查每個(gè)服務(wù)器上的資產(chǎn)余額。第一個(gè)服務(wù)器應(yīng)該顯示擁有1000的余額胖翰,第二個(gè)服務(wù)器應(yīng)該顯示沒有資產(chǎn):
gettotalbalances
On the first server, now try sending 100 units of the asset to the second server’s wallet: 現(xiàn)在在第一臺(tái)服務(wù)器上接剩,嘗試將100個(gè)新資產(chǎn)發(fā)送到第二臺(tái)服務(wù)器的錢包:
sendasset [address2] asset1 100
翻譯注:[address2]是第二臺(tái)服務(wù)器的地址
You should see an error that the address does not have receive permissions. So it’s time to add receive and send permissions: 您應(yīng)該看到地址沒有接收權(quán)限的錯(cuò)誤。所以現(xiàn)在是添加接收和發(fā)送權(quán)限的時(shí)候了:
grant [address2] receive,send
翻譯注:[address2]是第二臺(tái)服務(wù)器的地址(上面第二步的時(shí)候獲取的地址)萨咳,用第一臺(tái)服務(wù)器修改第二臺(tái)的權(quán)限
Now try sending the asset again, and it should go through:現(xiàn)在再試一次發(fā)送資產(chǎn),應(yīng)該可以通過了(成功的話會(huì)看到一串新的ID):
sendasset [address2] asset1 100
翻譯注:[address2]是第二臺(tái)服務(wù)器的地址
Now check the asset balances on each server, including transactions with zero confirmations. They should be900and100respectively: 現(xiàn)在檢查每個(gè)服務(wù)器上的資產(chǎn)余額培他,包括零確認(rèn)的交易鹃两。他們應(yīng)該分別是是900(第一臺(tái))和100(第二臺(tái)):
gettotalbalances 0
You can also view the transaction on each node and see how it affected their balances:您還可以查看每個(gè)節(jié)點(diǎn)上的交易,并查看它們是如何影響其余額
listwallettransactions 1
翻譯注:這里的1就代表你要看最近的一筆交易靶壮。如果你多做幾次交易操作怔毛,想看到更多的,可以更換這個(gè)數(shù)值腾降。
5. Transaction metadata 交易元數(shù)據(jù)
In this section we’ll create a transaction that sends 125 units of asset1 along with some metadata. On the first server, run: 在本節(jié)中拣度,我們將創(chuàng)建一個(gè)交易,發(fā)送125個(gè)單位的asset1(上文創(chuàng)建的新資產(chǎn))以及一些元數(shù)據(jù)(后面那一串?dāng)?shù)字)螃壤。在第一臺(tái)服務(wù)器上運(yùn)行:
sendwithdata [address2] '{"asset1":125}' 48692066726f6d204d756c7469436861696e21
這一步會(huì)產(chǎn)生一個(gè)交易序列號(hào)(transaction ID)抗果,要存下來
翻譯注:[address2]是第二臺(tái)服務(wù)器的地址,489...這些數(shù)據(jù)就是元數(shù)據(jù)(必須是hex string) 可以用這個(gè)網(wǎng)站來轉(zhuǎn)換普通的字符串?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: 現(xiàn)在可以在下面的第二個(gè)服務(wù)器上檢查此交易:
getwallettransactiona [transaction ID]
需要輸入上一步產(chǎn)生的交易序列號(hào)
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. 在此命令的輸出中冤馏,您應(yīng)該看到余額欄(balance field)顯示了傳入的125個(gè)單位的asset1同時(shí)數(shù)據(jù)欄包含了我們添加的十六進(jìn)制元數(shù)據(jù)的數(shù)據(jù)字段。
6. Streams 流
Now let’s create a stream, which can be used for general data storage and retrieval. On the?first server: 現(xiàn)在我們創(chuàng)建一個(gè)流寄啼,流可以用于一般的數(shù)據(jù)存儲(chǔ)和檢索逮光。在第一臺(tái)服務(wù)器上輸入:
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表示流只能由具有明確權(quán)限的用戶寫入。讓我們查看一下它的權(quán)限:
listpermissions stream1.*
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: 所以現(xiàn)在只有第一臺(tái)服務(wù)器有能力寫入流墩划,以及管理它涕刚。我們用key1來發(fā)布一些東西:
publish stream1 key1 73747265616d2064617461
翻譯注:stream可以用來存任何key value pair鍵值對(duì),也就是key1可以用你喜歡的任何關(guān)鍵詞乙帮,后面的值也可以放自己喜歡的任何值 但是后面這個(gè)還是要用hex string
http://string-functions.com/string-hex.aspx 這個(gè)頁面可以幫忙做轉(zhuǎn)換
The txid of the stream item is returned. Now let’s see that the stream is visible on another node. On the?second server: 這個(gè)流條目的txid會(huì)被返回回來《拍現(xiàn)在我們看看流在另一個(gè)節(jié)點(diǎn)上應(yīng)該是可見的。在第二臺(tái)服務(wù)器上輸入
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: (根基流是默認(rèn)存在區(qū)塊鏈中的)現(xiàn)在我們想讓第二個(gè)服務(wù)器訂閱流,并查看其內(nèi)容:
subscribe stream1
liststreamitems stream1
Now we want the second server to be allowed to publish to the stream. On the first server: 現(xiàn)在我們希望允許第二臺(tái)服務(wù)器也發(fā)布信息到流上驾茴。在第一臺(tái)服務(wù)器上輸入:
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:請(qǐng)注意盼樟,該地址需要塊的一般發(fā)送/接收權(quán)限,以及寫入此特定流的權(quán)限⌒庵粒現(xiàn)在讓我們?cè)诘诙_(tái)服務(wù)器上發(fā)布幾個(gè)東西:
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: 現(xiàn)在讓我們用各種不同的方式來查詢流的內(nèi)容晨缴。回到第一臺(tái)服務(wù)器上:
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. 這只是可以查詢流的方法的一些例子 - 需要更多信息裹赴,請(qǐng)參閱API文檔喜庞。
7. Round-robin mining 循環(huán)挖礦
In this section we’ll start collaborative mining between the nodes. On the first server, run: 在本節(jié)中我們將開始在節(jié)點(diǎn)之間進(jìn)行協(xié)作挖礦。在第一臺(tái)服務(wù)器上運(yùn)行:
grant [address2] mine
On the second server, check that two permitted miners are listed: 在第二臺(tái)服務(wù)器上棋返,檢查是否列出了兩個(gè)允許的礦工(第一個(gè)是第一臺(tái)服務(wù)器延都,默認(rèn)會(huì)成為礦工):
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或更高版本,請(qǐng)?jiān)趦膳_(tái)服務(wù)器上運(yùn)行以下命令睛竣,以最大限度地提高礦工隨機(jī)性:
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: 現(xiàn)在等待幾分鐘晰房,以便讓幾個(gè)區(qū)塊可以成功被挖出。 (假設(shè)您的默認(rèn)時(shí)間為15秒射沟。)在任一服務(wù)器上殊者,檢查當(dāng)前塊的高度:
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:區(qū)塊高度值位于上述命令返回的的blocks部分中。現(xiàn)在我們來看看最后幾個(gè)塊的信息验夯,用以下命令:
getblock [block-height]
翻譯注:上一步拿到的info里面是區(qū)塊的最大高度猖吴,可以填入比最大高度小的任何高度
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. 每個(gè)礦工的地址會(huì)在以上命令返回的miner部分中顯示。在不同的區(qū)塊中挥转,您應(yīng)該在miner部分中看到兩個(gè)不同的地址海蔽。翻譯注:這里多嘗試幾個(gè)不同的區(qū)塊高度,以驗(yàn)證miner是不是隨機(jī)的绑谣。
8. Now go explore… 基本教程結(jié)束党窜,去探索吧~
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.
恭喜 - 你已經(jīng)完成了第一個(gè)教程! 現(xiàn)在您可以嘗試任何其他教程借宵,創(chuàng)建具有不同參數(shù)的區(qū)塊鏈幌衣,或者探索可用的API命令。 您還可以安裝Exploreror 或者 Web Demo 來查看您的區(qū)塊鏈的圖形界面壤玫。
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. 最后豁护,您可能想在下面訂閱更新(訂閱更新的話到原頁面 輸入你的郵箱地址)。如果您有任何問題或疑問欲间,請(qǐng)?jiān)陂_發(fā)者問答中詢問或聯(lián)系我們择镇。