【EOS】Cleos基础

介绍

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值