经验分享 cleos 命令解析 (1)

OuterST · 2018年05月30日 · 最后由 maoGod 回复于 2018年10月26日 · 7823 次阅读
本帖已被设为精华帖!

启动nodes和删除本地数据

nodeos -e -p eosio --plugin eosio::wallet_api_plugin --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin   

rm -rf ~/.local/share/eosio/nodeos/data/ ~/eosio-wallet/default.wallet 

1. cleos

Options:
-h,--help Print this help message and exit
-u,--url TEXT=http://localhost:8888/
the http/https URL where nodeos is running
--wallet-url TEXT=http://localhost:8900/
the http/https URL where keosd is running
-r,--header pass specific HTTP header; repeat this option to pass multiple headers
-n,--no-verify don't verify peer certificate when using HTTPS
-v,--verbose output verbose actions on error

Subcommands:
version Retrieve version information
create Create various items, on and off the blockchain
get Retrieve various items and information from the blockchain
set Set or update blockchain state
transfer Transfer EOS from account to account
net Interact with local p2p network connections
wallet Interact with local wallet
sign Sign a transaction
push Push arbitrary transactions to the blockchain
multisig Multisig contract commands
system Send eosio.system contract action to the blockchain.

2. cleos version

查看客户端版本

cleos version client
"/usr/local/bin/keosd" launched
Build version: 60231e3e

3. cleos wallet

Subcommands:
create Create a new wallet locally
open Open an existing wallet
lock Lock wallet
lock_all Lock all unlocked wallets
unlock Unlock wallet
import Import private key into wallet
create_key Create private key within wallet
list List opened wallets, * = unlocked
keys List of private keys from all unlocked wallets in wif format.
stop Stop keosd (doesn't work with nodeos).

3.1 wallet create

创建钱包

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.
"PW5J76aYmk8dFr39jpB87K9nE7TUm2iMJxFDPrvXb8EzBaXKAMNPm"

3.2 wallet open

打开钱包

cleos wallet open
Opened: default

3.3 wallet lock

锁定钱包,-n name 指定name钱包

cleos wallet lock
Locked: default

cleos wallet lock -n default
Locked: default

3.4 wallet lock_all

锁定所有钱包

cleos wallet lock_all
Locked All Wallets

3.5 wallet unlock

解锁钱包

cleos wallet unlock --password PW5J76aYmk8dFr39jpB87K9nE7TUm2iMJxFDPrvXb8EzBaXKAMNPm
Unlocked: default

3.6 wallet import

导入的是下面生成key的私钥

cleos wallet import 5HvJjAfg6P7z8E2EHDFtF1J4EZzuUZXbHw3ZnqGwEYep71WAhMZ
imported private key for: EOS5738kwE2Cc1PenVLcisdjqA15fNp3C1TYhQGWkaSQaYa6o2edw

3.7 wakket create_key

创建私钥,并导入钱包

cleos wallet create_key
Created new private key with a public key of: "EOS692yxcwkjdcCo121znDUhZQtPT1tCzWrceabm6JUcJ1RhN8dR1"

3.8 wallet list

查看钱包列表

cleos wallet list
Wallets:
[
"default *"
]

3.9 wallet keys

查看钱包已经导入的key

cleos wallet keys
[[
"EOS5738kwE2Cc1PenVLcisdjqA15fNp3C1TYhQGWkaSQaYa6o2edw",
"5HvJjAfg6P7z8E2EHDFtF1J4EZzuUZXbHw3ZnqGwEYep71WAhMZ"
],[
"EOS692yxcwkjdcCo121znDUhZQtPT1tCzWrceabm6JUcJ1RhN8dR1",
"5JRsB7jE3eXkSmsLQPvoGVzZZVgvS1navY1U7eGkZECmDPsKCkK"
],[
"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
]
]

3.10 stop

cleos wallet stop
OK

4. cleos create

Subcommands:
 key Create a new keypair and print the public and private keys
 account Create an account, buy ram, stake for bandwidth for the account

4.1 cleos create key

创建key

cleos create key
Private key: 5HvJjAfg6P7z8E2EHDFtF1J4EZzuUZXbHw3ZnqGwEYep71WAhMZ
Public key: EOS5738kwE2Cc1PenVLcisdjqA15fNp3C1TYhQGWkaSQaYa6o2edwc

4.2 cleos create account

创建账号

cleos create account eosio ost EOS5738kwE2Cc1PenVLcisdjqA15fNp3C1TYhQGWkaSQaYa6o2edw
executed transaction: 66ebd9285875c4631649a73d9999c4ffd5ed4cec3b3497703bbcad0b989bbfda 200 bytes 665 us
# eosio <= eosio::newaccount {"creator":"eosio","name":"ost","owner":{"threshold":1,"keys":[{"key":"EOS5738kwE2Cc1PenVLcisdjqA15f...

5 cleos get

Options:
 -h,--help Print this help message and exit
 -u,--url TEXT=http://localhost:8888/
 the http/https URL where nodeos is running
 --wallet-url TEXT=http://localhost:8900/
 the http/https URL where keosd is running
 -r,--header pass specific HTTP header; repeat this option to pass multiple headers
 -n,--no-verify don't verify peer certificate when using HTTPS
 -v,--verbose output verbose actions on error

Subcommands:
 version Retrieve version information
 create Create various items, on and off the blockchain
 get Retrieve various items and information from the blockchain
 set Set or update blockchain state
 transfer Transfer EOS from account to account
 net Interact with local p2p network connections
 wallet Interact with local wallet
 sign Sign a transaction
 push Push arbitrary transactions to the blockchain
 multisig Multisig contract commands
 system Send eosio.system contract action to the blockchain.

5.1 get info

获取信息

cleos get info
{
 "server_version": "60231e3e",
 "head_block_num": 18572,
 "last_irreversible_block_num": 18571,
 "last_irreversible_block_id": "0000488bca0c990127cce2dc65a7b8f69c2a3f0f331998fb8804798e6b8f1ef1",
 "head_block_id": "0000488ccd04b9ebd58afd5bf977b6333c4249c19fb1dd691d6320b03bce93bf",
 "head_block_time": "2018-05-28T06:01:13",
 "head_block_producer": "eosio",
 "virtual_block_cpu_limit": 200000000,
 "virtual_block_net_limit": 1048576000,
 "block_cpu_limit": 199900,
 "block_net_limit": 1048576
}

5.2 get block

获取区块信息

cleos get block 1
{
 "timestamp": "2018-03-02T12:00:00.000",
 "producer": "",
 "confirmed": 1,
 "previous": "0000000000000000000000000000000000000000000000000000000000000000",
 "transaction_mroot": "0000000000000000000000000000000000000000000000000000000000000000",
 "action_mroot": "144b6ab7924ea47bae7a5846b4494a35563ae816e2ed5affa7a9c990c2b3cfb3",
 "schedule_version": 0,
 "new_producers": null,
 "header_extensions": [],
 "producer_signature": "SIG_K1_111111111111111111111111111111111111111111111111111111111111111116uk5ne",
 "transactions": [],
 "block_extensions": [],
 "id": "0000000118f82f39c450da47f609bb0ab2b59343a070be6c6c128a36068f91e3",
 "block_num": 1,
 "ref_block_prefix": 1205489860
}

5.3 get account

获取账号信息

cleos get account ost
privileged: false
permissions: 
 owner 1: 1 EOS5738kwE2Cc1PenVLcisdjqA15fNp3C1TYhQGWkaSQaYa6o2edw
 active 1: 1 EOS5738kwE2Cc1PenVLcisdjqA15fNp3C1TYhQGWkaSQaYa6o2edw
memory: 
 quota: -1 bytes used: 2.66 Kb

net bandwidth: (averaged over 3 days)
 used: -1 bytes
 available: -1 bytes
 limit: -1 bytes

cpu bandwidth: (averaged over 3 days)
 used: -1 us 
 available: -1 us 
 limit: -1 us

5.4 get code

获取code,如果部署合约后,hash会有变化

cleos get code ost
code hash: 0000000000000000000000000000000000000000000000000000000000000000

5.5 get abi

获取账号对应的abi

cleos get abi eosio
{
       ... 这里有个很长的json....
}

5.6 get table

需要先部署合约eosio.token

cleos set contract ost build/contracts/eosio.token -p ost

获取表数据

cleos get table ost ost accounts
{
 "rows": [],
 "more": false
}

5.7 get currency
需要先发币,转账

cleos push action ost create '["ost","10000.0000 SYS"]' -p ost
cleos push action ost issue '["ost","10000.0000 SYS"]' -p ost
cleos push action ost create '["ost","10000.0000 EOS"]' -p ost
cleos push action ost issue '["ost","10000.0000 EOS"]' -p ost

get currency balance
获取token值

cleos get currency balance ost ost
10000.0000 EOS
10000.0000 SYS

get currency stats
获取账号对应的tokeni信息


cleos get currency stats ost SYS
{
 "SYS": {
 "supply": "10000.0000 SYS",
 "max_supply": "10000.0000 SYS",
 "issuer": "ost"
 }
}

5.8 get accounts

获取账号信息

cleos get accounts EOS5738kwE2Cc1PenVLcisdjqA15fNp3C1TYhQGWkaSQaYa6o2edw
{
 "account_names": [
 "ost"
 ]
}

5.9 get servants

获取子账号信息
ps:暂时了解的是由ost创建的子账号才会获取到,暂时不知道怎么创建关联子账号

cleos get servants ost
{
 "controlled_accounts": []
}

5.10 get transaction

获取交易信息

cleos get transaction 1
{
 "id": "1000000000000000000000000000000000000000000000000000000000000000",
 "trx": null,
 "block_time": "2000-01-01T00:00:00.000",
 "block_num": 0,
 "last_irreversible_block": 32733,
 "traces": []
}

5.11 get actions

获取动作

cleos get actions ost -j
{
 "actions": [],
 "last_irreversible_block": 32840
}

6. cleos set

Options:
 -h,--help Print this help message and exit

Subcommands:
 code Create or update the code on an account
 abi Create or update the abi on an account
 contract Create or update the contract on an account
 account set or update blockchain account state
 action set or update blockchain action state

6.1 set code

设置wast or wasm

cleos set code eosio build/contracts/eosio.system/eosio.system.wasm
Reading WAST/WASM from build/contracts/eosio.system/eosio.system.wasm...
Using already assembled WASM...
Setting Code...
executed transaction: d41c186dc221233540cb6e45de121c3bdbd369b48a6d18b7257fdb4aa1eeb376 43216 bytes 3767 us
# eosio <= eosio::setcode {"account":"eosio","vmtype":0,"vmversion":0,"code":"0061736d0100000001c5023160027f7e0060067f7e7e7f7f...
warning: transaction executed locally, but may not be confirmed by the network yet

6.2 set abi

设置abi

Positionals:
 account TEXT The account to set the ABI for
 abi-file TEXT The fullpath containing the contract WAST or WASM

Options:
 -h,--help Print this help message and exit
 -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' (defaults to 'account@active')
 --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)

这里的abi-file的说明是wast或者wasm,但实际操作却不行。更改成abi文件同样也行不通。

cleos set abi eosio build/contracts/eosio.token/eosio.token.abi

6.3 set contract

设置合约

cleos set contract eosio build/contracts/eosio.token/ -p eosio
Reading WAST/WASM from build/contracts/eosio.token/eosio.token.wasm...
Using already assembled WASM...
Publishing contract...
executed transaction: 5d97ad9844177df488eafad21164877025c85a261a21fac1da49ef791a9fef39 8096 bytes 1672 us
# eosio <= eosio::setcode "0000000000ea305500009594010061736d01000000017e1560037f7e7f0060057f7e7e7f7f0060047f7e7f7f00600000600...
# eosio <= eosio::setabi "0000000000ea3055b4030e656f73696f3a3a6162692f312e30010c6163636f756e745f6e616d65046e616d6505087472616...
warning: transaction executed locally, but may not be confirmed by the network yet

6.4 set account

设置账号权限

cleos set account permission ost active '{"threshold":2,"keys":[{"key":"EOS5738kwE2Cc1PenVLcisdjqA15fNp3C1TYhQGWkaSQaYa6o2edw","weight":1}],"accounts":[{"permission":{"actor":"eosio","permission":"active"},"weight":1}]}' owner
executed transaction: 05f9ce1719a6a4ef38e562ad6788baa14b1920d2c65c7aac3c4a6e90ad3a27c3 184 bytes 614 us
# eosio <= eosio::updateauth "00000000000032a600000000a8ed32320000000080ab26a7020000000100021c7ddcb0ba99e51bd7f641a14a0c07600ee51...
warning: transaction executed locally, but may not be confirmed by the network yet

6.5 set action

设置动作权限,暂时不知道具体格式。

Usage: cleos set action permission [OPTIONS] account code type requirement

Positionals:
 account TEXT The account to set/delete a permission authority for
 code TEXT The account that owns the code for the action
 type TEXT the type of the action
 requirement TEXT [delete] NULL, [set/update] The permission name require for executing the given action
共收到 9 条回复

get transaction
为什么总是空的

strahe 将本帖设为了精华贴 05月31日 18:12

chuck@chuck-MacBook-Pro:~/opensource/eos(master↑1|✚1) % cleos create account eosio ost EOS5738kwE2Cc1PenVLcisdjqA15fNp3C1TYhQGWkaSQaYa6o2edw (master↑1|✚1)
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.

seaify 回复

看一下这个私钥导入了没

cleos wallet import --private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3

对应公钥:EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV

OuterST 回复

感谢,是没导入私钥的问题,导入就好了. 只是有些不理解,create account为什么一定要先导入私钥呢?

seaify 回复

那个私钥是eosio的私钥。创建的账号,其实是eosio的子账号

OuterST 回复

感谢,完全懂了,EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV, 就是默认的eosio账号,而eosio应该是系统创建的第一批账号,用户的账号只能先从eosio这种账号产生出来吧

seaify 回复

第一批只有一个就是eosio,其他都是他的子账号或者更下级账号

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. 检查了下eosio的私钥也导入了 钱包也是解锁状态的 为啥还会报这个错误


有大佬遇到这样的问题吗

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册