[关闭]
@hitchhacker 2018-05-24T23:34:07.000000Z 字数 2335 阅读 1198

cleos命令之账户类 | 大狗教你EOS开发

1 查看账户具体信息

输入以下命令:
cleos get account [账户名]
查看该账户的信息。
返回如下结果:

  1. {
  2. "account_name": "gakki",
  3. "permissions": [{
  4. "perm_name": "active",
  5. "parent": "owner",
  6. "required_auth": {
  7. "threshold": 1,
  8. "keys": [{
  9. "key": "EOS6mzzYJfUq2V55PRLrfu4UqoSt1wKMs6XvbxCFfw4trsnqECC97",
  10. "weight": 1
  11. }
  12. ],
  13. "accounts": []
  14. }
  15. },{
  16. "perm_name": "owner",
  17. "parent": "",
  18. "required_auth": {
  19. "threshold": 1,
  20. "keys": [{
  21. "key": "EOS6mzzYJfUq2V55PRLrfu4UqoSt1wKMs6XvbxCFfw4trsnqECC97",
  22. "weight": 1
  23. }
  24. ],
  25. "accounts": []
  26. }
  27. }
  28. ]
  29. }

在第二讲的时候,我们创建账户的时候输入的是如下命令:
cleos create account eosio [新账户名] [ 生成的公钥 ] [ 生成的公钥 ]
有人会产生这个疑问:为什么公钥要输入两次呢?这一串命令的实际形式是这样的:
cleos create account [授权账户] [新账户名] [所有者(owner)公钥] [活跃(active)公钥]

原文:

  1. owner authority symbolizes ownership of an account. There are only a few transactions that require this authority, but most notably, are actions that make any kind of change to the owner authority. Generally, it is suggested that owner is kept in cold storage and not shared with anyone. owner can be used to recover another permission that may have been compromised.
  2. active authority is used for transferring funds, voting for producers and making other high-level account changes.

2 查看某个公钥下的账户

输入以下命令:
cleos get accounts [公钥]
查看该公钥下的所有账户。
返回如下结果:

  1. {
  2. "account_names": [
  3. "gakki",
  4. "gakkifans"
  5. ]
  6. }

3 查看某个账户下的「仆人」账户

输入以下命令:
cleos get servants [主人账户名]
返回主人账户下的所有仆人账户。
例如我们输入:
cleos get servants eosio
返回如下结果:
{
"controlled_accounts": [
"gakki",
"gakkifans"
]
}

4 绑定「仆人」账户

输入以下命令:
cleos set account permission [「仆人」账户名] [权限名(例如active或者owner)] [一个JSON] [ [授权的权限名,一般是 owner]
例如:
「仆人」账户名: sb2
权限名: active
一个 JSON:

  1. '{"threshold":2,"keys":[{"key":"EOS6mzzYJfUq2V55PRLrfu4UqoSt1wKMs6XvbxCFfw4trsnqECC97","weight":1}],"accounts":[{"permission":{"actor":"gakki","permission":"active"},"weight":1}]}'

授权的权限名: owner
然后这行代码是这样的:

  1. cleos set account permission sb2 active '{"threshold":2,"keys":[{"key":"EOS6mzzYJfUq2V55PRLrfu4UqoSt1wKMs6XvbxCFfw4trsnqECC97","weight":1}],"accounts":[{"permission":{"actor":"gakki","permission":"active"},"weight":1}]}' owner

那么这行鬼画符一样的JSON又是什么呢?别急,让我们继续拆解:
Threshold:一个整数——授权所需的签名权重的和
keys:一个数组——由EOSIO样式的公钥代表的每个权限所组成。
account:一个数组——由EOSIO样式的账户代表的每个权限所组成。

所以,别憷,构建这个JSON很容易,我们只要把这篇文章里的JSON复制过去,然后修改key为「主人」账户的公钥,修改actor为「主人」账户的名字即可。然后还要注意的,就是所有的weight加起来要等于Threshold了。

我们运行这一串命令,返回如下结果即表示操作成功。
image.png-109.7kB
再用cleos get account sb2这个命令查看账户具体信息,发现gakki具有本账户的active权限。
image.png-190.6kB
再用cleos get servants gakki查看一下gakki的仆人,嗯,sb2赫然在列!
image.png-25.7kB

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注