2018-09-08

賬戶(hù)與錢(qián)包


重要提醒:該教程面向私有的單節(jié)點(diǎn)測(cè)試網(wǎng)絡(luò),但稍加修改也能在公共網(wǎng)絡(luò)上使用支竹。該教程目的是針對(duì)發(fā)者對(duì)錢(qián)包字逗,密鑰以及賬戶(hù)的一個(gè)底層的教學(xué),以便更好地理解 EOSIO醒陆。


前言

教程受眾

本教程針適用于開(kāi)發(fā)者瀑构,可以幫助他們了解學(xué)習(xí):

  • 錢(qián)包和賬戶(hù)管理

  • 如何使用 cleos 管理錢(qián)包和賬戶(hù)

  • 錢(qián)包和賬戶(hù)管理這些 EOSIO 組件是如何進(jìn)行交互的

關(guān)于 cleos 的其余信息可以在Cleos 命令參考中獲取。


你將學(xué)到什么

  • 創(chuàng)建和管理錢(qián)包以及密鑰

  • 通過(guò) cleos 命令行使用創(chuàng)建的錢(qián)包與區(qū)塊鏈進(jìn)行交互

  • 如何使用 cleos 創(chuàng)建賬戶(hù)

  • 通過(guò) cleos刨摩,keosd 寺晌,nodeos 之間的交互,對(duì)發(fā)布到區(qū)塊鏈上的內(nèi)容進(jìn)行簽名澡刹。


EOSIO賬戶(hù)和錢(qián)包概念

下圖展示了EOSIO中賬戶(hù)和錢(qián)包之間的一個(gè)簡(jiǎn)單概念圖呻征。

可以把錢(qián)包視為一個(gè)加密編碼的公私鑰對(duì)倉(cāng)庫(kù)。錢(qián)包以及其中的內(nèi)容由 keosd 管理罢浇,通過(guò) cleos 訪(fǎng)問(wèn)錢(qián)包陆赋。

可以把賬戶(hù)視為一個(gè)鏈上標(biāo)識(shí)符,其具有與之相關(guān)的訪(fǎng)問(wèn)權(quán)限(例如一個(gè)安全主體)嚷闭。nodeos 管理賬戶(hù)的發(fā)布以及鏈上賬戶(hù)相關(guān)的操作攒岛。nodeos 的賬戶(hù)管理能力也能通過(guò) cleos 進(jìn)行訪(fǎng)問(wèn)。

賬戶(hù)和錢(qián)包之間沒(méi)有任何內(nèi)在聯(lián)系凌受。賬戶(hù)對(duì)錢(qián)包一無(wú)所知阵子,反之亦然思杯。相應(yīng)地胜蛉,nodeos 和 keosd 之間也沒(méi)有任何內(nèi)在聯(lián)系挠进。它們的基礎(chǔ)功能完全不同。(話(huà)雖如此誊册,但也有一些部署配置模糊了這種區(qū)別领突。但這個(gè)超出了本教程的范圍,所以這里不涉及案怯。)

錢(qián)包和賬戶(hù)有交集的地方就是即需要簽名的場(chǎng)景君旦,如對(duì)交易進(jìn)行簽名。錢(qián)包有利于以一種安全的模式獲取簽名嘲碱, 該模式將密鑰鎖定加密存儲(chǔ)在本地金砍。這是 cleos 就是充當(dāng) keosd 和 nodeos 之間的一個(gè)中間人,keosd 負(fù)責(zé)檢索密鑰麦锯,nodeos 負(fù)責(zé)需要使用這些密鑰簽名的賬戶(hù)相關(guān)(以及其他)操作恕稠。


創(chuàng)建并管理錢(qián)包

進(jìn)入 EOSIO 安裝目錄,輸入:

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n58" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
$ cleos wallet create --to-console
Creating wallet: default
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"這里是錢(qián)包對(duì)應(yīng)的 master password扶欣! "</pre>

現(xiàn)在名為 default 的錢(qián)包已經(jīng)創(chuàng)建成功鹅巍,并返回一個(gè) master password,需要妥善保管好該密碼料祠,往后解鎖(解密)錢(qián)包文件需要用到骆捧。

這個(gè)錢(qián)包對(duì)應(yīng)的文件為 default.wallet 。keosd 默認(rèn)會(huì)將錢(qián)包文件存儲(chǔ)在 ~/eosio-wallet 文件夾中髓绽。錢(qián)包數(shù)據(jù)文件夾的位置可以通過(guò)命令行參數(shù) --wallet-dir 來(lái)指定敛苇。


管理多個(gè)錢(qián)包以及錢(qián)包命名

cleos 能夠管理多個(gè)錢(qián)包。每個(gè)單獨(dú)的錢(qián)包都有不同的密碼來(lái)保護(hù)顺呕。以下例子我們創(chuàng)建另一個(gè)錢(qián)包并且演示如何使用參數(shù) -n 參數(shù)進(jìn)行命名接谨。

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n67" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
$ cleos wallet create -n garyWallet --to-console
Creating wallet: garyWallet
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"A MASTER PASSWORD"</pre>

下面我們確認(rèn)一下自命名的錢(qián)包是否已創(chuàng)建:

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n70" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
$ cleos wallet list
Wallets:
[
"default",
"garyWallet *"
]</pre>

其中有(*****)標(biāo)識(shí)的錢(qián)包標(biāo)識(shí)其當(dāng)前沒(méi)有鎖定,當(dāng)使用 create wallet 命令時(shí)塘匣,為了操作方便脓豪,默認(rèn)所創(chuàng)建的錢(qián)包屬于解鎖狀態(tài)。

我們?cè)囋?wallet lock 命令:

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n75" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
$ cleos wallet lock -n garyWallet
Locked: garyWallet</pre>

我們?cè)俅螆?zhí)行 wallet list 命令忌卤,就會(huì)看到所有錢(qián)包都以鎖定:

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n78" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
$ cleos wallet list
Wallets:
[
"default",
"garyWallet"
]</pre>

執(zhí)行 wallet list 命令扫夜,附帶 - n 參數(shù)指定錢(qián)包名稱(chēng)以及 - -password 參數(shù)對(duì)應(yīng)錢(qián)包的密碼:

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n81" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
$ cleos wallet unlock -n periwinkle --password YOUR_MASTER_KEY</pre>

命令行窗口會(huì)輸出提示錢(qián)包已解鎖,同時(shí)你也可以調(diào)用命令檢查一遍:

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n84" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
Unlocked: 'periwinkle'
$ cleos wallet list
Wallets:
[
"default *",
"garyWallet *"
]</pre>

上文我們說(shuō)過(guò)驰徊,cleos 會(huì)自動(dòng)啟動(dòng) kesod 進(jìn)程◇源常現(xiàn)在我們停止 keosd 進(jìn)程:

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n87" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
ps aux|grep kesod
kill keosd的進(jìn)程pid
$ cleos wallet list
wallets:
[]</pre>

上面命令中,我們先 kill keosd進(jìn)程棍厂,然后再執(zhí)行錢(qián)包查詢(xún)命令颗味,而且這時(shí)候 keosd 也由于cleos 命令的調(diào)用自動(dòng)啟動(dòng)了 ,但是卻沒(méi)有查出任何錢(qián)包牺弹,這是為什么呢浦马?

在對(duì)錢(qián)包進(jìn)行操作之前(包括 list 操作)时呀,需要先打開(kāi)錢(qián)包(open)。當(dāng)你殺掉 keosd 進(jìn)程時(shí)晶默,錢(qián)包會(huì)被加鎖谨娜。當(dāng) keosd 進(jìn)程重啟時(shí),錢(qián)包并不會(huì)自動(dòng)打開(kāi)磺陡。執(zhí)行下面命令打開(kāi)錢(qián)包:

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n92" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
cleos wallet open /* 同樣 -n 指定具體的錢(qián)包*/ cleos wallet list
Wallets:
[
"default"
]</pre>

現(xiàn)在趴梢,我們已經(jīng)掌握了如果創(chuàng)建過(guò)個(gè)錢(qián)包,并通過(guò) cleos 命令與之交互了币他。但是坞靶,一個(gè)空錢(qián)包并沒(méi)有什么作用。接下來(lái)我們來(lái)學(xué)習(xí)如何將密鑰導(dǎo)入到錢(qián)包中蝴悉。


生成 EOSIO 密鑰對(duì)并導(dǎo)入

生成 EOSIO 密鑰對(duì)有多種方式滩愁,但本教程偏向于在 cleos 中使用 create Key 命令。

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n99" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
cleos create key --to-console Private key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Public key: EOSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX cleos create key --to-console
Private key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Public key: EOSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</pre>

使用 --file filename 參數(shù)替代 --to-console辫封,可以將你的密鑰對(duì)寫(xiě)入本地文件硝枉。

現(xiàn)在我們生成了兩個(gè) EOSIO 鍵值對(duì)。但目前它們只是一些隨機(jī)的鍵值對(duì)且沒(méi)有任何權(quán)利倦微。

接下來(lái)妻味,我們將導(dǎo)入私鑰(private key)到 default 錢(qián)包中。我們會(huì)執(zhí)行 wallet import 兩次欣福,使用前面生成的兩個(gè)私鑰责球。(如果錢(qián)包鎖定了,得先解鎖)

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n106" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
cleos wallet unlock password: Unlocked: default cleos wallet import --private-key XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
imported private key for: EOS6FzRdKEfSozzvjRsAWhvbSoCZ8JWD4sHm16gT21tQ3viK4sajQ
$ cleos wallet import --private-key XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
imported private key for: EOS65UPCFro71rAUudMZEC5VZRnk65KEb364jBUEpEt7tZbnrwJLT</pre>

我們可以檢查哪些密鑰已經(jīng)被裝載到錢(qián)包中了拓劝,使用 wallet keys 只能顯示公鑰雏逾,使用 wallet private_keys 公鑰私鑰都顯示,這兩個(gè)命令只會(huì)列出已解鎖的錢(qián)包郑临。

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n109" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
cleos wallet keys [ "EOS6....", "EOS3...." ] cleos wallet private_keys --password YOUR WALLET PASSWORD
password:
[[
"EOS6....",
"5KQwr..."
],
[
"EOS3....",
"5Ks0e..."
]
]</pre>

錢(qián)包文件本身是加密的栖博,所以當(dāng)錢(qián)包已鎖定時(shí)能起到保護(hù)密鑰的作用。訪(fǎng)問(wèn)一個(gè)已鎖定的錢(qián)包中的密鑰需要錢(qián)包的密碼厢洞。


錢(qián)包備份

現(xiàn)在你的錢(qián)包已經(jīng)有了密鑰對(duì)仇让,就需要養(yǎng)成錢(qián)包備份的好習(xí)慣,例如備份到 USB 以及其他存儲(chǔ)媒介等躺翻,防止錢(qián)包文件丟失丧叽。錢(qián)包文件是經(jīng)過(guò)了高度加密的,如果沒(méi)有錢(qián)包密碼公你,錢(qián)包內(nèi)的密鑰信息幾乎是無(wú)法訪(fǎng)問(wèn)的踊淳。

錢(qián)包數(shù)據(jù)默認(rèn)存儲(chǔ)在 ~/eosio-wallet 文件夾中。(或者在你之前創(chuàng)建錢(qián)包指定的 --data-dir 參數(shù)路徑中 )

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n118" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
$ cd ~/eosio-wallet && ls
config.ini default.wallet garyWallet.wallet wallet.lock</pre>


創(chuàng)建一個(gè)賬戶(hù)

要執(zhí)行鏈上操作需要有一個(gè)賬戶(hù)陕靠。我們使用 cleos 向 nodeos 請(qǐng)求創(chuàng)建賬戶(hù)并發(fā)布到區(qū)塊鏈上迂尝。在本教程中脱茉,我們需要啟動(dòng) nodeos 進(jìn)程。下面的命令將會(huì)啟動(dòng)一個(gè)單節(jié)點(diǎn)測(cè)試網(wǎng)絡(luò)雹舀。關(guān)于安裝本地環(huán)境的詳細(xì)內(nèi)容請(qǐng)看創(chuàng)建并啟動(dòng)一個(gè)單節(jié)點(diǎn)測(cè)試網(wǎng)絡(luò)芦劣。

在本教程中粗俱,我們需要同時(shí)運(yùn)行 keosd 和 nodeos 進(jìn)程说榆。目前這兩個(gè)進(jìn)程的默認(rèn)端口都是 8888。本教程為了簡(jiǎn)化運(yùn)行 nodeos 的步驟寸认,我們將 keosd 的端口 改為8899 签财。有兩種修改方法:

  1. 編輯 keosd 配置文件 ~/eosio-wallet/config.ini ,修改屬性:http-server-address = 127.0.0.1:8899

  2. 使用命令行參數(shù)啟動(dòng) keosd --http-server-address=localhost:8899

平兄使用第二種方式:

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n134" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
pkill keosd nohup keosd --http-server-address=localhost:8899 > /dev/null 2>&1 &
$ cleos --wallet-url=http://localhost:8899 wallet unlock /* keosd 重啟需要解鎖 */</pre>

接下來(lái)啟動(dòng) nodeos 偏塞,新建一個(gè)終端窗口唱蒸,運(yùn)行:

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n137" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
$ nohup nodeos -e -p eosio --eosio::chain_api_plugin --plugin eosio::history_api_plugin > /dev/null 2>&1 &
[1] 21244</pre>

在本實(shí)例中,eosio 是授權(quán)賬戶(hù)灸叼,區(qū)塊鏈上的操作必須使用與 eosio 賬戶(hù)關(guān)聯(lián)的密鑰進(jìn)行簽名神汹。eosio 賬戶(hù)是一個(gè)特殊的賬戶(hù),用于引導(dǎo) EOSIO 節(jié)點(diǎn)古今。該賬戶(hù)的密鑰可以在 nodeos 進(jìn)程的配置文件中找到屁魏,linux 環(huán)境下位置為:~/.local/share/eosio/nodeos/config/config.ini

我們需要把賬戶(hù) eosio 的私鑰導(dǎo)入到 default 錢(qián)包中捉腥,以便下文創(chuàng)建新賬戶(hù)氓拼。

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n142" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
$ cleos wallet import --private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3</pre>

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n143" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
$ cleos create account authorizing_account NEW_ACCOUNT OWNER_KEY ACTIVE_KEY</pre>

  • authorizing_account :為新建的賬戶(hù)提供資金的賬戶(hù)。

  • new_account :新建賬戶(hù)名抵碟。

  • owner_key :所有權(quán)權(quán)限公鑰桃漾。

  • active_key :管理權(quán)權(quán)限公鑰。

現(xiàn)在我們創(chuàng)建一個(gè)新的賬戶(hù):

<pre class="md-fences md-end-block" lang="shell" contenteditable="false" cid="n159" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: Consolas, "Liberation Mono", Courier, monospace; font-size: 0.9em; white-space: pre; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 8px 1em 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
$ cleos --wallet-url=http://localhost:8899 create account eosio eospingxiong 所有權(quán)公鑰 支配權(quán)公鑰
executed transaction: a64bf59e0c0a75ba0a4a408af1e7f61da27958ef8952d81329bff3795fed288b 200 bytes 66641 us

eosio <= eosio::newaccount {"creator":"eosio","name":"eospingxiong","owner":{"threshold":1,"keys":[{"key":"EOS65UPCFro71rAUudMZ...

warning: transaction executed locally, but may not be confirmed by the network yet ] </pre>

如果看到以上的輸出拟逮,恭喜你撬统,you make it !

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市敦迄,隨后出現(xiàn)的幾起案子宪摧,更是在濱河造成了極大的恐慌,老刑警劉巖颅崩,帶你破解...
    沈念sama閱讀 216,402評(píng)論 6 499
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件几于,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡沿后,警方通過(guò)查閱死者的電腦和手機(jī)沿彭,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,377評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)尖滚,“玉大人喉刘,你說(shuō)我怎么就攤上這事瞧柔。” “怎么了睦裳?”我有些...
    開(kāi)封第一講書(shū)人閱讀 162,483評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵造锅,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我廉邑,道長(zhǎng)哥蔚,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,165評(píng)論 1 292
  • 正文 為了忘掉前任蛛蒙,我火速辦了婚禮糙箍,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘牵祟。我一直安慰自己深夯,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,176評(píng)論 6 388
  • 文/花漫 我一把揭開(kāi)白布诺苹。 她就那樣靜靜地躺著咕晋,像睡著了一般。 火紅的嫁衣襯著肌膚如雪收奔。 梳的紋絲不亂的頭發(fā)上掌呜,一...
    開(kāi)封第一講書(shū)人閱讀 51,146評(píng)論 1 297
  • 那天,我揣著相機(jī)與錄音,去河邊找鬼。 笑死乐横,一個(gè)胖子當(dāng)著我的面吹牛据悔,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 40,032評(píng)論 3 417
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了汰蓉?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 38,896評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤棒卷,失蹤者是張志新(化名)和其女友劉穎顾孽,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體比规,經(jīng)...
    沈念sama閱讀 45,311評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡若厚,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,536評(píng)論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了蜒什。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片测秸。...
    茶點(diǎn)故事閱讀 39,696評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出霎冯,到底是詐尸還是另有隱情铃拇,我是刑警寧澤,帶...
    沈念sama閱讀 35,413評(píng)論 5 343
  • 正文 年R本政府宣布沈撞,位于F島的核電站慷荔,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏缠俺。R本人自食惡果不足惜显晶,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,008評(píng)論 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望晋修。 院中可真熱鬧吧碾,春花似錦凰盔、人聲如沸墓卦。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,659評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)落剪。三九已至,卻和暖如春尿庐,著一層夾襖步出監(jiān)牢的瞬間忠怖,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,815評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工抄瑟, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留凡泣,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,698評(píng)論 2 368
  • 正文 我出身青樓皮假,卻偏偏與公主長(zhǎng)得像鞋拟,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子惹资,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,592評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容