区块链100讲:如何使用开发环境命令行注册EOS靓号及变更EOS账号的active key和owner key?

image

1

摘要

【本文目标】

通过本文学习,程序员可以在EOS本地环境完成主网心意的12位EOS账号注册,并且可以通过EOS本地环境完成EOS注册账号的active key和owner key的变更。

在EOS账号是其他人代为注册时,私钥往往也被其他人知晓,存在泄漏风险,建议尽快完成变更。

【前置条件】

1)已完成了EOS编译,编译测试成功。未完成的可参考如何在UBUNTU虚拟机上编译EOS完成环境搭建?(附代码)

【技术收获】

1) 命令行操作实践完成主网的12位账号注册;

2) cleos set account permission的使用;

2

注册账号

2.1 创建新的密钥对,配置钱包

【小提醒】让别人创建EOS账号,密钥对的私钥最好由账号拥有者自行获取,不要让帮忙者自己创建,否则这个账号的安全性存在风险。但是反向考虑,如果能自己创建EOS密钥对,这样的朋友估计也知道怎么创建账号了,那可能就不存在请求帮忙的事情了。

1)创建本地钱包

在本地创建一个default钱包,用于给徐总存放账号的,如果钱包已创建,则忽略本步。

cleos wallet create

输出结果:

duncanwang@duncanwang:~$ 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

输出结果:(私钥的部分关键字已隐藏)

duncanwang@duncanwang:~$ cleos create key

Private key: 5JkT6Dd9G1**dfajJ8SQpgYzScDBaV***ZFkMG8siw***z9Mf8v

Public key: EOS8gaYL4uHyAiZjviwNJ8CdY31xikYtQfexyUfkNUnDqhNpnYXQR

3) 新的私钥导入default钱包

cleos wallet import

输出结果:

duncanwang@duncanwang:~$ cleos wallet import 5JkT6Dd9G1**dfajJ8SQpgYzScDBaV***ZFkMG8siw***z9Mf8vimported private key for: EOS8gaYL4uHyAiZjviwNJ8CdY31xikYtQfexyUfkNUnDqhNpnYXQR

2.2 查找主网NODEOS地址

主网的p2p节点地址可以到 EOS Seed List网址(https://eosnodes.privex.io/)查找。找到一个合适的节点后,可以用命令行查看信息。以佳能节点为例,命令如下:

cleos -u https://node1.eoscannon.io get info

输出结果如下:

duncanwang@duncanwang:~$ 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(https://eos.host/mainnet) 查看,目前的chain_id是
aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906,一致的。

【说明】用命令行的方式也可以找到所有节点的列表。命令如下:

cleos -u https://node1.eoscannon.io system listproducers -l 1000

2.3 注册EOS新账号

1) 确认创建父账号的资源是否充足

辉哥为别人创建帐号,意味着辉哥把自己的一部分计算资源分配给了他,所以需要消耗EOS。

注意:所有账号名必须为12个字符,包括a-z以及1-5,不含0。
小于12位的EOS账号是需要拍卖的,参考文档《第3课 惊天秘诀,2位账号如JD只要0.5个EOS就可注册?!》(https://www.jianshu.com/p/51f29a1c3cba)。

cleos -u https://node1.eoscannon.io get account wangdenghui1

输出结果:

duncanwang@duncanwang:~$ 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) 查询账号是否存在

cleos -u https://node1.eoscannon.io get account gobipartners

输出结果(账号不存在):

duncanwang@duncanwang:~$ 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

duncanwang@duncanwang:~$ 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> <要申请的新账号名>

duncanwang@duncanwang:~$ 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)查询新创建的账号是否存在

  • 命令行查询方式

cleos -u https://node1.eoscannon.io get account gobipartners

输出结果,显示该账号存在:

duncanwang@duncanwang:~$ 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   
  • 网页查询方式

https://eosflare.io输入信息,查询该账号确认已存在。

image

6)创建账号的命令参考

创建系统账号的命令的帮助说明如下,供参考。

duncanwang@duncanwang:~$ 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 'account@permission' 

 --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)

3

变更EOS账号的active key和owner key

3.1 通过TokenPocket钱包创建密钥对

通过TokenPocket官网(https://www.mytokenpocket.vip/)下载钱包版本。

安装后,通过 发现 > EOS助手 > 账号注册 > 密码生成器 完成密钥对的生成。

image

image

image

3.2 密钥导入

来到本地EOS环境,亲自把私钥导入duncanwang本地钱包。

【说明】此步操作可以在别的任意EOS开发环境完成导入工作。

cleos wallet import <新的私钥> -n duncanwang

3.3 权限变更

1) 查看gobipartners账号信息

cleos -u https://node1.eoscannon.io get account gobipartners

输出结果表明 owner key 和 active key还是辉哥的密钥对。

duncanwang@duncanwang:~$ 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:        55.92 KiB

       limit:            55.92 KiB

  cpu bandwidth:

     delegated:       0.1000 EOS           (total staked delegated to account from others)

     used:                 0 us

        available:         10.9 ms 

       limit:             10.9 ms

3.4 变更账户active权限为徐总公钥

假设产生的公钥Public key如下:EOS7Rq86JcZLgPXwZKRGPYUnLayBy7NcBV7FBE7gSNCW3HmGApK9V

命令格式:

cleos set account permission <转让账户名> active ‘{“threshold”:1,”keys”:[{“key”:”<对方公钥>”,”weight”:1}]}’ owner

输出结果:

duncanwang@duncanwang:~$ cleos -u https://node1.eoscannon.io set account permission gobipartners active '{"threshold":1,"keys":[{"key":"EOS7Rq86JcZLgPXwZKRGPYUnLayBy7NcBV7FBE7gSNCW3HmGApK9V","weight":1}]}' ownerexecuted transaction: 0b7ab9fe92413e6b4b5d25578afdef81438c73adac015972ce56f59c570034e9  160 bytes  1317 us

#         eosio <= eosio::updateauth            {"account":"gobipartners","permission":"active","parent":"owner","auth":{"threshold":1,"keys":[{"key...

warning: transaction executed locally, but may not be confirmed by the network yet

查询确认active的KEY已发生变更:

duncanwang@duncanwang:~$ cleos -u https://node1.eoscannon.io get  account gobipartners

permissions:

      owner     1:    1 EOS8gaYL4uHyAiZjviwNJ8CdY31xikYtQfexyUfkNUnDqhNpnYXQR

        active     1:    1 EOS7Rq86JcZLgPXwZKRGPYUnLayBy7NcBV7FBE7gSNCW3HmGApK9V

memory: 

     quota:     7.959 KiB    used:     2.926 KiB

  net bandwidth:

      delegated:       0.1000 EOS           (total staked delegated to account from others)

     used:               161 bytes

     available:        55.76 KiB

       limit:            55.92 KiB

  cpu bandwidth:

     delegated:       0.1000 EOS           (total staked delegated to account from others)

     used:             1.122 ms

        available:        9.779 ms

        limit:             10.9 ms

3.5 变更账户owner为徐总公钥

命令格式:

cleos set account permission <转让账户名> owner ‘{“threshold”:1,”keys”:[{“key”:”<对方公钥>”,”weight”:1}]}’ -p <转让账户名>@owner

输出结果:

duncanwang@duncanwang:~$ cleos -u https://node1.eoscannon.io set account permission -x 120 gobipartners owner '{"threshold":1,"keys":[{"key":"EOS7Rq86JcZLgPXwZKRGPYUnLayBy7NcBV7FBE7gSNCW3HmGApK9V","weight":1}]}' -p gobipartners@owner

executed transaction: ed1593fee153baa7b02e1e3e1155e732c3e7db4fbb3fd50ff73b0de1a04d5831  160 bytes  1186 us

#         eosio <= eosio::updateauth            {"account":"gobipartners","permission":"owner","parent":"","auth":{"threshold":1,"keys":[{"key":"EOS...

warning: transaction executed locally, but may not be confirmed by the network yet

【问题】输入命令提示错误,信息如下:

duncanwang@duncanwang:~$ cleos set account permission gobipartners owner '{"threshold":1,"keys":[{"key":"EOS7Rq86JcZLgPXwZKRGPYUnLayBy7NcBV7FBE7gSNCW3HmGApK9V","weight":1}]}' -p gobipartners@owner

Error 3090003: provided keys, permissions, and delays do not satisfy declared authorizations

Ensure that you have the related private keys inside your wallet and your wallet is unlocked.

初步估计是跟主网节点连接处理的时间不够,增加-x 120,把等待时间改为2分钟,就成功了。

查询确认owner的KEY已发生变更:

duncanwang@duncanwang:~$ cleos -u https://node1.eoscannon.io get  account gobipartners

permissions:

      owner     1:    1 EOS7Rq86JcZLgPXwZKRGPYUnLayBy7NcBV7FBE7gSNCW3HmGApK9V

        active     1:    1 EOS7Rq86JcZLgPXwZKRGPYUnLayBy7NcBV7FBE7gSNCW3HmGApK9V

memory:

      quota:     7.959 KiB    used:     2.926 KiB

  net bandwidth:

      delegated:       0.1000 EOS           (total staked delegated to account from others)

     used:               318 bytes

     available:        55.61 KiB

       limit:            55.92 KiB

  cpu bandwidth:

     delegated:       0.1000 EOS           (total staked delegated to account from others)

     used:             1.628 ms 

       available:        9.273 ms

        limit:             10.9 ms

本文作者:HiBlock区块链技术布道群-辉哥

原文发布于简书

原文链接:

https://www.jianshu.com/p/ef09a0ce4231

https://www.jianshu.com/p/c6bd914dc2d0

加微信baobaotalk_com,加入技术布道群

以下是我们的社区介绍,欢迎各种合作、交流、学习:)

image

猜你喜欢

转载自blog.csdn.net/HiBlock/article/details/81276482
key