1. 程式人生 > >第8課 如何使用開發環境命令列註冊EOS靚號?

第8課 如何使用開發環境命令列註冊EOS靚號?

1,摘要

【本文目標】 通過本文學習,程式設計師可以在EOS本地環境完成主網心意的12位EOS賬號註冊。 不願意折騰的其他人員可參考文件《第2課 不懂技術,如何搶注熱門EOS賬號?》完成賬號註冊。

【技術收穫】 1) 命令列操作實踐完成主網的12位賬號註冊;

2. 實踐操作

為了體驗更佳,我們舉個場景吧。戈壁創投的徐晨總找到輝哥,希望能幫他註冊個他們公司同名的EOS賬號(例如:gobipartners),便於後續做區塊鏈投資使用。

2.1 建立新的金鑰對,配置錢包

【小提醒】讓別人建立EOS賬號,金鑰對的私鑰最好由賬號擁有者自行獲取,不要讓幫忙者自己建立,否則這個賬號的安全性存在風險。但是反向考慮,如果能自己建立EOS金鑰對,這樣的朋友估計也知道怎麼建立賬號了,那可能就不存在請求幫忙的事情了。 輝哥此處假設跟徐總非常熟悉,也採用命令列方式產生金鑰對給徐總用。

1)建立本地錢包 在本地建立一個default錢包,用於給徐總存放賬號的,如果錢包已建立,則忽略本步。

cleos wallet create

輸出結果:

[email protected]:~$ cleos wallet create
Creating wallet: default
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5K6PTcK1nfr6RT9KfcMtzZDcrM7ZqvtBnAnPyYcigH5HR15roDL"

2)建立新賬號所需的金鑰對

cleos create key

輸出結果:(私鑰的部分關鍵字已隱藏)

[email protected]:~$ cleos create key
Private key: 5JkT6Dd9G1**dfajJ8SQpgYzScDBaV***ZFkMG8siw***z9Mf8v
Public key: EOS8gaYL4uHyAiZjviwNJ8CdY31xikYtQfexyUfkNUnDqhNpnYXQR

3) 新的私鑰匯入default錢包

cleos wallet import <your_private_key>

輸出結果:

[email protected]
:~$ cleos wallet import 5JkT6Dd9G1**dfajJ8SQpgYzScDBaV***ZFkMG8siw***z9Mf8v imported private key for: EOS8gaYL4uHyAiZjviwNJ8CdY31xikYtQfexyUfkNUnDqhNpnYXQR

2.2 查詢主網NODEOS地址

主網的p2p節點地址可以到 EOS Seed List網址查詢。找到一個合適的節點後,可以用命令列檢視資訊。以佳能節點為例,命令如下:

輸出結果如下:

[email protected]:~$ cleos -u https://node1.eoscannon.io get info
{
  "server_version": "6ee30205",
  "chain_id": "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906",
  "head_block_num": 5448946,
  "last_irreversible_block_num": 5448615,
  "last_irreversible_block_id": "005323a7c602e9a643226f6e00b3709858c9f42f05c7381b457e0f38c2ef2d74",
  "head_block_id": "005324f2e20f241d036b46560812fcc1dc6e5dfe6644351a6c3ab699f27b0e3f",
  "head_block_time": "2018-07-12T06:10:33.000",
  "head_block_producer": "argentinaeos",
  "virtual_block_cpu_limit": 200000000,
  "virtual_block_net_limit": 1048576000,
  "block_cpu_limit": 192923,
  "block_net_limit": 1046944
}

說明下,“chain_id”這個欄位,它是主鏈ID,可以到 eos.host 檢視,目前的chain_id是 aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906,一致的。

【說明】用命令列的方式也可以找到所有節點的列表。命令如下:

2.3 註冊EOS新賬號

1) 確認建立父賬號的資源是否充足 輝哥為徐晨建立帳號,意味著輝哥把自己的一部分計算資源分配給了徐晨,所以需要消耗EOS。 注意:所有賬號名必須為12個字元,包括a-z以及1-5,不含0。 小於12位的EOS賬號是需要拍賣的,參考文件《第3課 驚天祕訣,2位賬號如JD只要0.5個EOS就可註冊?!》

輸出結果:

[email protected]:~$ cleos -u https://node1.eoscannon.io get account wangdenghui1
permissions: 
     owner     1:    1 EOS7Rq86JcZLgPXwZKRGPYUnLayBy7NcBV7FBE7gSNCW3HmGApK9V
        active     1:    1 EOS7Rq86JcZLgPXwZKRGPYUnLayBy7NcBV7FBE7gSNCW3HmGApK9V
memory: 
     quota:     24.96 KiB    used:     4.021 KiB  

net bandwidth: 
     delegated:       0.0501 EOS           (total staked delegated to account from others)
     used:               519 bytes
     available:        26.13 KiB  
     limit:            26.64 KiB  

cpu bandwidth:
     delegated:       0.3001 EOS           (total staked delegated to account from others)
     used:             10.15 ms   
     available:        20.96 ms   
     limit:            31.11 ms   

producers:     <not voted>

按照經驗,建立一個EOS新賬號需要消耗的資源如下,目前輝哥賬號的資源還滿足建立要求。 NET Stake (in EOS): 0.05 CPU Stake (in EOS): 0.1 RAM (in kbytes):8

** 2) 查詢賬號是否存在**

輸出結果(賬號不存在):

[email protected]:~$ cleos -u https://node1.eoscannon.io get account gobipartners
892747ms thread-0   main.cpp:2712                 main                 ] Failed with error: unspecified (0)

3)匯入wangdenghui1的私鑰到duncanwang錢包 部分私鑰內容已隱藏。

cleos wallet import <私鑰> -n duncanwang

[email protected]:~$ cleos wallet import 5KH***Mev**JtQW***iXLfVvUFx***D8iL7H***8wAa***YZR54 -n duncanwang
imported private key for: EOS7Rq86JcZLgPXwZKRGPYUnLayBy7NcBV7FBE7gSNCW3HmGApK9V

4)註冊EOS新賬戶名 呼叫eosio.system合約的newaccount Action,命令如下:

cleos -u https://node1.eoscannon.io system newaccount -x 1000 --stake-net ‘0.0010 EOS’ --stake-cpu ‘0.0010 EOS’ --buy-ram-kbytes 8 <對映分配的account_name> <要申請的新賬號名> <EOS公鑰>

【引數的含義】 **-x 1000:**1000s內最長反饋時間; **–stake-net:**使用頻寬抵押的EOS; **–stake-cpu:**使用CPU抵押的EOS; **–buy-ram-kbytes:**購買的記憶體(最低8KB); **<對映分配的account_name>:**即第3步記下來的12個字元的賬戶名; **<要申請的新賬號名>:**同樣是12個字元,只能使用小寫字母a-z,和數字1-5; <EOS公鑰> 【經驗】 NET Stake (in EOS): 0.05 CPU Stake (in EOS): 0.1 RAM (in kbytes):8

cleos -u https://node1.eoscannon.io system newaccount -x 1000 --stake-net “0.1 EOS” --stake-cpu “0.1 EOS” --buy-ram-kbytes 8 wangdenghui1 gobipartners EOS8gaYL4uHyAiZjviwNJ8CdY31xikYtQfexyUfkNUnDqhNpnYXQR EOS8gaYL4uHyAiZjviwNJ8CdY31xikYtQfexyUfkNUnDqhNpnYXQR

輸出結果(建立成功):

[email protected]:~$ cleos -u https://node1.eoscannon.io system newaccount -x 1000 --stake-net "0.1 EOS" --stake-cpu "0.1 EOS" --buy-ram-kbytes 8 wangdenghui1 gobipartners EOS8gaYL4uHyAiZjviwNJ8CdY31xikYtQfexyUfkNUnDqhNpnYXQR EOS8gaYL4uHyAiZjviwNJ8CdY31xikYtQfexyUfkNUnDqhNpnYXQR
1229333ms thread-0   main.cpp:429                  create_action        ] result: {"binargs":"109c6e6caac4a6e180af9af99aea0e6500200000"} arg: {"code":"eosio","action":"buyrambytes","args":{"payer":"wangdenghui1","receiver":"gobipartners","bytes":8192}} 
1229958ms thread-0   main.cpp:429                  create_action        ] result: {"binargs":"109c6e6caac4a6e180af9af99aea0e65e80300000000000004454f5300000000e80300000000000004454f530000000000"} arg: {"code":"eosio","action":"delegatebw","args":{"from":"wangdenghui1","receiver":"gobipartners","stake_net_quantity":"0.1000 EOS","stake_cpu_quantity":"0.1000 EOS","transfer":false}} 
executed transaction: d0c3543b6db8787a151a748ab73d0dec9210442cf7022a442c42fa9fe2a27f3c  336 bytes  5477 us
#         eosio <= eosio::newaccount            {"creator":"wangdenghui1","name":"gobipartners","owner":{"threshold":1,"keys":[{"key":"EOS8gaYL4uHyA...
#         eosio <= eosio::buyrambytes           {"payer":"wangdenghui1","receiver":"gobipartners","bytes":8192}
#   eosio.token <= eosio.token::transfer        {"from":"wangdenghui1","to":"eosio.ram","quantity":"2.9714 EOS","memo":"buy ram"}
#  wangdenghui1 <= eosio.token::transfer        {"from":"wangdenghui1","to":"eosio.ram","quantity":"2.9714 EOS","memo":"buy ram"}
#     eosio.ram <= eosio.token::transfer        {"from":"wangdenghui1","to":"eosio.ram","quantity":"2.9714 EOS","memo":"buy ram"}
#   eosio.token <= eosio.token::transfer        {"from":"wangdenghui1","to":"eosio.ramfee","quantity":"0.0150 EOS","memo":"ram fee"}
#  wangdenghui1 <= eosio.token::transfer        {"from":"wangdenghui1","to":"eosio.ramfee","quantity":"0.0150 EOS","memo":"ram fee"}
#  eosio.ramfee <= eosio.token::transfer        {"from":"wangdenghui1","to":"eosio.ramfee","quantity":"0.0150 EOS","memo":"ram fee"}
#         eosio <= eosio::delegatebw            {"from":"wangdenghui1","receiver":"gobipartners","stake_net_quantity":"0.1000 EOS","stake_cpu_quanti...
#   eosio.token <= eosio.token::transfer        {"from":"wangdenghui1","to":"eosio.stake","quantity":"0.2000 EOS","memo":"stake bandwidth"}
#  wangdenghui1 <= eosio.token::transfer        {"from":"wangdenghui1","to":"eosio.stake","quantity":"0.2000 EOS","memo":"stake bandwidth"}
#   eosio.stake <= eosio.token::transfer        {"from":"wangdenghui1","to":"eosio.stake","quantity":"0.2000 EOS","memo":"stake bandwidth"}
warning: transaction executed locally, but may not be confirmed by the network yet

5)查詢新建立的賬號是否存在 1] 命令列查詢方式

輸出結果,顯示該賬號存在:

[email protected]:~$ cleos -u https://node1.eoscannon.io get account gobipartners
permissions: 
     owner     1:    1 EOS8gaYL4uHyAiZjviwNJ8CdY31xikYtQfexyUfkNUnDqhNpnYXQR
        active     1:    1 EOS8gaYL4uHyAiZjviwNJ8CdY31xikYtQfexyUfkNUnDqhNpnYXQR
memory: 
     quota:     7.959 KiB    used:     2.926 KiB  

net bandwidth: 
     delegated:       0.1000 EOS           (total staked delegated to account from others)
     used:                 0 bytes
     available:        53.17 KiB  
     limit:            53.17 KiB  

cpu bandwidth:
     delegated:       0.1000 EOS           (total staked delegated to account from others)
     used:                 0 us   
     available:        10.37 ms   
     limit:            10.37 ms   

6)建立賬號的命令參考 建立系統賬號的命令的幫助說明如下,供參考。

[email protected]:~$ cleos system newaccount -h
Create an account, buy ram, stake for bandwidth for the account
Usage: cleos system newaccount [OPTIONS] creator name OwnerKey [ActiveKey]

Positionals:
  creator TEXT                The name of the account creating the new account (required)
  name TEXT                   The name of the new account (required)
  OwnerKey TEXT               The owner public key for the new account (required)
  ActiveKey TEXT              The active public key for the new account

Options:
  -h,--help                   Print this help message and exit
  --stake-net TEXT            The amount of EOS delegated for net bandwidth (required)
  --stake-cpu TEXT            The amount of EOS delegated for CPU bandwidth (required)
  --buy-ram-kbytes UINT       The amount of RAM bytes to purchase for the new account in kibibytes (KiB), default is 8 KiB
  --buy-ram TEXT              The amount of RAM bytes to purchase for the new account in EOS
  --transfer                  Transfer voting power and right to unstake EOS to receiver
  -x,--expiration             set the time in seconds before a transaction expires, defaults to 30s
  -f,--force-unique           force the transaction to be unique. this will consume extra bandwidth and remove any protections against accidently issuing the same transaction multiple times
  -s,--skip-sign              Specify if unlocked wallet keys should be used to sign transaction
  -j,--json                   print result as json
  -d,--dont-broadcast         don't broadcast transaction to the network (just print to stdout)
  -r,--ref-block TEXT         set the reference block num or block id used for TAPOS (Transaction as Proof-of-Stake)
  -p,--permission TEXT ...    An account and permission level to authorize, as in '[email protected]'
  --max-cpu-usage-ms UINT     set an upper limit on the milliseconds of cpu usage budget, for the execution of the transaction (defaults to 0 which means no limit)
  --max-net-usage UINT        set an upper limit on the net usage budget, in bytes, for the transaction (defaults to 0 which means no limit)

4,參考

本故事純屬虛構,輝哥還沒有跟徐晨總建立聯絡。但是戈壁創投的EOS帳號已註冊好了,如有需要可轉讓給徐總。