账户相关常用操作
1. 创建账户
有多种方法可以创建账户。如:
- cleos create account
- cleos system newaccount
- cleos push action newaccount
1.1 cleos create account
使用方式为 cleos create account [OPTIONS] creator name OwnerKey [ActiveKey]。
$ cleos create account eosio alice EOS84BLRbGbFahNJEpnnJHYCoW9QPbQEk2iHsHGGS6qcVUq9HhutG
executed transaction: b146e19ba664ef4bf973a34e25bc2f5f22cd8b193aacaff136f3bd51bc14c0b2 200 bytes 166 us
$ cleos create account eosio alice EOS84BLRbGbFahNJEpnnJHYCoW9QPbQEk2iHsHGGS6qcVUq9HhutG -p eosio@active
$ cleos create account eosio alice EOS84BLRbGbFahNJEpnnJHYCoW9QPbQEk2iHsHGGS6qcVUq9HhutG EOS8mUftJXepGzdQ2TaCduNuSPAfXJHf22uex4u41ab1EVv9EAhWt
$ cleos create account eosio alice EOS84BLRbGbFahNJEpnnJHYCoW9QPbQEk2iHsHGGS6qcVUq9HhutG EOS8mUftJXepGzdQ2TaCduNuSPAfXJHf22uex4u41ab1EVv9EAhWt -p eosio@active
$ cleos create account eosio bob EOS84BLRbGbFahNJEpnnJHYCoW9QPbQEk2iHsHGGS6qcVUq9HhutG --json
$ cleos create account eosio charlie EOS84BLRbGbFahNJEpnnJHYCoW9QPbQEk2iHsHGGS6qcVUq9HhutG --json --max-cpu-usage-ms 100000 --max-net-usage 1048576
注意,这里的选项 --max-cpu-usage-ms 和 --max-net-usage 是指本交易最大能够消耗的资源,而不是质押给被创建账户的。
1.2 cleos system newaccount
$ cleos system newaccount eosio alice EOS84BLRbGbFahNJEpnnJHYCoW9QPbQEk2iHsHGGS6qcVUq9HhutG --stake-net "100 EOS" --stake-cpu "100 EOS" --buy-ram "100 EOS" -p eosio@active
1.3 cleos push action newaccount
$ cleos push action eosio newaccount '{"creator" : eosio, "name" : "test11", "owner" : {"threshold": 1, "keys": [{"key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", "weight": 1}], "accounts": [], "waits": []}, "active" : {"threshold": 1, "keys": [{"key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", "weight": 1}], "accounts": [], "waits": []}}' -p eosio@active
2. 查询账户的详细信息
$ cleos get account eosio
created: 2018-06-08T08:08:08.500
privileged: true
permissions:
owner 1: 1 eosio.prods@active
active 1: 1 eosio.prods@active
memory:
quota: unlimited used: 38.12 MiB
net bandwidth:
used: unlimited
available: unlimited
limit: unlimited
cpu bandwidth:
used: unlimited
available: unlimited
limit: unlimited
EOS balances:
liquid: 0.0041 EOS
staked: 0.0000 EOS
unstaking: 0.0000 EOS
total: 0.0041 EOS
$ $ cleos get account eosio 4,EOS
$ cleos get account eosio --json
3. 查询对应公钥的账户列表
获取指定公钥对应的账户列表。使用方式 cleos get accounts public_key。
$ cleos get accounts EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
{
"account_names": [
"1111sutaiyun",
"5555sutaiyun",
"aliaoquanlei",
"sutaiyunnnnn"
]
}
其中:
- EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV 是公钥
4. 获取指定账户的从属账户
获取给定账号的附属账号列表。使用方式 cleos get servants account。
$ cleos get servants eosio
{
"controlled_accounts": [
"eosio.bpay",
"eosio.msig",
"eosio.names",
"eosio.ram",
"eosio.ramfee",
"eosio.saving",
"eosio.stake",
"eosio.token",
"eosio.unregd",
"eosio.vpay"
]
}
其中:
- eosio 是账户名称
5. 更新账户权限
更新账户权限。使用方式 cleos set account permission [OPTIONS] account permission [authority] [parent]。
上面的使用方式是不是书写错误,因为这个是从 cleos 输出的帮助信息。正确的是不是应该是 cleos set account permission [authority] [parent] [OPTIONS]。
5.1 更新 owner 权限
$ cleos set account permission alice owner '{ "threshold": 1, "waits": [], "keys": [{"key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", "weight": 1}], "accounts": []}' -p alice@owner
5.2 更新 active 权限
$ cleos set account permission alice active '{"accounts": [], "keys": [{"key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", "weight": 1}], "threshold": 1, "waits": []}' owner -p alice@active
其中:
- alice 是账户名称
- active 是权限
- json 字符串描述的是 authority
- owner 是 parent,即本权限的父权限
执行上述命令之后,alice 的权限 active 即由之前的公钥改成了 EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV。
项目源代码
项目源代码会逐步上传到 Github,地址为 https://github.com/windstamp/blockchain。
Contributor
- Windstamp, https://github.com/windstamp