介绍
cleos是一个命令行工具,它与nodeos公开的REST API接口。为了使用cleos,您需要有一个nodeos实例的端点(IP地址和端口号),还需要配置nodeos来加载“eosio::chain_api_plugin”。
Command Line Interface to EOSIO Client
Usage: ./programs/cleos/cleos [OPTIONS] SUBCOMMAND
Options:
-h,--help Print this help message and exit
-u,--url http://localhost:8888/ nodeos运行地址
--wallet-url http://localhost:8900/ keosd 运行地址
-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.
keosd是由cleos自动启动的。在进行开发和测试时,keosd可能是手动启动的(不是由cleos启动的),最终可能会运行多个keosd进程。当keosd的多个实例在同一台服务器上运行时,您可能会发现cleos命令没有找到正确的键集。要检查keosd的多个实例是否正在运行,以及它们在哪些端口上运行,可以尝试以下方法来隔离使用中的keosd进程和端口:
$ pgrep keosd | xargs printf " -p %d" | xargs lsof -Pani
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
keosd 49590 tutorial 6u IPv4 0x72cd8ccf8c2c2d03 0t0 TCP 127.0.0.1:8900 (LISTEN)
keosd 62812 tutorial 7u IPv4 0x72cd8ccf90428783 0t0 TCP 127.0.0.1:8899 (LISTEN)
管理节点
config.ini文件中加入plugin = eosio::net_api_plugin
,重新启动Nodeos和/或Keosd
列出所有节点
$ cleos net peers -H yournode.host -P yourport
[{
"peer": "123.456.78.9:9876",
"connecting": false,
"syncing": false,
"last_handshake": {
"network_version": 0,
"chain_id": "0000000000000000000000000000000000000000000000000000000000000000",
"node_id": "0000000000000000000000000000000000000000000000000000000000000000",
"key": "EOS1111111111111111111111111111111114T1Anm",
"time": 0,
"token": "0000000000000000000000000000000000000000000000000000000000000000",
"sig": "EOS111111111111111111111111111111111111111111111111111111111111111115NsAua",
"p2p_address": "",
"last_irreversible_block_num": 0,
"last_irreversible_block_id": "0000000000000000000000000000000000000000000000000000000000000000",
"head_num": 0,
"head_id": "0000000000000000000000000000000000000000000000000000000000000000",
"os": "",
"agent": "",
"generation": 0
}
}
...]
使用cleos的助手将eosio.code
转换为active权限
当开发合约的时候,你可能需要你的合约有广播inline actions
的能力,这时需要用到你合约的 active authority
。然后为了安全考虑,除非合约账户已经被配置这些权限,否则合约无法用active authority
.eosio.code
是一个虚假的权限,授予合约active authority
;
在此之前,需要一个复杂的、具有潜在风险的cleos命令来添加yourcontract@eosio,现在大大简化了。
# Adding eosio.code to a contract's active authority
$ cleos set account permission YOURCONTRACT active --add-code
# Removing eosio.code from a contract's active authority
$ cleos set account permission YOURCONTRACT active --remove-code
# --add-code 和 --remove-code 在幕后做了什么?
# 在使用—-add-code和--remove-code时,cleos获取帐户的当前权限,并追加从活动权限中删除YOURCONTRACT@eosio.code。
# 建议使用--add-code 工具,而不是下面的命令,因为很容易出错,可能导致帐户被锁定。
$ cleos set account permission YOUR_CONTRACT active '{"threshold": 1,"keys": [{"key": "CURRENT_PUBLIC_KEY(S)_IN_ACTIVE_PERM","weight": 1}], "accounts": [{"permission":{"actor":"YOUR_CONTRACT","permission":"eosio.code"},"weight":1}]}' -p YOUR_CONTRACT@owner