第5課 EOS環(huán)境搭建入門(私鏈節(jié)點(diǎn)-錢包-密鑰-賬號)

1橄杨,摘要

【本文目標(biāo)】
通過本文實(shí)踐秘症,能在已編譯的EOS V1.0.5版本環(huán)境上,完成私鏈節(jié)點(diǎn)啟動(dòng)式矫,錢包創(chuàng)建乡摹,密鑰導(dǎo)入和賬號創(chuàng)建等內(nèi)容。
【前置條件】
你已完成了EOS編譯采转,編譯測試成功聪廉。未完成的可參考《第4課 如何在UBUNTU虛擬機(jī)上編譯EOS完成環(huán)境搭建?》完成相關(guān)配置故慈。
【技術(shù)收獲】
1)EOS的節(jié)點(diǎn)板熊,錢包,密鑰惯悠,賬號的概念和理解
2)EOS錢包/賬號的建立和遇到的問題分析及解決方法
【說明】
EOS版本還沒有穩(wěn)定下來邻邮,即使完成了V1.0.2版本環(huán)境搭建的人竣况,到V1.0.5時(shí)還是摔在了坑里克婶。輝哥通過踩坑分析給大家提供盡可能多的知識和解決思路,大家在V1.0.5以后的版本部署可參考文章和以錯(cuò)誤關(guān)鍵字搜索官網(wǎng)的issue網(wǎng)址獲取更多知識丹泉。

2. EOSIO總體框架

EOSIO有多個(gè)程序模塊組成情萤,經(jīng)常會(huì)用到的有以下三個(gè)模塊:

  • nodeos - EOSIO核心模塊,用于啟動(dòng)eosio服務(wù)摹恨,在后臺運(yùn)行筋岛,啟動(dòng)時(shí)可以添加多種插件plugin。
  • cleos - 命令行界面錢包工具晒哄,見《EOS命令行界面錢包》睁宰,位于eos/build/programs/cleos/cleos
  • keosd - 管理錢包的各種組件,默認(rèn)情況下寝凌,keosd將隨cleos一起啟動(dòng)裕偿。位于eos/build/programs/keosd

下圖是上面三個(gè)工具的關(guān)系:


另外洗鸵,還有智能合約的編譯工具eosiocpp

3. EOS系統(tǒng)中錢包,密鑰對花椭,賬號,智能合約的關(guān)系

相對其他區(qū)塊鏈公鏈趣兄,EOS系統(tǒng)的組合關(guān)系比較自由木羹,也帶來了理解上的困難。輝哥結(jié)合自己的理解峰锁,以中國大地上人們最關(guān)系的房子為例萎馅,做比喻介紹。
1) 錢包是土豪房東
土豪可以有很多的房子和各種開門的鑰匙虹蒋。上海這個(gè)城市有很多個(gè)土豪房東糜芳,所以一個(gè)節(jié)點(diǎn)可以創(chuàng)建多個(gè)錢包拣技。

cleos wallet create ${參數(shù)}

2)鑰匙用來打開房東門的。
鑰匙分為私鑰和公鑰耍目。公鑰是別人可以看到的膏斤,例如下面圖片是土豪家的橙色鑰匙包,是專門用來存放仁恒濱江的大平層房子鑰匙的邪驮,私鑰是鑰匙包里面實(shí)際開門的鑰匙莫辨。
你拿到鑰匙包沒有用的,你得拿到鑰匙盒里面的私鑰才可以打開土豪家房子大門毅访。
土豪房東可以把很多的房子配成一樣的鎖沮榜,用一對公鑰/私鑰來開門,也可以不同的房子不同的鑰匙喻粹。

cleos wallet import ${參數(shù)} 私鑰

3) 賬戶是房子
房東可以給多個(gè)房子配一對鑰匙(鑰匙包和鑰匙)蟆融,也可以不同房子配不同鑰匙。
另外守呜,一個(gè)房子可以用2把鑰匙打開型酥,一把是owner鑰匙對,一把是active鑰匙對查乒。
房子的owner鑰匙地址表示為房東的公鑰弥喉,表示主人產(chǎn)權(quán)歸屬,用它對應(yīng)的私鑰可以打開房子玛迄,這個(gè)鑰匙包是房東連小姨子也不會(huì)給的由境;
房子的active鑰匙對表示為房客的公鑰,表示該用戶的私鑰可以打開房子蓖议,房子出租后虏杰,房東就把這個(gè)鑰匙包給租客了;

cleos create account 節(jié)點(diǎn) 賬戶名 Owner的公鑰 Active的公鑰

4. 搭建實(shí)操

搭建實(shí)操的流程圖如下勒虾。


4. 1 啟動(dòng)私鏈

1) 啟動(dòng)keosd

keosd --http-server-address=127.0.0.1:8900

命令行界面錢包程序?yàn)?keosd,位于 eos/build/programs/keosd 路徑下纺阔,用于存儲交易簽名的私鑰。keosd在本地節(jié)點(diǎn)上運(yùn)行从撼,并將私鑰保存在本地節(jié)點(diǎn)上州弟。

默認(rèn)情況下,keosd會(huì)在目錄 ~/eosio-wallet 中生成一個(gè)基礎(chǔ)的配置文件 config.ini低零。該配置文件中的wallet-dir指定了錢包文件存放目錄婆翔。

另外,在運(yùn)行命令行錢包時(shí)掏婶,可通過配置命令行參數(shù) --config-dir指定config.ini配置文件的目錄啃奴。該配置文件中保存用于接入http鏈接的服務(wù)器配置http-server-address參數(shù),以及其他用于資源共享的配置參數(shù)雄妥。

默認(rèn)情況下最蕾,keosd將錢包文件保存在 ~/eosio-wallet 目錄下依溯,錢包文件名為:<wallet-name>.wallet。例如瘟则,默認(rèn)錢包文件名為 default.wallet黎炉。當(dāng)建立了其他錢包后,在該目錄下會(huì)分別建立每個(gè)錢包文件醋拧,例如當(dāng)建立了一個(gè)名稱為"duncanwang"的錢包慷嗜,會(huì)生成一個(gè)錢包文件duncanwang.wallet。錢包文件可以通過命令行參數(shù)--data-dir存放在指定的目錄中丹壕。

【預(yù)警】從V1.0.5開始庆械,發(fā)現(xiàn)要先運(yùn)行keosd后在運(yùn)行nodeos才可以創(chuàng)建錢包。

成功輸出結(jié)果如下:

duncanwang@duncanwang:~$ keosd --http-server-address=127.0.0.1:8900
3861ms thread-0   wallet_plugin.cpp:39          plugin_initialize    ] initializing wallet plugin
3862ms thread-0   http_plugin.cpp:290           plugin_initialize    ] configured http to listen on 127.0.0.1:8900
3863ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/keosd/stop
3863ms thread-0   http_plugin.cpp:331           plugin_startup       ] start listening for http requests
3865ms thread-0   wallet_api_plugin.cpp:73      plugin_startup       ] starting wallet_api_plugin
3865ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/wallet/create
3865ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/wallet/create_key
3865ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/wallet/get_public_keys
3865ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/wallet/import_key
3865ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/wallet/list_keys
3865ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/wallet/list_wallets
3865ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/wallet/lock
3865ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/wallet/lock_all
3865ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/wallet/open
3865ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/wallet/remove_key
3865ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/wallet/set_timeout
3865ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/wallet/sign_digest
3866ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/wallet/sign_transaction
3866ms thread-0   http_plugin.cpp:377           add_handler          ] add api url: /v1/wallet/unlock
75115ms thread-0   wallet.cpp:223                save_wallet_file     ] saving wallet to file /home/duncanwang/eosio-wallet/./duncanwang.wallet

【問題】關(guān)機(jī)后重新啟動(dòng)NODEOS菌赖,會(huì)有以下錯(cuò)誤提示缭乘。

duncanwang@duncanwang:~/eos/build/programs/nodeos$ ./nodeos -e -p eosio --plugin eosio::wallet_plugin --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --replay-blockchain
1983994ms thread-0   wallet_plugin.cpp:39          plugin_initialize    ] initializing wallet plugin
1983994ms thread-0   chain_plugin.cpp:208          plugin_initialize    ] initializing chain plugin
1983996ms thread-0   chain_plugin.cpp:337          plugin_initialize    ] Replay requested: deleting state database
CHAINBASE:   Failed to pin chainbase shared memory (of size 1024 MB) in RAM. Performance degradation is possible.
1984049ms thread-0   main.cpp:123                  main                 ] database dirty flag set (likely due to unclean shutdown): replay required

【解決方法】
進(jìn)入'~/.local/share/eosio/nodeos' 目錄,刪除data文件夾琉用。
重新運(yùn)行即可成功堕绩。

duncanwang@duncanwang:~/eos/build/programs/nodeos$ cd ~/.local/share/eosio/nodeos
duncanwang@duncanwang:~/.local/share/eosio/nodeos$ ls
config  data
duncanwang@duncanwang:~/.local/share/eosio/nodeos$ rm -r -f data

2) 啟動(dòng)私鏈
在新的命令行窗口輸入以下命令。

cd ~/eos/build/programs/nodeos
./nodeos -e -p eosio --plugin eosio::wallet_plugin --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --replay-blockchain

參數(shù)說明:
1) -e
enable-stale-production辕羽,開啟后逛尚,即使鏈過時(shí)了,也能產(chǎn)生區(qū)塊
2) -p eosio
producer-name刁愿,生產(chǎn)者的名字,這里指定為eosio
3) --plugin eosio::wallet_plugin
在啟動(dòng)nodeos時(shí)到逊,需要添加參數(shù)eosio::wallet_plugin铣口,否則的話,每次節(jié)點(diǎn)重啟觉壶,之前創(chuàng)建的錢包脑题,賬號都不會(huì)加載進(jìn)來。
4)--plugin eosio::chain_api_plugin

5) --plugin eosio::history_api_plugin
記錄執(zhí)行過程铜靶。
7) --replay-blockchain
--replay-blockchain表示清除數(shù)據(jù)庫內(nèi)鏈的狀態(tài)叔遂,重新運(yùn)行,它會(huì)導(dǎo)致重新啟動(dòng)時(shí)先讀取之前的區(qū)塊進(jìn)行加載争剿。
【注意】 節(jié)點(diǎn)關(guān)閉后已艰,錢包將會(huì)被加鎖。重新啟動(dòng)nodeos后蚕苇,需要使用open命令打開錢包哩掺,然后使用unlock命令解鎖錢包。
例如:

duncanwang@duncanwang:~/eos$ cleos wallet unlock -n duncanwang
password: Unlocked: duncanwang

輸入nodes -help可以看到所有參數(shù)的幫助說明涩笤。

duncanwang@duncanwang:~/eos$ nodeos -help
Application Options:

Config Options for eosio::bnet_plugin:
  --bnet-endpoint arg (=0.0.0.0:4321)   the endpoint upon which to listen for 
                                        incoming connections
  --bnet-follow-irreversible arg (=0)   this peer will request only 
                                        irreversible blocks from other nodes
  --bnet-threads arg                    the number of threads to use to process
                                        network messages
  --bnet-connect arg                    remote endpoint of other node to 
                                        connect to; Use multiple bnet-connect 
                                        options as needed to compose a network
  --bnet-no-trx                         this peer will request no pending 
                                        transactions from other nodes
  --bnet-peer-log-format arg (=["${_name}" ${_ip}:${_port}])
                                        The string used to format peers when 
                                        logging messages about them.  Variables
                                        are escaped with ${<variable name>}.
                                        Available Variables:
                                           _name  self-reported name
                                        
                                           _id    self-reported ID (Public Key)
                                        
                                           _ip    remote IP address of peer
                                        
                                           _port  remote port number of peer
                                        
                                           _lip   local IP address connected to
                                                  peer
                                        
                                           _lport local port number connected 
                                                  to peer
                                        
                                        

Config Options for eosio::chain_plugin:
  --blocks-dir arg (="blocks")          the location of the blocks directory 
                                        (absolute path or relative to 
                                        application data dir)
  --checkpoint arg                      Pairs of [BLOCK_NUM,BLOCK_ID] that 
                                        should be enforced as checkpoints.
  --wasm-runtime wavm/binaryen          Override default WASM runtime
  --chain-state-db-size-mb arg (=1024)  Maximum size (in MB) of the chain state
                                        database
  --reversible-blocks-db-size-mb arg (=340)
                                        Maximum size (in MB) of the reversible 
                                        blocks database
  --contracts-console                   print contract's output to console
  --actor-whitelist arg                 Account added to actor whitelist (may 
                                        specify multiple times)
  --actor-blacklist arg                 Account added to actor blacklist (may 
                                        specify multiple times)
  --contract-whitelist arg              Contract account added to contract 
                                        whitelist (may specify multiple times)
  --contract-blacklist arg              Contract account added to contract 
                                        blacklist (may specify multiple times)
  --action-blacklist arg                Action (in the form code::action) added
                                        to action blacklist (may specify 
                                        multiple times)
  --key-blacklist arg                   Public key added to blacklist of keys 
                                        that should not be included in 
                                        authorities (may specify multiple 
                                        times)

Command Line Options for eosio::chain_plugin:
  --genesis-json arg                    File to read Genesis State from
  --genesis-timestamp arg               override the initial timestamp in the 
                                        Genesis State file
  --print-genesis-json                  extract genesis_state from blocks.log 
                                        as JSON, print to console, and exit
  --extract-genesis-json arg            extract genesis_state from blocks.log 
                                        as JSON, write into specified file, and
                                        exit
  --fix-reversible-blocks               recovers reversible block database if 
                                        that database is in a bad state
  --force-all-checks                    do not skip any checks that can be 
                                        skipped while replaying irreversible 
                                        blocks
  --replay-blockchain                   clear chain state database and replay 
                                        all blocks
  --hard-replay-blockchain              clear chain state database, recover as 
                                        many blocks as possible from the block 
                                        log, and then replay those blocks
  --delete-all-blocks                   clear chain state database and block 
                                        log
  --truncate-at-block arg (=0)          stop hard replay / block log recovery 
                                        at this block number (if set to 
                                        non-zero number)

Config Options for eosio::history_plugin:
  -f [ --filter-on ] arg                Track actions which match 
                                        receiver:action:actor. Actor may be 
                                        blank to include all. Receiver and 
                                        Action may not be blank.

Config Options for eosio::http_client_plugin:
  --https-client-root-cert arg          PEM encoded trusted root certificate 
                                        (or path to file containing one) used 
                                        to validate any TLS connections made.  
                                        (may specify multiple times)
                                        
  --https-client-validate-peers arg (=1)
                                        true: validate that the peer 
                                        certificates are valid and trusted, 
                                        false: ignore cert errors

Config Options for eosio::http_plugin:
  --http-server-address arg (=127.0.0.1:8888)
                                        The local IP and port to listen for 
                                        incoming http connections; set blank to
                                        disable.
  --https-server-address arg            The local IP and port to listen for 
                                        incoming https connections; leave blank
                                        to disable.
  --https-certificate-chain-file arg    Filename with the certificate chain to 
                                        present on https connections. PEM 
                                        format. Required for https.
  --https-private-key-file arg          Filename with https private key in PEM 
                                        format. Required for https
  --access-control-allow-origin arg     Specify the Access-Control-Allow-Origin
                                        to be returned on each request.
  --access-control-allow-headers arg    Specify the Access-Control-Allow-Header
                                        s to be returned on each request.
  --access-control-max-age arg          Specify the Access-Control-Max-Age to 
                                        be returned on each request.
  --access-control-allow-credentials    Specify if Access-Control-Allow-Credent
                                        ials: true should be returned on each 
                                        request.
  --max-body-size arg (=1048576)        The maximum body size in bytes allowed 
                                        for incoming RPC requests
  --verbose-http-errors                 Append the error log to HTTP responses

Config Options for eosio::net_plugin:
  --p2p-listen-endpoint arg (=0.0.0.0:9876)
                                        The actual host:port used to listen for
                                        incoming p2p connections.
  --p2p-server-address arg              An externally accessible host:port for 
                                        identifying this node. Defaults to 
                                        p2p-listen-endpoint.
  --p2p-peer-address arg                The public endpoint of a peer node to 
                                        connect to. Use multiple 
                                        p2p-peer-address options as needed to 
                                        compose a network.
  --p2p-max-nodes-per-host arg (=1)     Maximum number of client0nodes from any
                                        single IP address
  --agent-name arg (="EOS Test Agent")  The name supplied to identify this node
                                        amongst the peers.
  --allowed-connection arg (=any)       Can be 'any' or 'producers' or 
                                        'specified' or 'none'. If 'specified', 
                                        peer-key must be specified at least 
                                        once. If only 'producers', peer-key is 
                                        not required. 'producers' and 
                                        'specified' may be combined.
  --peer-key arg                        Optional public key of peer allowed to 
                                        connect.  May be used multiple times.
  --peer-private-key arg                Tuple of [PublicKey, WIF private key] 
                                        (may specify multiple times)
  --max-clients arg (=25)               Maximum number of clients from which 
                                        connections are accepted, use 0 for no 
                                        limit
  --connection-cleanup-period arg (=30) number of seconds to wait before 
                                        cleaning up dead connections
  --network-version-match arg (=0)      True to require exact match of peer 
                                        network version.
  --sync-fetch-span arg (=100)          number of blocks to retrieve in a chunk
                                        from any individual peer during 
                                        synchronization
  --max-implicit-request arg (=1500)    maximum sizes of transaction or block 
                                        messages that are sent without first 
                                        sending a notice
  --use-socket-read-watermark arg (=0)  Enable expirimental socket read 
                                        watermark optimization
  --peer-log-format arg (=["${_name}" ${_ip}:${_port}])
                                        The string used to format peers when 
                                        logging messages about them.  Variables
                                        are escaped with ${<variable name>}.
                                        Available Variables:
                                           _name  self-reported name
                                        
                                           _id    self-reported ID (64 hex 
                                                  characters)
                                        
                                           _sid   first 8 characters of 
                                                  _peer.id
                                        
                                           _ip    remote IP address of peer
                                        
                                           _port  remote port number of peer
                                        
                                           _lip   local IP address connected to
                                                  peer
                                        
                                           _lport local port number connected 
                                                  to peer
                                        
                                        

Config Options for eosio::producer_plugin:

  -e [ --enable-stale-production ]      Enable block production, even if the 
                                        chain is stale.
  -x [ --pause-on-startup ]             Start this node in a state where 
                                        production is paused
  --max-transaction-time arg (=30)      Limits the maximum time (in 
                                        milliseconds) that is allowed a pushed 
                                        transaction's code to execute before 
                                        being considered invalid
  --max-irreversible-block-age arg (=-1)
                                        Limits the maximum age (in seconds) of 
                                        the DPOS Irreversible Block for a chain
                                        this node will produce blocks on (use 
                                        negative value to indicate unlimited)
  -p [ --producer-name ] arg            ID of producer controlled by this node 
                                        (e.g. inita; may specify multiple 
                                        times)
  --private-key arg                     (DEPRECATED - Use signature-provider 
                                        instead) Tuple of [public key, WIF 
                                        private key] (may specify multiple 
                                        times)
  --signature-provider arg (=EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3)
                                        Key=Value pairs in the form 
                                        <public-key>=<provider-spec>
                                        Where:
                                           <public-key>    is a string form of 
                                                           a vaild EOSIO public
                                                           key
                                        
                                           <provider-spec> is a string in the 
                                                           form <provider-type>
                                                           :<data>
                                        
                                           <provider-type> is KEY, or KEOSD
                                        
                                           KEY:<data>      is a string form of 
                                                           a valid EOSIO 
                                                           private key which 
                                                           maps to the provided
                                                           public key
                                        
                                           KEOSD:<data>    is the URL where 
                                                           keosd is available 
                                                           and the approptiate 
                                                           wallet(s) are 
                                                           unlocked
  --keosd-provider-timeout arg (=5)     Limits the maximum time (in 
                                        milliseconds) that is allowd for 
                                        sending blocks to a keosd provider for 
                                        signing

Config Options for eosio::txn_test_gen_plugin:
  --txn-reference-block-lag arg (=0)    Lag in number of blocks from the head 
                                        block when selecting the reference 
                                        block for transactions (-1 means Last 
                                        Irreversible Block)

Config Options for eosio::wallet_plugin:
  --wallet-dir arg (=".")               The path of the wallet files (absolute 
                                        path or relative to application data 
                                        dir)
  --unlock-timeout arg (=900)           Timeout for unlocked wallet in seconds 
                                        (default 900 (15 minutes)). Wallets 
                                        will automatically lock after specified
                                        number of seconds of inactivity. 
                                        Activity is defined as any wallet 
                                        command e.g. list-wallets.

Application Config Options:
  --plugin arg                          Plugin(s) to enable, may be specified 
                                        multiple times

Application Command Line Options:
  -h [ --help ]                         Print this help message and exit.
  -v [ --version ]                      Print version information.
  --print-default-config                Print default configuration template
  -d [ --data-dir ] arg                 Directory containing program runtime 
                                        data
  --config-dir arg                      Directory containing configuration 
                                        files such as config.ini
  -c [ --config ] arg (=config.ini)     Configuration file name relative to 
                                        config-dir
  -l [ --logconf ] arg (=logging.json)  Logging configuration file name/path 
                                        for library users

4.2 創(chuàng)建錢包

cleos wallet create -n duncanwang

創(chuàng)建duncanwang錢包成功嚼吞,輸出結(jié)果如下:

duncanwang@duncanwang:~/eos$ cleos wallet create -n duncanwang
Creating wallet: duncanwang
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5JMZdES2Cds5LsPRUBRo2THEXpbFSM17Xmcd2XWG7XBd49wveTo"

【結(jié)果確認(rèn)】

duncanwang@duncanwang:~$ cleos wallet list
Wallets:
[
  "duncanwang *"
]

duanwang錢包已存在了盒件,*表示該賬號已解鎖。

【問題1】 創(chuàng)建錢包重名舱禽,但是cleos wallet list看不到

duncanwang@duncanwang:~$ cleos wallet create -n duncanwang
Error 3120001: Wallet already exists
Try to use different wallet name.

【解決方法】
這個(gè)主要是運(yùn)行的命令中沒有導(dǎo)入錢包--plugin eosio::wallet_plugin這個(gè)參數(shù)炒刁,導(dǎo)致已創(chuàng)建錢包未加載,但是目錄下存在已創(chuàng)建的錢包文件誊稚。

./nodeos -e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --replay-blockchain

~/eosio-wallet 目錄下刪除文件duncanwang.wallet即可重新創(chuàng)建切心。

【問題2】重啟節(jié)點(diǎn)后,cleos wallet list發(fā)現(xiàn)已創(chuàng)建的錢包等不存在片吊。

duncanwang@duncanwang:~$ cleos wallet list
Wallets:
[
]

【解決方法】
運(yùn)行./nodeos命令時(shí)要帶參數(shù)--plugin eosio::wallet_plugin
【解決方法2】
后來發(fā)現(xiàn)這種方法有時(shí)也是不可行绽昏,cleos wallet list沒有看到錢包。
采用命令'cleos wallet open -n duncanwang'打開錢包后俏脊,就正常加載進(jìn)來了全谤。

【問題3】創(chuàng)建錢包時(shí)提示keosd已運(yùn)行,并且無法連接

duncanwang@duncanwang:~$ cleos wallet create -n duncanwang
"/usr/local/bin/keosd" launched
Unable to connect to keosd, if keosd is running please kill the process and try again.

【解決方法】
需要輸入以下命令把keosd重啟下爷贫。

ps -ef | grep keosd
kill -9 pid
keosd --http-server-address=127.0.0.1:8900

操作實(shí)例如下:

duncanwang@duncanwang:~$ ps -ef | grep keosd
duncanw+  2439     1  0 07:14 pts/1    00:00:00 /usr/local/bin/keosd --http-server-address=::1:8900
duncanw+  2441  2389  0 07:16 pts/1    00:00:00 grep --color=auto keosd

duncanwang@duncanwang:~$ kill -9 2439

4.3 錢包導(dǎo)入系統(tǒng)賬號私鑰

1) 找到eosio的系統(tǒng)賬號的默認(rèn)公鑰/私鑰對
找到配置文件认然,例如以下地址,~/.local/share/eosio/nodeosconfig 的 config.ini漫萄,默認(rèn)的私鑰/公鑰是一樣的卷员。

#signature-provider = EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

2),錢包導(dǎo)入系統(tǒng)賬號私鑰

cleos wallet import 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 -n duncanwang

duncanwang@duncanwang:~/eos$ cleos wallet import 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 -n duncanwang
imported private key for: EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV

3)腾务,查看系統(tǒng)賬號信息
以下命令可以查看eosio系統(tǒng)賬號的密鑰和資源占用情況毕骡。

cleos get account eosio

duncanwang@duncanwang:~/eos/build$ cleos get account eosio
privileged: true
permissions: 
     owner     1:    1 EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
        active     1:    1 EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
memory: 
     quota:       unlimited  used:     60.75 KiB  

net bandwidth: 
     used:               unlimited
     available:          unlimited
     limit:              unlimited

cpu bandwidth:
     used:               unlimited
     available:          unlimited
     limit:              unlimited

4.4 加載Bios合約

現(xiàn)在我們有一個(gè)錢包,并且加載了eosio帳戶的密鑰岩瘦,我們可以設(shè)置一個(gè)默認(rèn)的系統(tǒng)合約未巫。為了開發(fā)的目的,可以使用默認(rèn)的eosio.bios合約启昧。通過此合約叙凡,您可以直接控制其他帳戶的資源分配,并調(diào)用其他特權(quán)API密末。在公開區(qū)塊鏈中握爷,這個(gè)系統(tǒng)合約將管理其他賬戶的 token 抵押和解抵押操作,以為合約執(zhí)行預(yù)留CPU严里、網(wǎng)絡(luò)活動(dòng)帶寬新啼,以及預(yù)留內(nèi)存。
eosio.bios合約可以在你的EOSIO源代碼文件夾中找到:contracts/eosio.bios田炭。下面的命令序列师抄,都假定是在EOSIO源代碼的根目錄執(zhí)行。但是您可以通過指定完整路徑教硫,從任意位置執(zhí)行這個(gè)命令:${EOSIO_SOURCE}/build/contracts/eosio.bios叨吮。

這個(gè)命令序列的結(jié)果是辆布,cleos發(fā)起一個(gè)包含兩個(gè)操作(actions)的交易(transaction):eosio::setcode和eosio::setabi。

代碼定義了合約如何運(yùn)行茶鉴,abi描述了參數(shù)如何在二進(jìn)制和json表示之間進(jìn)行轉(zhuǎn)換锋玲。雖然abi在技術(shù)上是可選的,但為了便于使用涵叮,所有的EOSIO工具都依賴于它惭蹂。

輸入命令:

cleos set contract eosio build/contracts/eosio.bios -p eosio

輸出結(jié)果,表示本地執(zhí)行成功割粮。

duncanwang@duncanwang:~/eos$ cleos set contract eosio build/contracts/eosio.bios -p eosio
Reading WAST/WASM from build/contracts/eosio.bios/eosio.bios.wasm...
Using already assembled WASM...
Publishing contract...
executed transaction: f4c1cc4e953710645a4849eb41cf92d9d3881c756b227323a3ade221e3807fbb  3720 bytes  12685 us
#         eosio <= eosio::setcode               {"account":"eosio","vmtype":0,"vmversion":0,"code":"0061736d0100000001621260037f7e7f0060057f7e7e7e7e...
#         eosio <= eosio::setabi                {"account":"eosio","abi":"0e656f73696f3a3a6162692f312e30050c6163636f756e745f6e616d65046e616d650f7065...
warning: transaction executed locally, but may not be confirmed by the network yet

4.5 創(chuàng)建并導(dǎo)入新的密鑰對

1)創(chuàng)建新的密鑰對

cleos create key

創(chuàng)建密鑰對的輸出結(jié)果盾碗。

duncanwang@duncanwang:~/eos$ cleos create key
Private key: 5JZQmnt6ZtEzUADswgKgBwMp9qAwTSNM9JFHPRFu1FjrLjj49g7
Public key: EOS6EHAzvrpQ4wo1BPcAk86X6aGDARZgqTcAq1mJRF1SxEYgNGWN1

2) 導(dǎo)入新的私鑰

cleos wallet import 5JZQmnt6ZtEzUADswgKgBwMp9qAwTSNM9JFHPRFu1FjrLjj49g7 -n duncanwang

輸出結(jié)果如下:

duncanwang@duncanwang:~/eos$ cleos wallet import 5JZQmnt6ZtEzUADswgKgBwMp9qAwTSNM9JFHPRFu1FjrLjj49g7 -n duncanwang
imported private key for: EOS6EHAzvrpQ4wo1BPcAk86X6aGDARZgqTcAq1mJRF1SxEYgNGWN1

**3)查看確認(rèn)密鑰對是否導(dǎo)入成功 **

cleos wallet keys

用于查看錢包的密鑰對情況。
【輸出結(jié)果】

duncanwang@duncanwang:~/eos$ cleos wallet keys
[
  "EOS6EHAzvrpQ4wo1BPcAk86X6aGDARZgqTcAq1mJRF1SxEYgNGWN1",
  "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
]

4.6 創(chuàng)建新賬號

創(chuàng)建賬號的命令:
cleos create account eosio {new_account} ownerkey {active_key}

其中eosio是超級用戶舀瓢,需要靠超級用戶來創(chuàng)建其它的新用戶廷雅,eosio后面就是你的新用戶的用戶名。

除了新的賬號之外京髓,命令后面還有兩個(gè)key:
1航缀、Owner key
2、Active key

Owner key是什么意思呢堰怨?Owner key表示分配給新賬號的一個(gè)Owner認(rèn)證的公鑰芥玉。Active key是分配給新賬號一個(gè)Active認(rèn)證的一個(gè)公鑰。

至于這兩個(gè)認(rèn)證备图,我后面會(huì)給詳細(xì)介紹灿巧,這是兩個(gè)主要的權(quán)限。我創(chuàng)建一個(gè)賬號诬烹,如果這個(gè)賬號要有Owner的權(quán)限和Active的權(quán)限砸烦,就必須要用這兩個(gè)key才能實(shí)現(xiàn)。
我們來總結(jié)一下剛才的操作绞吁,我們剛才操作是調(diào)用cleos create account創(chuàng)建了一個(gè)賬號,這個(gè)賬號的命名規(guī)則遵守下邊兩個(gè)規(guī)則:
1唬格、小于13個(gè)字符家破;
2、僅包含這些字符:.12345abcdefghijklmnopqrstuvwxyz
另外购岗,剛才給大家說到Owner key和Active key的概念汰聋。Owner key的概念就是你賬號的所有控制權(quán)限,你只要有了Owner key喊积,你可以對這個(gè)賬號的任何東西做任何的事兒烹困,這是它的所有控制權(quán)。
而Active key只掌握了你的賬號資金的訪問權(quán)限乾吻,也就是你如果有了Active這個(gè)權(quán)限的話髓梅,你可以對這個(gè)賬號的資金進(jìn)行轉(zhuǎn)移拟蜻,但是你不能轉(zhuǎn)移這個(gè)賬號的所有權(quán),或者不能做超過這個(gè)Active權(quán)限其它的權(quán)利枯饿。
如果簡單的理解酝锅,Owner key就是對這個(gè)賬號的最高權(quán)限,Active只是用來轉(zhuǎn)移資金而已奢方。這也是與以太坊智能合約開發(fā)的一個(gè)區(qū)別搔扁,以太坊賬號的權(quán)限其實(shí)沒有這么細(xì)分,它就只有一個(gè)賬號蟋字,我只要有這個(gè)賬號的公鑰和私鑰稿蹲,我就可以做任何事情。
具體操作如下鹊奖。

cleos create account eosio wangdenghui1 EOS6EHAzvrpQ4wo1BPcAk86X6aGDARZgqTcAq1mJRF1SxEYgNGWN1 EOS6EHAzvrpQ4wo1BPcAk86X6aGDARZgqTcAq1mJRF1SxEYgNGWN1

【錯(cuò)誤現(xiàn)象】

duncanwang@duncanwang:~/eos$ cleos create account eosio wangdenghui1 EOS6EHAzvrpQ4wo1BPcAk86X6aGDARZgqTcAq1mJRF1SxEYgNGWN1 EOS6EHAzvrpQ4wo1BPcAk86X6aGDARZgqTcAq1mJRF1SxEYgNGWN1
Error 3050000: action exception

【解決方案-查詢賬號】
查詢發(fā)現(xiàn)該賬號已存在苛聘,之前輝哥創(chuàng)建過,忘記了嫉入。

duncanwang@duncanwang:~/eos$ cleos get accounts EOS6EHAzvrpQ4wo1BPcAk86X6aGDARZgqTcAq1mJRF1SxEYgNGWN1
{
  "account_names": [
    "wangdenghui1"
  ]
}

cleos create account eosio boss EOS6EHAzvrpQ4wo1BPcAk86X6aGDARZgqTcAq1mJRF1SxEYgNGWN1 EOS6EHAzvrpQ4wo1BPcAk86X6aGDARZgqTcAq1mJRF1SxEYgNGWN1

創(chuàng)建成功輸出結(jié)果:

duncanwang@duncanwang:~/eos$ cleos create account eosio boss EOS6EHAzvrpQ4wo1BPcAk86X6aGDARZgqTcAq1mJRF1SxEYgNGWN1 EOS6EHAzvrpQ4wo1BPcAk86X6aGDARZgqTcAq1mJRF1SxEYgNGWN1
executed transaction: cb6801fe82816f94b447cbfb903ae8e9477f5c99920322d679a9c8c04347e536  200 bytes  367 us
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"boss","owner":{"threshold":1,"keys":[{"key":"EOS6EHAzvrpQ4wo1BPcAk86X6aGD...
warning: transaction executed locally, but may not be confirmed by the network yet

4.6 總結(jié)

至此焰盗,基于私鏈環(huán)境搭建和準(zhǔn)備工作已經(jīng)完畢,接下來就可以在上面運(yùn)行"Hello World"智能合約了咒林。

5. 參考

1)eoshackathon/eos_dapp_development_cn 古千峰Github
2) github官網(wǎng)
3)本地環(huán)境
EOS圈古千峰大俠擔(dān)任本篇的武術(shù)指導(dǎo)熬拒,深表感謝。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末垫竞,一起剝皮案震驚了整個(gè)濱河市澎粟,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌欢瞪,老刑警劉巖活烙,帶你破解...
    沈念sama閱讀 217,406評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異遣鼓,居然都是意外死亡啸盏,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,732評論 3 393
  • 文/潘曉璐 我一進(jìn)店門骑祟,熙熙樓的掌柜王于貴愁眉苦臉地迎上來回懦,“玉大人,你說我怎么就攤上這事次企∏釉危” “怎么了?”我有些...
    開封第一講書人閱讀 163,711評論 0 353
  • 文/不壞的土叔 我叫張陵缸棵,是天一觀的道長舟茶。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么吧凉? 我笑而不...
    開封第一講書人閱讀 58,380評論 1 293
  • 正文 為了忘掉前任隧出,我火速辦了婚禮,結(jié)果婚禮上客燕,老公的妹妹穿的比我還像新娘鸳劳。我一直安慰自己,他們只是感情好也搓,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,432評論 6 392
  • 文/花漫 我一把揭開白布赏廓。 她就那樣靜靜地躺著,像睡著了一般傍妒。 火紅的嫁衣襯著肌膚如雪幔摸。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,301評論 1 301
  • 那天颤练,我揣著相機(jī)與錄音既忆,去河邊找鬼。 笑死嗦玖,一個(gè)胖子當(dāng)著我的面吹牛患雇,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播宇挫,決...
    沈念sama閱讀 40,145評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼苛吱,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了器瘪?” 一聲冷哼從身側(cè)響起翠储,我...
    開封第一講書人閱讀 39,008評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎橡疼,沒想到半個(gè)月后援所,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,443評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡欣除,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,649評論 3 334
  • 正文 我和宋清朗相戀三年住拭,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片历帚。...
    茶點(diǎn)故事閱讀 39,795評論 1 347
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡废酷,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出抹缕,到底是詐尸還是另有隱情,我是刑警寧澤墨辛,帶...
    沈念sama閱讀 35,501評論 5 345
  • 正文 年R本政府宣布卓研,位于F島的核電站,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏奏赘。R本人自食惡果不足惜寥闪,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,119評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望磨淌。 院中可真熱鬧疲憋,春花似錦、人聲如沸梁只。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,731評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽搪锣。三九已至秋忙,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間构舟,已是汗流浹背灰追。 一陣腳步聲響...
    開封第一講書人閱讀 32,865評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留狗超,地道東北人弹澎。 一個(gè)月前我還...
    沈念sama閱讀 47,899評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像努咐,于是被迫代替她去往敵國和親苦蒿。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,724評論 2 354

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