賬戶(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 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</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 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 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 签财。有兩種修改方法:
編輯 keosd 配置文件 ~/eosio-wallet/config.ini ,修改屬性:http-server-address = 127.0.0.1:8899
使用命令行參數(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;">
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 !