EOS开发(三)在私链创建管理钱包、生成导入密钥对、创建账户

1.三大组件

这是EOS官网的组件架构关系图,描述了不同组件之间的关系:

  • nodeos - 服务器端的区块链节点组件
  • keosd - 钱包管理组件
  • cleos - 操作 nodeos 和 keosd 的命令行工具

本篇内容大部分翻译自官方文档

本篇对应的官方文档
https://developers.eos.io/eosio-nodeos/docs/learn-about-wallets-keys-and-accounts-with-cleos

cleos指令大全
https://developers.eos.io/eosio-cleos/reference

2.创建和管理钱包

2.1 创建钱包

yuyangdeMacBook-Pro:~ yuyang$ cd /Users/yuyang/eos/build/programs/cleos 
yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet list
"/usr/local/bin/keosd" launched
Wallets:
[]

可以看到keosd默认启动,并且还没有钱包

yuyangdeMacBook-Pro:cleos yuyang$ 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.
"PW5KQwfoDJDUUTTEdZzTpSHYfmvSWxL23jefVHLi6UL74Uw9em6WA"

创建了一个钱包,默认名为default.wallet,记下密码用于后面解锁钱包,keosd将钱包文件存储在~/eosio-wallet文件夹中

查看钱包,*表示该钱包文件处于解锁状态

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet list
Wallets:
[
  "default *"
]

2.2 创建自定义名称钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet create -n yuyang
Creating wallet: yuyang
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5J3F77veqpEkCKfc6GXCjj1eDXzWGVPiNjoFZNsQD7TvcT3X31V"

-n后面跟钱包名称

查看钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet list
Wallets:
[
  "default *",
  "yuyang *"
]

2.3 锁定钱包

锁定默认钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet lock
Locked: default

查看钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet list
Wallets:
[
  "default",
  "yuyang *"
]

可以看到default没有*号,说明已上锁

锁定指定名称钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet lock -n yuyang
Locked: yuyang

查看钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet list
Wallets:
[
  "default",
  "yuyang"
]

两个钱包都已锁定

2.4 解锁钱包

解锁默认钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet unlock
password: Unlocked: default

password提示出现时复制对应的钱包密码

查看钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet list
Wallets:
[
  "default *",
  "yuyang"
]

可以看到default钱包已解锁

解锁指定名称钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet unlock -n yuyang
password: Unlocked: yuyang

password提示出现时复制对应的钱包密码

查看钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet list
Wallets:
[
  "default *",
  "yuyang *"
]

两个钱包都已解锁

也可以直接在解锁时加入--password参数,然后输入钱包密码进行解锁。不过这样会导致钱包密码会显示在console记录上

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet unlock -n yuyang --password PW5J3F77veqpEkCKfc6GXCjj1eDXzWGVPiNjoFZNsQD7TvcT3X31V
Unlocked: yuyang

查看钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet list
Wallets:
[
  "default *",
  "yuyang *"
]

3.Keosd

因为接下来的操作涉及到另一个组件keosd,所以这里先插入讲解下。

keosd位于eos/build/programs/keosd下,作用是存储私钥,以便cleos用以签署交易并发送到区块链中。keosd在本机运行,并且将私钥存储在本地。

keosd会随着cleos自动启动。

3.1 自动锁定

keosd会在没有钱包指令的15分钟后自动锁定钱包,可以在~/eosio-wallet/config.ini中进行时长修改。可以设置一个超大数来取消这项功能。如果设为0,将会导致钱包永久锁定。

3.2 手动开启

yuyangdeMacBook-Pro:nodeos yuyang$ cd /Users/yuyang/eos/build/programs/keosd 
yuyangdeMacBook-Pro:keosd yuyang$ keosd

3.3 停止Keosd

停止keosd最有效的方法是找到keosd的进程,然后发送结束指令。需要注意的是cleos会自动开启keosd,这可能会导致其多个实例在运行。使用以下指令找到并结束所有keosd实例。

$ pgrep keosd
3178
24991
$ pkill keosd

3.4 其他选项

yuyangdeMacBook-Pro:keosd yuyang$ keosd --help
Application Options:

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-allow-credentials    Specify if Access-Control-Allow-Credent
                                        ials: true should be returned on each 
                                        request.

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                  Timeout for unlocked wallet in seconds.
                                        Wallets will automatically lock after 
                                        specified number of seconds of 
                                        inactivity. Activity is defined as any 
                                        wallet command e.g. list-wallets.
  --eosio-key arg                       eosio key that will be imported 
                                        automatically when a wallet is created.

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

3.5 重启后操作钱包

现在另开一个命令窗口,停止keosd

yuyangdeMacBook-Pro:keosd yuyang$ pgrep keosd
827
yuyangdeMacBook-Pro:keosd yuyang$ pkill keosd

回到cleos命令窗口,查看钱包

yuyangdeMacBook-Pro:nodeos yuyang$ cleos wallet list
"/usr/local/bin/keosd" launched
Wallets:
[]

由于cleos会检查keosd实例是否在运行,如果没有,则会启动其实例。

在操作钱包文件或者查看钱包列表前,需要先打开钱包文件。当我们停止keosd时,钱包文件会被上锁。当keosd重新启动后,钱包文件并未打开。输入以下命令打开并显示默认钱包default.wallet

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet open
Opened: default
yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet list
Wallets:
[
  "default"
]

打开指定名称钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet open -n yuyang
Opened: yuyang
yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet list
Wallets:
[
  "default",
  "yuyang"
]

4.生成并导入私钥对

生成两对公钥/私钥对

yuyangdeMacBook-Pro:cleos yuyang$ cleos create key
Private key: 5HqW8BxjUgNgWJQNNnvMVtLWRrwqmzDXnH5kZjFq5RmmTxUGvLx
Public key: EOS54RjRpGQbNhmz8gKspmH4DwPCXd6rhPy3U1UGZzjoxssAJALUM
yuyangdeMacBook-Pro:cleos yuyang$ cleos create key
Private key: 5JahG29Q57gVHjtWK2YD614Fodfb6Dr72zvN3oCKLGKJaEvFoew
Public key: EOS8GJ9YdSKcSfFcUXYff8MU4ifQLFiHGBNZ8VkSdDT7wcjnnL4gN

现在我们有两队密钥对了,此时,他们只是随意生成的密钥对,并且本身没有任何权限。

下一步,我们将两组密钥对中的私钥导入钱包。

现在先解锁default.wallet钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet list
Wallets:
[
  "default",
  "yuyang"
]
yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet unlock --password PW5KQwfoDJDUUTTEdZzTpSHYfmvSWxL23jefVHLi6UL74Uw9em6WA
Unlocked: default
yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet list
Wallets:
[
  "default *",
  "yuyang"
]

导入两个私钥到default.wallet钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet import --private-key 5HqW8BxjUgNgWJQNNnvMVtLWRrwqmzDXnH5kZjFq5RmmTxUGvLx
imported private key for: EOS54RjRpGQbNhmz8gKspmH4DwPCXd6rhPy3U1UGZzjoxssAJALUM
yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet import --private-key 5JahG29Q57gVHjtWK2YD614Fodfb6Dr72zvN3oCKLGKJaEvFoew
imported private key for: EOS8GJ9YdSKcSfFcUXYff8MU4ifQLFiHGBNZ8VkSdDT7wcjnnL4gN

可以看到,导入某个私钥成功后,会显示对应的公钥

现在查看所有解锁状态下钱包中的公钥

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet keys
[
  "EOS54RjRpGQbNhmz8gKspmH4DwPCXd6rhPy3U1UGZzjoxssAJALUM",
  "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
  "EOS8GJ9YdSKcSfFcUXYff8MU4ifQLFiHGBNZ8VkSdDT7wcjnnL4gN"
]

除了我们刚才生成的密钥,还多了一个EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV公钥。这个公钥是~/Library/Application Support/eosio/nodeos/config中的nodeos组件配置文件config.ini的默认值。

增加default.wallet钱包密码的参数,查看default.wallet钱包中的公私钥对

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet private_keys --password PW5KQwfoDJDUUTTEdZzTpSHYfmvSWxL23jefVHLi6UL74Uw9em6WA
[[
    "EOS54RjRpGQbNhmz8gKspmH4DwPCXd6rhPy3U1UGZzjoxssAJALUM",
    "5HqW8BxjUgNgWJQNNnvMVtLWRrwqmzDXnH5kZjFq5RmmTxUGvLx"
  ],[
    "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
    "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
  ],[
    "EOS8GJ9YdSKcSfFcUXYff8MU4ifQLFiHGBNZ8VkSdDT7wcjnnL4gN",
    "5JahG29Q57gVHjtWK2YD614Fodfb6Dr72zvN3oCKLGKJaEvFoew"
  ]
]

我们也为yuyang.wallet导入两组密钥对

先解锁yuyang.wallet钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet unlock -n yuyang --password PW5J3F77veqpEkCKfc6GXCjj1eDXzWGVPiNjoFZNsQD7TvcT3X31V
Unlocked: yuyang
yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet list
Wallets:
[
  "default *",
  "yuyang *"
]

生成两对公钥/私钥对

yuyangdeMacBook-Pro:cleos yuyang$ cleos create key
Private key: 5Kje821Tq2yh1MuVrPA4fxDXMXyhktRAhMEJp1rZPd58T3MXAB7
Public key: EOS6JCDcFJbkDBQuP8f5K9ELbDPMgtPo2dNU12ezNKAHi21SXgvSL
yuyangdeMacBook-Pro:cleos yuyang$ cleos create key
Private key: 5Jf83kKqgEATTu8vfhvwHJxV5SfJU6emKXCCvA3zDWVBXjYowaY
Public key: EOS7ZqcVEdGDmzKmhnCfjK3x9wzjqDd3mmv3hXtqWMVa1keVoU1Nc

指定钱包名称参数,导入两个私钥到yuyang.wallet钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet import --private-key 5Kje821Tq2yh1MuVrPA4fxDXMXyhktRAhMEJp1rZPd58T3MXAB7 -n yuyang
imported private key for: EOS6JCDcFJbkDBQuP8f5K9ELbDPMgtPo2dNU12ezNKAHi21SXgvSL
yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet import --private-key 5Jf83kKqgEATTu8vfhvwHJxV5SfJU6emKXCCvA3zDWVBXjYowaY -n yuyang
imported private key for: EOS7ZqcVEdGDmzKmhnCfjK3x9wzjqDd3mmv3hXtqWMVa1keVoU1Nc

现在查看所有解锁状态下钱包中的公钥

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet keys
[
  "EOS54RjRpGQbNhmz8gKspmH4DwPCXd6rhPy3U1UGZzjoxssAJALUM",
  "EOS6JCDcFJbkDBQuP8f5K9ELbDPMgtPo2dNU12ezNKAHi21SXgvSL",
  "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
  "EOS7ZqcVEdGDmzKmhnCfjK3x9wzjqDd3mmv3hXtqWMVa1keVoU1Nc",
  "EOS8GJ9YdSKcSfFcUXYff8MU4ifQLFiHGBNZ8VkSdDT7wcjnnL4gN"
]

可以看到又多了两个公钥

查看yuyang.wallet钱包中的公私钥对,注意这里需要传两个参数,钱包密码和钱包名称,如果不传钱包名称,eosio会认为你查询的是默认钱包default.wallet的公私钥对

yuyangdeMacBook-Pro:cleos yuyang$ cleos wallet private_keys --password PW5J3F77veqpEkCKfc6GXCjj1eDXzWGVPiNjoFZNsQD7TvcT3X31V -n yuyang
[[
    "EOS6JCDcFJbkDBQuP8f5K9ELbDPMgtPo2dNU12ezNKAHi21SXgvSL",
    "5Kje821Tq2yh1MuVrPA4fxDXMXyhktRAhMEJp1rZPd58T3MXAB7"
  ],[
    "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
    "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
  ],[
    "EOS7ZqcVEdGDmzKmhnCfjK3x9wzjqDd3mmv3hXtqWMVa1keVoU1Nc",
    "5Jf83kKqgEATTu8vfhvwHJxV5SfJU6emKXCCvA3zDWVBXjYowaY"
  ]
]

正常返回了yuyang.wallet钱包中的公私钥对

5. Nodeos

因为接下来创建账号需要启动nedeos,所以先了解下nedeos

官方文档Local Single-node Testnet

nedeos位于build/programs/nodeos文件夹中,使用以下命令启动单节点区块链

cd build/programs/nodeos
./nodeos -e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin

成功后开始产出区块

1575001ms thread-0   chain_controller.cpp:235      _push_block          ] initm #1 @2017-09-04T04:26:15  | 0 trx, 0 pending, exectime_ms=0
1575001ms thread-0   producer_plugin.cpp:207       block_production_loo ] initm generated block #1 @ 2017-09-04T04:26:15 with 0 trxs  0 pending
1578001ms thread-0   chain_controller.cpp:235      _push_block          ] initc #2 @2017-09-04T04:26:18  | 0 trx, 0 pending, exectime_ms=0
1578001ms thread-0   producer_plugin.cpp:207       block_production_loo ] initc generated block #2 @ 2017-09-04T04:26:18 with 0 trxs  0 pending
...
eosio generated block 046b9984... #101527 @ 2018-04-01T14:24:58.000 with 0 trxs
eosio generated block 5e527ee2... #101528 @ 2018-04-01T14:24:58.500 with 0 trxs
...

此时,eosio作为一个单独的区块生产者

5.1 建议步骤

nedeos的配置文件位于~/Library/Application Support/eosio/nodeos/config文件夹中,可以通过编辑该文件,以便直接使用nedeos命令生产区块。

修改或新增以下内容:

  # Enable production on a stale chain, since a single-node test chain is pretty much always stale
    enable-stale-production = true
    # Enable block production with the testnet producers
    producer-name = eosio
    # Load the block producer plugin, so you can produce blocks
    plugin = eosio::producer_plugin
    # As well as API and HTTP plugins
    plugin = eosio::chain_api_plugin
    plugin = eosio::http_plugin
   # This will be used by the validation step below, to view history
    plugin = eosio::history_api_plugin

现在可以直接使用nedeos命令生产区块了

yuyangdeMacBook-Pro:nodeos yuyang$ nodeos

nedeos将区块数据存储在文件~/Library/Application Support/eosio/nodeos/data

6. 创建账户

6.1 准备工作

我们使用cleos发送指令给nodeos来创建账户并提交到区块链上,所以需要启动一个测试用的单节点

我们需要keosdnodeos都处于运行状态。它们当前都使用的是同一个端口号8888。如果只想启动nodeos,我们需要将keosd的端口号改为8899,有两种方法可以进行修改:

  • 编辑keosd的配置文件~/eosio-wallet/config.ini,将http-server-address属性改为http-server-address = 127.0.0.1:8899

  • 启动keosd时加入--http-server-address=localhost:8899参数

注意:第一种方式已证明无效。如果想使用这种方式,需要将~/eosio-wallet/config.ini拷贝到其他文件夹,名称不变。此时修改其中的地址,然后在启动keosd时指定配置文件位置。例如:keosd --config-dir /Users/yuyang/eosio-wallet/configconfig.ini文件位于/Users/yuyang/eosio-wallet/config文件夹中。

现在重新启动keosd,使用命令参数的方式指定端口号:

yuyangdeMacBook-Pro:keosd yuyang$ pgrep keosd
808
yuyangdeMacBook-Pro:keosd yuyang$ pkill keosd
yuyangdeMacBook-Pro:keosd yuyang$ keosd --http-server-address=localhost:8899
2730059ms thread-0   wallet_plugin.cpp:41          plugin_initialize    ] initializing wallet plugin
2730060ms thread-0   http_plugin.cpp:247           plugin_initialize    ] configured http to listen on localhost:8899
2730060ms thread-0   http_plugin.cpp:285           plugin_startup       ] start listening for http requests
2730060ms thread-0   wallet_api_plugin.cpp:70      plugin_startup       ] starting wallet_api_plugin
2730060ms thread-0   http_plugin.cpp:325           add_handler          ] add api url: /v1/wallet/create
2730060ms thread-0   http_plugin.cpp:325           add_handler          ] add api url: /v1/wallet/get_public_keys
2730060ms thread-0   http_plugin.cpp:325           add_handler          ] add api url: /v1/wallet/import_key
2730060ms thread-0   http_plugin.cpp:325           add_handler          ] add api url: /v1/wallet/list_keys
2730060ms thread-0   http_plugin.cpp:325           add_handler          ] add api url: /v1/wallet/list_wallets
2730060ms thread-0   http_plugin.cpp:325           add_handler          ] add api url: /v1/wallet/lock
2730060ms thread-0   http_plugin.cpp:325           add_handler          ] add api url: /v1/wallet/lock_all
2730060ms thread-0   http_plugin.cpp:325           add_handler          ] add api url: /v1/wallet/open
2730060ms thread-0   http_plugin.cpp:325           add_handler          ] add api url: /v1/wallet/set_timeout
2730060ms thread-0   http_plugin.cpp:325           add_handler          ] add api url: /v1/wallet/sign_transaction
2730060ms thread-0   http_plugin.cpp:325           add_handler          ] add api url: /v1/wallet/unlock

解锁default.wallet钱包。因为现在keosd已经重启并且监听端口改为了8899,所以需要新增钱包指令的url参数:

yuyangdeMacBook-Pro:cleos yuyang$ cleos --wallet-url=http://localhost:8899 wallet unlock
password: Unlocked: default

查看钱包

yuyangdeMacBook-Pro:cleos yuyang$ cleos --wallet-url=http://localhost:8899 wallet list
Wallets:
[
  "default *"
]

新开一个命令行,启动nodeos:

yuyangdeMacBook-Pro:nodeos yuyang$ nodeos

在此教程中,eosio是授权账户。在区块链上进行actions操作时,需要使用eosio的密钥进行签名。eosio的密钥位于~/Libraries/Application Support/eosio/nodeos/config/config.ini中,内容如下:

#    KEOSD:<data>       is the URL where keosd is available and the approptiate wallet(s) are unlocked (eosio::producer_plugin)
signature-provider = EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

查看default.wallet钱包中的公钥

yuyangdeMacBook-Pro:cleos yuyang$ cleos --wallet-url=http://localhost:8899 wallet keys
[
  "EOS54RjRpGQbNhmz8gKspmH4DwPCXd6rhPy3U1UGZzjoxssAJALUM",
  "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
  "EOS8GJ9YdSKcSfFcUXYff8MU4ifQLFiHGBNZ8VkSdDT7wcjnnL4gN"
]

查看default.wallet钱包中的密钥对

yuyangdeMacBook-Pro:cleos yuyang$ cleos --wallet-url=http://localhost:8899 wallet private_keys --password PW5KQwfoDJDUUTTEdZzTpSHYfmvSWxL23jefVHLi6UL74Uw9em6WA
[[
    "EOS54RjRpGQbNhmz8gKspmH4DwPCXd6rhPy3U1UGZzjoxssAJALUM",
    "5HqW8BxjUgNgWJQNNnvMVtLWRrwqmzDXnH5kZjFq5RmmTxUGvLx"
  ],[
    "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
    "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
  ],[
    "EOS8GJ9YdSKcSfFcUXYff8MU4ifQLFiHGBNZ8VkSdDT7wcjnnL4gN",
    "5JahG29Q57gVHjtWK2YD614Fodfb6Dr72zvN3oCKLGKJaEvFoew"
  ]
]

可以看到default.wallet钱包已经包含了eosio的密钥对了

6.2 创建账户

有关账户和权限的深入理解,可以阅读这篇文章
EOS开发(二)账户和权限说明

创建账户的格式如下:

cleos create account AUTHORIZING_ACCOUNT NEW_ACCOUNT OWNER_KEY ACTIVE_KEY
  • authorizing_account 新账户的创建者。在此教程中,由于我们运行的是一个单节点测试网络,所以我们拥有一个名为eosio的系统账户,因此我们使用eosio作为新账户的创建者

  • new_account 要创建的账户名称

  • owner_key 账户owner权限的公钥

  • active_key 账户active权限的公钥

新账户的名称需要遵循以下规则:

  • 小于13个字符

  • 只能包含以下字符.12345abcdefghijklmnopqrstuvwxyz

我们使用myaccount作为新账户名称,使用之前生成并导入default.wallet钱包的两个公钥EOS54RjRpGQbNhmz8gKspmH4DwPCXd6rhPy3U1UGZzjoxssAJALUMEOS8GJ9YdSKcSfFcUXYff8MU4ifQLFiHGBNZ8VkSdDT7wcjnnL4gN作为owner权限和active权限的公钥

yuyangdeMacBook-Pro:cleos yuyang$ cleos --wallet-url=http://localhost:8899 create account eosio myaccount EOS54RjRpGQbNhmz8gKspmH4DwPCXd6rhPy3U1UGZzjoxssAJALUM EOS8GJ9YdSKcSfFcUXYff8MU4ifQLFiHGBNZ8VkSdDT7wcjnnL4gN
2018-08-24T09:09:44.488 thread-0   main.cpp:2870                 main                 ] Failed with error: Assert Exception (10)
pivot != std::string::npos: No delimiter in string, cannot determine type: EOSK2KfSbsj1Asfy2fczyYA37ycoWQtq1pb9wWDYgCaeghQMoc6cLFNL6B8msL8ffEsp1oZsWPTqe2XMeALypwNw6ivQbdoLU

这里我失败了。错误也很奇怪,查了很久,试了很多方法都不行,最后删了整个eos文件夹重新git了一次代码就好了。不知道是不是我之前git的代码的版本有这个BUG

成功提示:

yuyangdeMacBook-Pro:cleos yuyang$ cleos --wallet-url=http://localhost:8899 create account eosio myaccount EOS54RjRpGQbNhmz8gKspmH4DwPCXd6rhPy3U1UGZzjoxssAJALUM EOS8GJ9YdSKcSfFcUXYff8MU4ifQLFiHGBNZ8VkSdDT7wcjnnL4gN
executed transaction: 4e0e59dd56b8b3b9d9c9befd3a53a6e37845b9ad83739a5e54a7a9145a79bba6  200 bytes  336 us
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"myaccount","owner":{"threshold":1,"keys":[{"key":"EOS54RjRpGQbNhmz8gKspmH...
2018-08-25T02:14:18.568 thread-0   main.cpp:455                  print_result   warning: transaction executed locally, but may not be confirmed by the network yet

6.2 查询账户

在节点查询我们刚才创建的myaccount账户:

yuyangdeMacBook-Pro:cleos yuyang$ cleos --wallet-url=http://localhost:8899 get account myaccount
permissions: 
     owner     1:    1 EOS54RjRpGQbNhmz8gKspmH4DwPCXd6rhPy3U1UGZzjoxssAJALUM
        active     1:    1 EOS8GJ9YdSKcSfFcUXYff8MU4ifQLFiHGBNZ8VkSdDT7wcjnnL4gN
memory: 
     quota:       unlimited  used:      2.66 KiB  

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

cpu bandwidth:
     used:               unlimited
     available:          unlimited
     limit:              unlimited
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,723评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,485评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,998评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,323评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,355评论 5 374
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,079评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,389评论 3 400
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,019评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,519评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,971评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,100评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,738评论 4 324
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,293评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,289评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,517评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,547评论 2 354
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,834评论 2 345

推荐阅读更多精彩内容