第五篇 - 从零到壹学习EOS - 三连棋
2018-10-08 本文已影响0人
Venture_Mark
查看 cleos 命令
$ cleos
ERROR: RequiredError: Subcommand required
Command Line Interface to EOSIO Client
Usage: cleos [OPTIONS] SUBCOMMAND
Options:
-h,--help 获得帮助信息,使用 -h 或者 --help
-H,--host TEXT=localhost 运行节点主机地址,例如 localhost,则写为 -H localhost 或者 --host localhost
-p,--port UINT=8888 运行节点端口,例如8888,则写为 -p 8888 或者 --port 8888
--wallet-host TEXT=localhost 钱包运行地址
--wallet-port UINT=8888 钱包运行端口
-v,--verbose 输出详细错误操作信息
Subcommands:
version 返回版本信息
create 创建项目,基于或非基于区块链的
get 从区块链返回项目和信息
set 设置或者更新区块链状态
transfer 账户间转移EOS
net 与本地 P2P 网络进行交互
wallet 与本地钱包进行交互
sign 对事务进行签名
push 向区块链推送任意事务
version
version 中 cleos version client
返回客户端的版本信息
$ cleos version client
Build version: d9ad8eec
create
cleos create
主要包含 key
和 account
两个子命令
cleos create key
创建一对新的公钥和私钥
$ cleos create key
Private key: 5JuvDHboUGvNa4uUPAQKc3YwwvrHiUesvmCCG8vpS87wDgRiEuR
Public key: EOS6WkyKPNjcsM3VpynRNFXJtZRtW1tKKByQCXgBjkesLCixhnUgR
cleos create account
$ cleos create account
ERROR: RequiredError: creator
Create a new account on the blockchain
Usage: cleos create account [OPTIONS] creator name OwnerKey ActiveKey
Positionals:
creator TEXT 新账户创建者,例如 eosio
name TEXT 新账户名,例如 mytest
OwnerKey TEXT 新账户 owner 权限公钥
ActiveKey TEXT 新账户 active 权限公钥
Options:
-x,--expiration 设置事务失效时间(秒),默认为 30 秒
-f,--force-unique 确保事务唯一。该操作会消耗额外的带宽并移除保护以防同样的交易被执行
-s,--skip-sign 指定是否应使用解锁的钱包密钥来签署交易
-j,--json 以JSON格式打印结果
-d,--dont-broadcast 不向网络广播事务(仅打印标准输出)
-p,--permission TEXT ... 账户和权限授权,格式如 account@permission (默认为 creator@active)
--max-cpu-usage UINT 设置 CPU 上限,以消耗指令为单位,用于执行事务(默认为 0 即无限制)
--max-net-usage UINT 设置网络上限,以字节为单位,用于事务(默认为 0 即无限制)
$ cleos create account -j eosio mytest EOS6WkyKPNjcsM3VpynRNFXJtZRtW1tKKByQCXgBjkesLCixhnUgR EOS6WkyKPNjcsM3VpynRNFXJtZRtW1tKKByQCXgBjkesLCixhnUgR
{
"transaction_id": "1c927e573364a9a826dfc68bd7215ce4fce8101db3b373c6b05b58f29c62edbd",
"processed": {
"status": "executed",
"kcpu_usage": 100,
"net_usage_words": 44,
"id": "1c927e573364a9a826dfc68bd7215ce4fce8101db3b373c6b05b58f29c62edbd",
"action_traces": [{
"receiver": "eosio",
"context_free": false,
"cpu_usage": 32,
"act": {
"account": "eosio",
"name": "newaccount",
"authorization": [{
"actor": "eosio",
"permission": "active"
}
],
"data": {
"creator": "eosio",
"name": "mytest",
"owner": {
"threshold": 1,
"keys": [{
"key": "EOS6WkyKPNjcsM3VpynRNFXJtZRtW1tKKByQCXgBjkesLCixhnUgR",
"weight": 1
}
],
"accounts": []
},
"active": {
"threshold": 1,
"keys": [{
"key": "EOS6WkyKPNjcsM3VpynRNFXJtZRtW1tKKByQCXgBjkesLCixhnUgR",
"weight": 1
}
],
"accounts": []
},
"recovery": {
"threshold": 1,
"keys": [],
"accounts": [{
"permission": {
"actor": "eosio",
"permission": "active"
},
"weight": 1
}
]
}
},
"hex_data": "0000000000ea30550000000064acb29701000000010002d60cc82b2b85e2207f9721852bc54963cbb2e1954fb3990171e76feea4b000e701000001000000010002d60cc82b2b85e2207f9721852bc54963cbb2e1954fb3990171e76feea4b000e70100000100000000010000000000ea305500000000a8ed32320100"
},
"console": "",
"data_access": [{
"type": "write",
"code": "eosio",
"scope": "eosio.auth",
"sequence": 8
}
],
"_profiling_us": 116
}
],
"deferred_transaction_requests": [],
"read_locks": [],
"write_locks": [{
"account": "eosio",
"scope": "eosio.auth"
}
],
"cpu_usage": 102400,
"net_usage": 352,
"packed_trx_digest": "5e8709dca068c02816e492b084a9e54b0154f312265f71aac9fbeff91420e369",
"region_id": 0,
"cycle_index": 1,
"shard_index": 0,
"_profiling_us": 200,
"_setup_profiling_us": 7876
}
}
get
$ cleos get
ERROR: RequiredError: Subcommand required
Retrieve various items and information from the blockchain
Usage: cleos get SUBCOMMAND
Subcommands:
info 获得当前区块链信息
block 返回块信息
account 返回账户信息
code 返回账户代码和 ABI 接口
table 返回数据库表内容
currency 返回货币信息
accounts 返回指定公钥关联的账户
servants 返回指定账户下属账户
transaction 返回一条交易信息
transactions 返回指定账户所属全部交易信息
cleos get info
获取当前区块链的信息
$ cleos get info
{
"server_version": "d9ad8eec",
"head_block_num": 51011,
"last_irreversible_block_num": 51010,
"head_block_id": "0000c743aa4c825077a07c9c8206aac486bfde7bfb778c0c130dc99ee962cbac",
"head_block_time": "2018-05-02T07:26:30",
"head_block_producer": "eosio"
}
cleos get block
根据 block的块号 ( block_num ) 和 id 进行查询。
cleos get block 110
根据区块的 block_num
进行查询。
$ cleos get block 110
{
"previous": "0000006defbb2da98061a90254e25505b35b02632e3391d9ab803b1c4ade0533",
"timestamp": "2018-04-28T08:59:08.000",
"transaction_mroot": "7855e31417ce3a872842735bf4e341e91cc3685b57d408180b6f3f4bb7f66cc3",
"action_mroot": "dd415b823d7b65cb3345bbb3242fccad0739b790d4c5b7a25d0a1a26987f5f49",
"block_mroot": "41380e040cdf9e920b3bcd37a196a137fa44c0aaeeed986313869478b47936f8",
"producer": "eosio",
"schedule_version": 0,
"new_producers": null,
"producer_signature": "EOSKkdibZKi49uPY3JteEC8nNiuArnAeNesZp1PzaX35HBp9uoJm55rHPfPSmztvKJTpZdwcpyNxfzM8ngaqBG4Jv7FvQTQAj",
"regions": [{
"region": 0,
"cycles_summary": [[{
"read_locks": [],
"write_locks": [],
"transactions": [{
"status": "executed",
"kcpu_usage": 2,
"net_usage_words": 38,
"id": "1652d2926aad12476cd3a0393575201d06b491d82bd88326c9f6ad36da1decf4"
}
]
}
]
]
}
],
"input_transactions": [],
"id": "0000006e01966c10a54dedc1e7786c8996940e5734cbadeb64636603d46bca1d",
"block_num": 110,
"ref_block_prefix": 3253554597
}
cleos get block 0000006e01966c10a54dedc1e7786c8996940e5734cbadeb64636603d46bca1d
根据区块的 id 进行查询
$ cleos get block 0000006e01966c10a54dedc1e7786c8996940e5734cbadeb64636603d46bca1d
{
"previous": "0000006defbb2da98061a90254e25505b35b02632e3391d9ab803b1c4ade0533",
"timestamp": "2018-04-28T08:59:08.000",
"transaction_mroot": "7855e31417ce3a872842735bf4e341e91cc3685b57d408180b6f3f4bb7f66cc3",
"action_mroot": "dd415b823d7b65cb3345bbb3242fccad0739b790d4c5b7a25d0a1a26987f5f49",
"block_mroot": "41380e040cdf9e920b3bcd37a196a137fa44c0aaeeed986313869478b47936f8",
"producer": "eosio",
"schedule_version": 0,
"new_producers": null,
"producer_signature": "EOSKkdibZKi49uPY3JteEC8nNiuArnAeNesZp1PzaX35HBp9uoJm55rHPfPSmztvKJTpZdwcpyNxfzM8ngaqBG4Jv7FvQTQAj",
"regions": [{
"region": 0,
"cycles_summary": [[{
"read_locks": [],
"write_locks": [],
"transactions": [{
"status": "executed",
"kcpu_usage": 2,
"net_usage_words": 38,
"id": "1652d2926aad12476cd3a0393575201d06b491d82bd88326c9f6ad36da1decf4"
}
]
}
]
]
}
],
"input_transactions": [],
"id": "0000006e01966c10a54dedc1e7786c8996940e5734cbadeb64636603d46bca1d",
"block_num": 110,
"ref_block_prefix": 3253554597
}
cleos get account
获取相应的账号信息
$ cleos get account mytest
{
"account_name": "mytest",
"permissions": [{
"perm_name": "active",
"parent": "owner",
"required_auth": {
"threshold": 1,
"keys": [{
"key": "EOS6WkyKPNjcsM3VpynRNFXJtZRtW1tKKByQCXgBjkesLCixhnUgR",
"weight": 1
}
],
"accounts": []
}
},{
"perm_name": "owner",
"parent": "",
"required_auth": {
"threshold": 1,
"keys": [{
"key": "EOS6WkyKPNjcsM3VpynRNFXJtZRtW1tKKByQCXgBjkesLCixhnUgR",
"weight": 1
}
],
"accounts": []
}
}
]
}
cleos get code
返回指定账户名的代码信息
$ cleos get code mytest
code hash: 0000000000000000000000000000000000000000000000000000000000000000
cleos get table
返回指定表信息
$ cleos get table
ERROR: RequiredError: contract
Retrieve the contents of a database table
Usage: cleos get table [OPTIONS] contract scope table
Positionals:
contract TEXT 拥有数据表的合约名称
scope TEXT 目标表相关合约作用域
table TEXT 合约 ABI 文件指定的表名称
Options:
-b,--binary UINT 将值以二进制形式返回
-l,--limit UINT 设置最大返回行数
-k,--key TEXT ABI 定义的索引键,默认为主键
-L,--lower TEXT JSON representation of lower bound value of key, defaults to first
-U,--upper TEXT JSON representation of upper bound value value of key, defaults to last
$ cleos get table eosio.token user account
{
"rows": [],
"more": false
}
# 没有查询出数据,存在问题
cleos get currency
$ cleos get currency
ERROR: RequiredError: Subcommand required
Retrieve information related to standard currencies
Usage: cleos get currency [OPTIONS] SUBCOMMAND
Options:
-h,--help Print this help message and exit
Subcommands:
balance 返回账户内指定货币的余额
stats 返回指定货币的统计信息
cleos get currency balance
$ cleos get currency balance
ERROR: RequiredError: contract
Retrieve the balance of an account for a given currency
Usage: cleos get currency balance contract account [symbol]
Positionals:
contract TEXT 货币合约名称
account TEXT 查询账户
symbol TEXT 指定货币符号,例如 EOS ,此项非必须
$ cleos get currency balance eosio.token user
75.0000 EOS
cleos get currency stats
$ cleos get currency stats
ERROR: RequiredError: contract
Retrieve the stats of for a given currency
Usage: cleos get currency stats contract [symbol]
Positionals:
contract TEXT 货币合约名称
symbol TEXT 指定货币符号,例如 EOS ,此项非必须
$ cleos get currency stats eosio.token
{}
# 未返回任何信息,存在问题
cleos get accounts
$ cleos get accounts
ERROR: RequiredError: public_key
Retrieve accounts associated with a public key
Usage: cleos get accounts public_key
Positionals:
public_key TEXT 指定想返回其关联账户的公钥
$ cleos get accounts EOS7dhCfJx1W5JLNt8u5AaEBrMfqiZzcVuo9PoPWjsxuuzZE36eXE
{
"account_names": [
"eosio.token",
"tester",
"user"
]
}
cleos get servants
$ cleos get servants
ERROR: RequiredError: account
Retrieve accounts which are servants of a given account
Usage: cleos get servants account
Positionals:
account TEXT 指定想返回其控制账户的账户名
$ cleos get servants eosio
{
"controlled_accounts": [
"eosio.token",
"tester",
"user"
]
}
$ cleos get transactions
ERROR: RequiredError: account_name
Retrieve all transactions with specific account name referenced in their scope
Usage: cleos get transactions [OPTIONS] account_name [skip_seq] [num_seq]
Positionals:
account_name TEXT 目标账户名
skip_seq TEXT 交易起始号,例如想从第 3 条交易开始返回信息,就填 3 (交易起始 seq_num 为 0),此项非必须 num_seq TEXT 返回数据的数量
Options:
-j,--json print full json
$ cleos get transactions user -j
{
"transactions": [{
"seq_num": 0,
"transaction_id": "994f170977008e2b26b12fab4012ea820236d21be602688efaff7a75797d56c4",
"transaction": {
"signatures": [
"EOSK6DutajTW6dEG97x9AmABGVo5DUK2pGnv7e3HtoUqVxj4LzVQjAFAbeMiwz1dVspL4CsyxbhKi8meuCXmntfn7ndv3ociD"
],
"compression": "none",
"packed_context_free_data": "",
"context_free_data": [],
"packed_trx": "4729e85a0000922f614b7ebb000000000100a6823403ea3055000000572d3ccdcd0100000000007015d600000000a8ed32322200000000007015d6000000005c95b1ca90d003000000000004454f5300000000016d",
"transaction": {
"expiration": "2018-05-01T08:45:59",
"region": 0,
"ref_block_num": 12178,
"ref_block_prefix": 3145616225,
"max_net_usage_words": 0,
"max_kcpu_usage": 0,
"delay_sec": 0,
"context_free_actions": [],
"actions": [{
"account": "eosio.token",
"name": "transfer",
"authorization": [{
"actor": "user",
"permission": "active"
}
],
"data": {
"from": "user",
"to": "tester",
"quantity": "25.0000 EOS",
"memo": "m"
},
"hex_data": "00000000007015d6000000005c95b1ca90d003000000000004454f5300000000016d"
}
]
}
}
},{
"seq_num": 1,
"transaction_id": "5c293faaec455bf2b26bf3b2eb05c320a2aa3956085a1ad428ae2e53ff5091c0",
"transaction": {
"signatures": [
"EOSK3jt3GKJqiV32tG4vZuLprk1J7324ZkQc8eRYr6S8n1ctsoJYAdLFr2YWVYh2T9qCHHq8rkrWmAfDWUsVcfydUDbDhcVv2"
],
"compression": "none",
"packed_context_free_data": "",
"context_free_data": [],
"packed_trx": "d228e85a0000a92e7ac138db000000000100a6823403ea30550000000000a53176010000000000ea305500000000a8ed32321d00000000007015d640420f000000000004454f5300000000046d656d6f",
"transaction": {
"expiration": "2018-05-01T08:44:02",
"region": 0,
"ref_block_num": 11945,
"ref_block_prefix": 3677929850,
"max_net_usage_words": 0,
"max_kcpu_usage": 0,
"delay_sec": 0,
"context_free_actions": [],
"actions": [{
"account": "eosio.token",
"name": "issue",
"authorization": [{
"actor": "eosio",
"permission": "active"
}
],
"data": {
"to": "user",
"quantity": "100.0000 EOS",
"memo": "memo"
},
"hex_data": "00000000007015d640420f000000000004454f5300000000046d656d6f"
}
]
}
}
}
]
}
cleos get transaction
根据 transaction 的 id 查看详细信息。
$ cleos get transaction
ERROR: RequiredError: id
Retrieve a transaction from the blockchain
Usage: cleos get transaction id
Positionals:
id TEXT 交易的id
$ cleos get transaction 5c293faaec455bf2b26bf3b2eb05c320a2aa3956085a1ad428ae2e53ff5091c0
{
"transaction_id": "5c293faaec455bf2b26bf3b2eb05c320a2aa3956085a1ad428ae2e53ff5091c0",
"transaction": {
"signatures": [
"EOSK3jt3GKJqiV32tG4vZuLprk1J7324ZkQc8eRYr6S8n1ctsoJYAdLFr2YWVYh2T9qCHHq8rkrWmAfDWUsVcfydUDbDhcVv2"
],
"compression": "none",
"packed_context_free_data": "",
"context_free_data": [],
"packed_trx": "d228e85a0000a92e7ac138db000000000100a6823403ea30550000000000a53176010000000000ea305500000000a8ed32321d00000000007015d640420f000000000004454f5300000000046d656d6f",
"transaction": {
"expiration": "2018-05-01T08:44:02",
"region": 0,
"ref_block_num": 11945,
"ref_block_prefix": 3677929850,
"max_net_usage_words": 0,
"max_kcpu_usage": 0,
"delay_sec": 0,
"context_free_actions": [],
"actions": [{
"account": "eosio.token",
"name": "issue",
"authorization": [{
"actor": "eosio",
"permission": "active"
}
],
"data": {
"to": "user",
"quantity": "100.0000 EOS",
"memo": "memo"
},
"hex_data": "00000000007015d640420f000000000004454f5300000000046d656d6f"
}
]
}
}
}
set
$ cleos set
ERROR: RequiredError: Subcommand required
Set or update blockchain state
Usage: cleos set [OPTIONS] SUBCOMMAND
Options:
-h,--help Print this help message and exit
Subcommands:
contract 基于账户创建或更新合约
account 设置或更新区块链账户状况
action 设置或更新区块链操作状况
cleos set contract
$ cleos set contract
ERROR: RequiredError: account
Create or update the contract on an account
Usage: cleos set contract [OPTIONS] account contract-dir [wast-file] [abi-file]
Positionals:
account TEXT 发行合约的账户
contract-dir TEXT .wast 和 .abi 文件路径
wast-file TEXT 相对于合约文件夹, WAST 文件路径,此项非必须relative to contract-dir
abi-file TEXT 相对于合约文件夹, ABI 文件路径,此项非必须
Options:
-h,--help 打印帮助信息
-a,--abi TEXT 相对于合约文件夹, ABI 文件路径
-x,--expiration 设置交易失效时间(秒),默认为 30 秒
-f,--force-unique 确保交易唯一。该操作会消耗额外的带宽并移除保护以防同样的交易被执行
-s,--skip-sign 指定是否应使用解锁的钱包密钥来签署交易
-j,--json 以JSON格式打印结果
-d,--dont-broadcast 不向网络广播事务(仅打印标准输出)
-p,--permission TEXT ... 账户和权限授权,格式如 account@permission (默认为 creator@active)
--max-cpu-usage UINT 设置 CPU 上限,以消耗指令为单位,用于执行事务(默认为 0 即无限制)
--max-net-usage UINT 设置网络上限,以字节为单位,用于事务(默认为 0 即无限制)
$ cleos set contract eosio.test build/contracts/currency -j -p eosio.test
Reading WAST...
Assembling WASM...
Publishing contract...
{
"transaction_id": "c6d5b640b42aaccd50f209f92a489c10b12b8b8d736ec27af59acfe28ac87692",
"processed": {
"status": "executed",
"kcpu_usage": 2149,
"net_usage_words": 889,
"id": "c6d5b640b42aaccd50f209f92a489c10b12b8b8d736ec27af59acfe28ac87692",
"action_traces": [{
"receiver": "eosio",
"context_free": false,
"cpu_usage": 0,
"act": {
"account": "eosio",
"name": "setcode",
...
wallet
$ cleos wallet
ERROR: RequiredError: Subcommand required
Interact with local wallet
Usage: cleos wallet SUBCOMMAND
Subcommands:
create 创建本地新钱包
open 加载已存在钱包
lock 锁定钱包
lock_all 锁定所有钱包
unlock 解锁钱包
import 将私钥导入钱包
list 已加载钱包列表,钱包名后带有 * 代表此钱包未锁定
keys 未锁定钱包含有的公/私钥对
cleos wallet create
通过 -n
指定相应的钱包的名字
$ cleos wallet create -n test
Creating wallet: test
Save password to use in the future to unlock this wallet.
Without password imported keys will not be retrievable.
"PW5JR9veZBwZHouT6dk3Z3i3Zp7AFmPdBd7CaHfzvu13YbK7UQ6Ky"
cleos wallet open
通过 -n
打开相应的钱包
$ cleos wallet open
Opened: default
$ cleos wallet open -n test
Opened: test
cleos wallet lock
通过 -n
打开相应的钱包
$ cleos wallet lock
Locked: default
$ cleos wallet lock -n test
Locked: test
cleos wallet lock_all
$ cleos wallet lock_all
Locked All Wallets
cleos wallet unlock
$ cleos wallet unlock --password PW5KhQAW7G2BafbXiQSMV9PaNzqz118Uxj9S8VYZB2k6MNxSqNdmc
Unlocked: default
$ cleos wallet unlock -n default --password PW5KhQAW7G2BafbXiQSMV9PaNzqz118Uxj9S8VYZB2k6MNxSqNdmc
Unlocked: default
cleos wallet import
将 私钥 导入到钱包中
$ cleos wallet import
ERROR: RequiredError: key
Import private key into wallet
Usage: cleos wallet import [OPTIONS] key
Positionals:
key TEXT Private key in WIF format to import
Options:
-n,--name TEXT The name of the wallet to import key into
$ cleos wallet import 5JFAuV51Tu2pSSBrHLwiGjUohptSwHXYDvaXcRLd3LUEYGGLifF
imported private key for: EOS7AYodYDaYGixh9A7rusCnqLFXTX8BUHc7RsLQSNX2FHNwz8tez
cleos wallet list
$ cleos wallet list
Wallets:
[
"default *",
"test"
]
cleos wallet keys
返回所有解锁钱包含有的公/私钥对
$ cleos wallet keys
[[
"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
],[
"EOS7AYodYDaYGixh9A7rusCnqLFXTX8BUHc7RsLQSNX2FHNwz8tez",
"5JFAuV51Tu2pSSBrHLwiGjUohptSwHXYDvaXcRLd3LUEYGGLifF"
],[
"EOS7dhCfJx1W5JLNt8u5AaEBrMfqiZzcVuo9PoPWjsxuuzZE36eXE",
"5K4DKcS4qgDZ56qT8M7Z6SaJTw1FgTuPUWijmazYv1PUeuNuTFp"
],[
"EOS7psBkfWEr4W4xXa5iqqBimuMcpZrs3asM86xWSYAzQiBuXfnW6",
"5JrA4HTsUM9gQe6eQPyct1WAToNZQXK4gnDt3Ln57jtC4AWT6Nr"
]
]
push
cleos push action
推送一条操作事务
$ cleos push action
Positionals:
contract TEXT 执行合约账户
action TEXT 合约定义的操作方法
data TEXT 具体操作数据
$ cleos push action eosio.token transfer '[ "user", "tester", "25.0000 EOS", "m" ]' -p user
executed transaction: 0a72215bc435a06bdf275f123aaa25c0e897b63ed0ea3b8a8a068fcae3bc92ba 256 bytes 110592 cycles
# eosio.token <= eosio.token::transfer {"from":"user","to":"tester","quantity":"25.0000 EOS","memo":"m"}
>> transfer
# user <= eosio.token::transfer {"from":"user","to":"tester","quantity":"25.0000 EOS","memo":"m"}
# tester <= eosio.token::transfer {"from":"user","to":"tester","quantity":"25.0000 EOS","memo":"m"}