2.4 cleos-commands-contracts

合约相关命令

1. 获取合约 code

获取指定合约账户的代码和 ABI。使用方式 cleos get code [OPTIONS] name。

$ cleos get code eosio.token
code hash: b15e7bfddbad150158d1d3c3156f6357b7e27af0b5a20107784ba8b3a77b34e0

其中:

  • eosio.token 是智能合约的名称
$ cleos get code eosio --abi eosio.token.abi

2. 获取合约 ABI

获取指定合约账户的 ABI。使用方式 cleos get abi [OPTIONS] name。

$ cleos get abi eosio.token
$ cleos get abi eosio.token --file eosio.token.abi
$ cleos get abi eosio.token -f eosio.token.abi

3. 获取合约中的表内容

获取数据库表的内容。使用方式 cleos get table [OPTIONS] account scope table。

$ cleos get table eosio.token eosio accounts
{
  "rows": [{
      "balance": "0.0050 EOS"
    }
  ],
  "more": false
}

其中:

  • eosio.token 表示合约名称
  • eosio 表示 scope 名称
  • accounts 表示表名称
$ cleos get table eosio.token eosio accounts
{
  "rows": [{
      "data": {
        "balance": "0.0050 EOS"
      },
      "payer": "eosio"
    }
  ],
  "more": false
}
$ cleos get table eosio eosio producers
$ cleos get table eosio eosio voters
$ cleos get table eosio eosio users
{
  "rows": [{
      "from": "alice",
      "to": "alice",
      "net_weight": "1.0000 EOS",
      "cpu_weight": "1.0000 EOS"
    }
  ],
  "more": false
}
$ cleos get table eosio alice delband

4. 获取合约中 scope 的内容

$ cleos get scope eosio.token
{
  "rows": [{
      "code": "eosio.token",
      "scope": "........ehbo5",
      "table": "stat",
      "payer": "eosio.token",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "alice",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "eosio",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "eosio.ram",
      "table": "accounts",
      "payer": "eosio.ram",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "eosio.ramfee",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "eosio.stake",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "inita",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "node1",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "node2",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "node3",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    }
  ],
  "more": ""
}
$ cleos get scope eosio.token --table accounts --reverse
{
  "rows": [{
      "code": "eosio.token",
      "scope": "node3",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "node2",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "node1",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "inita",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "eosio.stake",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "eosio.ramfee",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "eosio.ram",
      "table": "accounts",
      "payer": "eosio.ram",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "eosio",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    },{
      "code": "eosio.token",
      "scope": "alice",
      "table": "accounts",
      "payer": "eosio",
      "count": 1
    }
  ],
  "more": ""
}

其中:

  • eosio.token 表示智能合约 eosio.token
  • accounts 表示表名
  • reverse 表示逆序

5. 部署合约

创建或更新合约账户对应的合约。使用方式 cleos set contract [OPTIONS] account [contract-dir] [wasm-file] [abi-file]。

$ cleos set contract eosio.token ~/bitbucket/zblockchain/eoscodes/contracts/eosio.contracts/eosio.token --abi eosio.token.abi -p eosio.token@active

其中:

  • eosio.toke 是合约账户名称
$ cleos get scope eosio

其中:

  • eosio 表示智能合约 eosio.system (也有可能是 eosio.bios),具体的根据创建时名称 eosio 对应的具体合约

项目源代码

项目源代码会逐步上传到 Github,地址为 https://github.com/windstamp/blockchain。

Contributor

  1. Windstamp, https://github.com/windstamp

你可能感兴趣的:(2.4 cleos-commands-contracts)