RPC接口

描述怎样去调用eosd的HTTP RPC.

内容列表

配置

eosd使用REST RPC接口,插件可以在API服务器上注册自己的端点。 本页将解释如何使用一些API来获取有关区块链和发送事务的信息。

在查询eosd之前,您必须先启用必要的API插件。根据您希望启用的API,将以下行添加到您的eosd的config.ini中:

  1. plugin = eosio::chain_api_plugin // 生效链API
  2. plugin = eosio::wallet_api_plugin // 生效钱包API

另外,对于电子钱包API,您还可以通过单独运行eos-walletd将电子钱包功能与eosd分开。

对于以下指南,我们假定我们已经在127.0.0.1:8888(启用了链接API插件,电子钱包API插件已禁用)以及在127.0.0.1:8889上运行的eos-walletd运行。

链接口

get_info

获取与节点相关的最新信息

get_info 用法示例

  1. curl http://127.0.0.1:8888/v1/chain/get_info

get_info结果示例

  1. {
  2. "server_version": "b2eb1667",
  3. "head_block_num": 259590,
  4. "last_irreversible_block_num": 259573,
  5. "head_block_id": "0003f60677f3707f0704f16177bf5f007ebd45eb6efbb749fb1c468747f72046",
  6. "head_block_time": "2017-12-10T17:05:36",
  7. "head_block_producer": "initp",
  8. "recent_slots": "1111111111111111111111111111111111111111111111111111111111111111",
  9. "participation_rate": "1.00000000000000000"
  10. }

get_block

获取一个块的信息

get_block 用法示例

  1. $ curl http://127.0.0.1:8888/v1/chain/get_block -X POST -d '{"block_num_or_id":5}'
  2. $ curl http://127.0.0.1:8888/v1/chain/get_block -X POST -d '{"block_num_or_id":0000000445a9f27898383fd7de32835d5d6a978cc14ce40d9f327b5329de796b}'

get_block 结果示例

  1. {
  2. "previous": "0000000445a9f27898383fd7de32835d5d6a978cc14ce40d9f327b5329de796b",
  3. "timestamp": "2017-07-18T20:16:36",
  4. "transaction_merkle_root": "0000000000000000000000000000000000000000000000000000000000000000",
  5. "producer": "initf",
  6. "producer_changes": [ ],
  7. "producer_signature": "204cb94b3186c3b4a7f88be4e9db9f8af2ffdb7ef0f27a065c8177a5fcfacf876f684e59c39fb009903c0c59220b147bb07f1144df1c65d26c57b534a76dd29073",
  8. "cycles": [ ],
  9. "id":"000000050c0175cbf218a70131ddc3c3fab8b6e954edef77e0bfe7c36b599b1d",
  10. "block_num":5,
  11. "ref_block_prefix":27728114
  12. }

get_account

获取账户的信息

get_account 用法示例

  1. $ curl http://127.0.0.1:8888/v1/chain/get_account -X POST -d '{"account_name":"inita"}'

get_account 结果示例

  1. {
  2. "name": "inita",
  3. "eos_balance": "999998.9574 EOS",
  4. "staked_balance": "0.0000 EOS",
  5. "unstaking_balance": "0.0000 EOS",
  6. "last_unstaking_time": "2106-02-07T06:28:15",
  7. "permissions": [
  8. {
  9. "name": "active",
  10. "parent": "owner",
  11. "required_auth": {
  12. "threshold": 1,
  13. "keys": [
  14. {
  15. "key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
  16. "weight": 1
  17. }
  18. ],
  19. "accounts": []
  20. }
  21. },
  22. {
  23. "name": "owner",
  24. "parent": "owner",
  25. "required_auth": {
  26. "threshold": 1,
  27. "keys": [
  28. {
  29. "key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
  30. "weight": 1
  31. }
  32. ],
  33. "accounts": []
  34. }
  35. }
  36. ]
  37. }

get_code

获取智能合约代码

get_code 用法示例

  1. $ curl http://127.0.0.1:8888/v1/chain/get_code -X POST -d '{"account_name":"currency"}'

get_code 结果示例

  1. {
  2. "name":"currency",
  3. "code_hash":"a1c8c84b4700c09c8edb83522237439e33cf011a4d7ace51075998bd002e04c9",
  4. "wast":"(module\n (type $0 (func (param i64 i64 i32) (result i32)))\n ...truncated",
  5. "abi": {
  6. "types": [{
  7. "new_type_name": "account_name",
  8. "type": "name"
  9. }
  10. ],
  11. "structs": [{
  12. "name": "transfer",
  13. "base": "",
  14. "fields": [
  15. {"name":"from", "type":"account_name"},
  16. {"name":"to", "type":"account_name"},
  17. {"name":"quantity", "type":"uint64"}
  18. ]
  19. },{
  20. "name": "account",
  21. "base": "",
  22. "fields": [
  23. {"name":"key", "type":"name"},
  24. {"name":"balance", "type":"uint64"}
  25. ]
  26. }
  27. ],
  28. "actions": [{
  29. "name": "transfer",
  30. "type": "transfer"
  31. }
  32. ],
  33. "tables": [{
  34. "name": "account",
  35. "type": "account",
  36. "index_type": "i64",
  37. "key_names" : ["key"],
  38. "key_types" : ["name"]
  39. }
  40. ]
  41. }
  42. }

get_table_rows

获取智能合约数据

get_table_rows 用法示例

  1. $ curl http://127.0.0.1:8888/v1/chain/get_table_rows -X POST -d '{"scope":"inita", "code":"currency", "table":"account", "json": true}'
  2. $ curl http://127.0.0.1:8888/v1/chain/get_table_rows -X POST -d '{"scope":"inita", "code":"currency", "table":"account", "json": true, "lower_bound":0, "upper_bound":-1, "limit":10}'

get_table_rows 结果示例

  1. {
  2. "rows": [
  3. {
  4. "account": "account",
  5. "balance": 1000
  6. }
  7. ],
  8. "more": false
  9. }

abi_json_to_bin

将json序列化为二进制十六进制。得到的二进制十六进制通常用于push_transaction中的数据字段。

abi_json_to_bin 用法示例

  1. $ curl http://127.0.0.1:8888/v1/chain/abi_json_to_bin -X POST -d '{"code":"currency", "action":"transfer", "args":{"from":"initb", "to":"initc", "quantity":1000}}'

abi_json_to_bin 结果示例

  1. {
  2. "binargs": "000000008093dd74000000000094dd74e803000000000000",
  3. "required_scope": [],
  4. "required_auth": []
  5. }

abi_bin_to_json

将二进制十六进制序列化为json。

abi_bin_to_json 用法示例

  1. $ curl http://127.0.0.1:8888/v1/chain/abi_bin_to_json -X POST -d '{"code":"currency", "action":"transfer", "binargs":"000000008093dd74000000000094dd74e803000000000000"}'

abi_bin_to_json 结果示例

  1. {
  2. "args": {
  3. "from": "initb",
  4. "to": "initc",
  5. "quantity": 1000
  6. },
  7. "required_scope": [],
  8. "required_auth": []
  9. }

push_transaction

此方法预期采用JSON格式的事务,并将尝试将其应用于区块链。

成功的返回

成功时它将返回HTTP 200和事务ID。

  1. {
  2. "transaction_id": "..."
  3. }

仅仅因为交易是在本地进行的,并不意味着交易已经被合并到一个区块中。

错误的返回

如果发生错误,它将返回HTTP 400(无效参数)或500(内部服务器错误)

  1. HTTP/1.1 500 Internal Server Error
  2. Content-Length: 1466
  3. ...error message...

push_transactions

该方法一次推送多个事务。

push_transactions 用法示例

  1. curl http://localhost:8888/v1/chain/push_transaction -X POST -d '[{"ref_block_num":"101","ref_block_prefix":"4159312339","expiration":"2017-09-25T06:28:49","scope":["initb","initc"],"actions":[{"code":"currency","type":"transfer","recipients":["initb","initc"],"authorization":[{"account":"initb","permission":"active"}],"data":"000000000041934b000000008041934be803000000000000"}],"signatures":[],"authorizations":[]}, {"ref_block_num":"101","ref_block_prefix":"4159312339","expiration":"2017-09-25T06:28:49","scope":["inita","initc"],"actions":[{"code":"currency","type":"transfer","recipients":["inita","initc"],"authorization":[{"account":"inita","permission":"active"}],"data":"000000008040934b000000008041934be803000000000000"}],"signatures":[],"authorizations":[]}]'

get_required_keys

获取必需的密钥,从密钥列表中签署交易。

get_required_keys 用法示例

  1. curl http://localhost:8888/v1/chain/get_required_keys -X POST -d '{"transaction": {"ref_block_num":"100","ref_block_prefix":"137469861","expiration":"2017-09-25T06:28:49","scope":["initb","initc"],"actions":[{"code":"currency","type":"transfer","recipients":["initb","initc"],"authorization":[{"account":"initb","permission":"active"}],"data":"000000000041934b000000008041934be803000000000000"}],"signatures":[],"authorizations":[]}, "available_keys":["EOS4toFS3YXEQCkuuw1aqDLrtHim86Gz9u3hBdcBw5KNPZcursVHq","EOS7d9A3uLe6As66jzN8j44TXJUqJSK3bFjjEEqR4oTvNAB3iM9SA","EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"]}'
  1. ### get_required_keys 结果示例
  2. ```json
  3. {
  4. "required_keys": [
  5. "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
  6. ]
  7. }

get_required_keys

获取必需的密钥,从密钥列表中签署交易。

get_required_keys 用法示例

  1. curl http://localhost:8888/v1/chain/get_required_keys -X POST -d '{"transaction": {"ref_block_num":"100","ref_block_prefix":"137469861","expiration":"2017-09-25T06:28:49","scope":["initb","initc"],"actions":[{"code":"currency","type":"transfer","recipients":["initb","initc"],"authorization":[{"account":"initb","permission":"active"}],"data":"000000000041934b000000008041934be803000000000000"}],"signatures":[],"authorizations":[]}, "available_keys":["EOS4toFS3YXEQCkuuw1aqDLrtHim86Gz9u3hBdcBw5KNPZcursVHq","EOS7d9A3uLe6As66jzN8j44TXJUqJSK3bFjjEEqR4oTvNAB3iM9SA","EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"]}'
  1. ### get_required_keys 结果示例
  2. ```json
  3. {
  4. "required_keys": [
  5. "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
  6. ]
  7. }

钱包接口

wallet_create

用给定的名称创建一个新的钱包.

wallet_create 用法示例

  1. $ curl http://localhost:8889/v1/wallet/create -X POST -d '"default"'

wallet_create 结果示例

该命令将返回将来可用于解锁钱包的密码.

  1. PW5KFWYKqvt63d4iNvedfDEPVZL227D3RQ1zpVFzuUwhMAJmRAYyX

wallet_open

打开给定名称的现有钱包.

wallet_open 用法示例

  1. $ curl http://localhost:8889/v1/wallet/open -X POST -d '"default"'

wallet_open 结果示例

  1. {}

wallet_lock_all

锁定所有钱包.

wallet_lock_all 用法示例

  1. $ curl http://localhost:8889/v1/wallet/lock_all

wallet_lock_all 结果示例

  1. {}

wallet_unlock

用给定的名称和密码解锁钱包.

wallet_unlock 用法示例

  1. $ curl http://localhost:8889/v1/wallet/unlock -X POST -d '["default", "PW5KFWYKqvt63d4iNvedfDEPVZL227D3RQ1zpVFzuUwhMAJmRAYyX"]'

wallet_unlock 结果示例

  1. {}

wallet_list

列出所有钱包.

wallet_list 用法示例

  1. $ curl http://localhost:8889/v1/wallet/list_wallets

wallet_list 结果示例

  1. ["default *"]

wallet_list_keys

列出所有钱包中的所有密钥对.

wallet_list_keys 用法示例

  1. $ curl http://localhost:8889/v1/wallet/list_keys

wallet_list_keys 结果示例

  1. [["EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]]

wallet_get_public_keys

列出所有钱包中的所有公钥.

wallet_get_public_keys 用法示例

  1. $ curl http://localhost:8889/v1/wallet/get_public_keys

wallet_get_public_keys 结果示例

  1. ["EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"]

wallet_set_timeout

设置钱包自动锁定超时(以秒为单位).

wallet_set_timeout 用法示例

  1. $ curl http://localhost:8889/v1/wallet/set_timeout -X POST -d '10'

wallet_set_timeout 结果示例

  1. {}

wallet_sign_trx

给定一个事务数组的签名事务,需要公钥和链ID.

wallet_sign_trx 用法示例

  1. $ curl http://localhost:8889/v1/wallet/sign_transaction -X POST -d '[{"ref_block_num":21453,"ref_block_prefix":3165644999,"expiration":"2017-12-08T10:28:49","scope":["initb","initc"],"read_scope":[],"messages":[{"code":"currency","type":"transfer","authorization":[{"account":"initb","permission":"active"}],"data":"000000008093dd74000000000094dd74e803000000000000"}],"signatures":[]}, ["EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"], ""]'
  1. ### wallet_sign_trx 结果示例
  2. ```json
  3. {
  4. "ref_block_num": 21453,
  5. "ref_block_prefix": 3165644999,
  6. "expiration": "2017-12-08T10:28:49",
  7. "scope": [
  8. "initb",
  9. "initc"
  10. ],
  11. "read_scope": [],
  12. "messages": [
  13. {
  14. "code": "currency",
  15. "type": "transfer",
  16. "authorization": [
  17. {
  18. "account": "initb",
  19. "permission": "active"
  20. }
  21. ],
  22. "data": "000000008093dd74000000000094dd74e803000000000000"
  23. }
  24. ],
  25. "signatures": [
  26. "1f393cc5ce6a6951fb53b11812345bcf14ffd978b07be386fd639eaf440bca7dca16b14833ec661ca0703d15e55a2a599a36d55ce78c4539433f6ce8bcee0158c3"
  27. ]
  28. }