EOS小白学习(五)EOS的HTTP API

欢迎来到EOS小白学习系列,本系列会记录EOS学习过程中的一些操作和细节,大饼果子非C++出身,如有错误,欢迎指出

接上一篇:

EOS小白学习(四)使用http请求EOS节点

本篇将会列出EOS支持的HTTP API(chain和history),没有过多的讲解,只是小小的给了几个应用场景和调用的数据,以方便大家使用

1. chain/get_info(请求链的信息)

应用场景:

去查当前区块的业务,尤其是执行合约的时候,会附带一个reference的block,用于检查合约执行的action是否因为过期不允许上链

POST:

http://127.0.0.1:8888/v1/chain/get_info

BODY: 什么都不需要填

{}

RESPONSE:

1{ 2 "server_version": "75635168", 3 "chain_id": "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f", 4 "head_block_num": 43060, 5 "last_irreversible_block_num": 43059, 6 "last_irreversible_block_id": "0000a833ade6bcfaa05490c14b9e2dec3b59271001314048405a0b2b8fb35f7e", 7 "head_block_id": "0000a834303d5901171d86c699f0a00a309dcf86ad28252f1b05191b3f3f509e", 8 "head_block_time": "2018-07-24T06:56:29.500", 9 "head_block_producer": "eosio", 10 "virtual_block_cpu_limit": 200000000, 11 "virtual_block_net_limit": 1048576000, 12 "block_cpu_limit": 199900, 13 "block_net_limit": 1048576 14}

2. chain/get_block(请求block的信息)

应用场景:

除了上述执行合约的需要之外,还有比较基本的就是去查询block的信息

POST:

http://127.0.0.1:8888/v1/chain/get_block

BODY: 需要填写block的number

{
  "block_num_or_id": 19238
}

RESPONSE:

1{ 2 "timestamp": "2018-07-22T02:55:41.000", 3 "producer": "eosio", 4 "confirmed": 0, 5 "previous": "00004b25b6213b5de760937e2315611de3a65cdacfea4bdf757ba46730d79d06", 6 "transaction_mroot": "0000000000000000000000000000000000000000000000000000000000000000", 7 "action_mroot": "1738e6b70e77ce96a56982dc3eda3cc2191801e1e15854935508c91891c10385", 8 "schedule_version": 0, 9 "new_producers": null, 10 "header_extensions": [], 11 "producer_signature": "SIG_K1_Jwy7AtXzLMX6wy4DfYQhQ2vKSaA77k4RH7fCBh9cq6FMA8hzdwY5nHSSJzUbgTL8tnzRoerAzgrY3aqNPuvCMgWcreN7rz", 12 "transactions": [], 13 "block_extensions": [], 14 "id": "00004b269841c0b8899b8c5218eaf1d5beb1881ece8f1303954cc65d944a8365", 15 "block_num": 19238, 16 "ref_block_prefix": 1384946569 17}

3. chain/get_account(请求account的信息)

应用场景:

查看account是否存在,并且查看account的资源使用情况

POST:

http://127.0.0.1:8888/v1/chain/get_account

BODY: 需要填写account的名字

{
  "account_name":"dabingguozi"
}

RESPONSE:

1{ 2 "account_name": "dabingguozi", 3 "head_block_num": 44279, 4 "head_block_time": "2018-07-24T07:06:39.000", 5 "privileged": false, 6 "last_code_update": "1970-01-01T00:00:00.000", 7 "created": "2018-07-21T08:04:17.000", 8 "core_liquid_balance": "554.0000 SYS", 9 "ram_quota": 8150, 10 "net_weight": 10000000, 11 "cpu_weight": 10000000, 12 "net_limit": { 13 "used": 0, 14 "available": "347781061036", 15 "max": "347781061036" 16 }, 17 "cpu_limit": { 18 "used": 0, 19 "available": "66333973128", 20 "max": "66333973128" 21 }, 22 "ram_usage": 2996, 23 "permissions": [ 24 { 25 "perm_name": "active", 26 "parent": "owner", 27 "required_auth": { 28 "threshold": 1, 29 "keys": [ 30 { 31 "key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", 32 "weight": 1 33 } 34 ], 35 "accounts": [], 36 "waits": [] 37 } 38 }, 39 { 40 "perm_name": "owner", 41 "parent": "", 42 "required_auth": { 43 "threshold": 1, 44 "keys": [ 45 { 46 "key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", 47 "weight": 1 48 } 49 ], 50 "accounts": [], 51 "waits": [] 52 } 53 } 54 ], 55 "total_resources": { 56 "owner": "dabingguozi", 57 "net_weight": "1000.0000 SYS", 58 "cpu_weight": "1000.0000 SYS", 59 "ram_bytes": 8150 60 }, 61 "self_delegated_bandwidth": null, 62 "refund_request": null, 63 "voter_info": null 64}

**
4. chain/get_abi(请求合约的信息)**

应用场景:

去查看合约暴露的方法,去看合约的表名,方便合约执行,方便数据库读取

POST:

http://127.0.0.1:8888/v1/chain/get_abi

BODY: 需要填写合约用户名字

{
  "account_name":"eosio.token"
}

RESPONSE:

1{ 2 "account_name": "eosio.token", 3 "abi": { 4 "version": "eosio::abi/1.0", 5 "types": [ 6 { 7 "new_type_name": "account_name", 8 "type": "name" 9 } 10 ], 11 "structs": [ 12 { 13 "name": "transfer", 14 "base": "", 15 "fields": [ 16 { 17 "name": "from", 18 "type": "account_name" 19 }, 20 { 21 "name": "to", 22 "type": "account_name" 23 }, 24 { 25 "name": "quantity", 26 "type": "asset" 27 }, 28 { 29 "name": "memo", 30 "type": "string" 31 } 32 ] 33 }, 34 { 35 "name": "create", 36 "base": "", 37 "fields": [ 38 { 39 "name": "issuer", 40 "type": "account_name" 41 }, 42 { 43 "name": "maximum_supply", 44 "type": "asset" 45 } 46 ] 47 }, 48 { 49 "name": "issue", 50 "base": "", 51 "fields": [ 52 { 53 "name": "to", 54 "type": "account_name" 55 }, 56 { 57 "name": "quantity", 58 "type": "asset" 59 }, 60 { 61 "name": "memo", 62 "type": "string" 63 } 64 ] 65 }, 66 { 67 "name": "account", 68 "base": "", 69 "fields": [ 70 { 71 "name": "balance", 72 "type": "asset" 73 } 74 ] 75 }, 76 { 77 "name": "currency_stats", 78 "base": "", 79 "fields": [ 80 { 81 "name": "supply", 82 "type": "asset" 83 }, 84 { 85 "name": "max_supply", 86 "type": "asset" 87 }, 88 { 89 "name": "issuer", 90 "type": "account_name" 91 } 92 ] 93 } 94 ], 95 "actions": [ 96 { 97 "name": "transfer", 98 "type": "transfer", 99 "ricardian_contract": "" 100 }, 101 { 102 "name": "issue", 103 "type": "issue", 104 "ricardian_contract": "" 105 }, 106 { 107 "name": "create", 108 "type": "create", 109 "ricardian_contract": "" 110 } 111 ], 112 "tables": [ 113 { 114 "name": "accounts", 115 "index_type": "i64", 116 "key_names": [ 117 "currency" 118 ], 119 "key_types": [ 120 "uint64" 121 ], 122 "type": "account" 123 }, 124 { 125 "name": "stat", 126 "index_type": "i64", 127 "key_names": [ 128 "currency" 129 ], 130 "key_types": [ 131 "uint64" 132 ], 133 "type": "currency_stats" 134 } 135 ], 136 "ricardian_clauses": [], 137 "error_messages": [], 138 "abi_extensions": [] 139 } 140}

5. chain/get_table_rows(请求表的信息)

应用场景:

取出数据库数据,比如币种余额,合约代码要求存的中间状态等等

POST:

http://127.0.0.1:8888/v1/chain/get_table_rows

BODY: 其中code是合约账户,scope是合约中设定的(相当于mysql的database),table也是合约中设定的(相当于mysql的table)

{
  "code":"eosio.token",
  "scope": "dabingguozi",
  "table": "accounts",
  "json": true
}

RESPONSE:

1{ 2 "rows": [ 3 { 4 "balance": "554.0000 SYS" 5 } 6 ], 7 "more": false 8}

6. chain/get_currency_balance(请求余额的信息)

应用场景:

取出余额

POST:

http://127.0.0.1:8888/v1/chain/get_currency_balance

BODY: 其中code是合约账户,account是用户account

{
  "code":"eosio.token",
  "account": "dabingguozi"
}

RESPONSE:

1[ 2 "554.0000 SYS" 3]

7. history/get_transactions(请求transaction的信息)

应用场景:

合约执行流水,比如说转账流水,账户创建流水等

POST:

http://127.0.0.1:8888/v1/history/get_transaction

BODY: 需要填写transaction的id

{
  "id":"b09395d938e594b838277453cea832ddc5d57ab5e92d8763ea011df9e35d7b34"
}

RESPONSE:

1{ 2 "id": "b09395d938e594b838277453cea832ddc5d57ab5e92d8763ea011df9e35d7b34", 3 "trx": { 4 "receipt": { 5 "status": "executed", 6 "cpu_usage_us": 2751, 7 "net_usage_words": 16, 8 "trx": [ 9 1, 10 { 11 "signatures": [ 12 "SIG_K1_KfYZbh4ed1qamontvHfnV5AVUFkMd5NzGxTAXqGmN96xmtUHw5YqJMkFwejRs8JbngUgdD44y8zrRszNwTKVjzZ9tJkEJW" 13 ], 14 "compression": "none", 15 "packed_context_free_data": "", 16 "packed_trx": "4bf2535b264b899b8c52000000000100a6823403ea3055000000572d3ccdcd010000000000ea305500000000a8ed3232210000000000ea305500dca79ab1e98e49a08601000000000004535953000000000000" 17 } 18 ] 19 }, 20 "trx": { 21 "expiration": "2018-07-22T02:56:11", 22 "ref_block_num": 19238, 23 "ref_block_prefix": 1384946569, 24 "max_net_usage_words": 0, 25 "max_cpu_usage_ms": 0, 26 "delay_sec": 0, 27 "context_free_actions": [], 28 "actions": [ 29 { 30 "account": "eosio.token", 31 "name": "transfer", 32 "authorization": [ 33 { 34 "actor": "eosio", 35 "permission": "active" 36 } 37 ], 38 "data": { 39 "from": "eosio", 40 "to": "dabingguozi", 41 "quantity": "10.0000 SYS", 42 "memo": "" 43 }, 44 "hex_data": "0000000000ea305500dca79ab1e98e49a086010000000000045359530000000000" 45 } 46 ], 47 "transaction_extensions": [], 48 "signatures": [ 49 "SIG_K1_KfYZbh4ed1qamontvHfnV5AVUFkMd5NzGxTAXqGmN96xmtUHw5YqJMkFwejRs8JbngUgdD44y8zrRszNwTKVjzZ9tJkEJW" 50 ], 51 "context_free_data": [] 52 } 53 }, 54 "block_time": "2018-07-22T02:55:42.000", 55 "block_num": 19240, 56 "last_irreversible_block": 63969, 57 "traces": [ 58 { 59 "receipt": { 60 "receiver": "dabingguozi", 61 "act_digest": "f8ce7062290be813e6484e50c7c0e3c22a9898e3240bab76f7e11b99c07abe52", 62 "global_sequence": 19298, 63 "recv_sequence": 5, 64 "auth_sequence": [ 65 [ 66 "eosio", 67 19293 68 ] 69 ], 70 "code_sequence": 1, 71 "abi_sequence": 1 72 }, 73 "act": { 74 "account": "eosio.token", 75 "name": "transfer", 76 "authorization": [ 77 { 78 "actor": "eosio", 79 "permission": "active" 80 } 81 ], 82 "data": { 83 "from": "eosio", 84 "to": "dabingguozi", 85 "quantity": "10.0000 SYS", 86 "memo": "" 87 }, 88 "hex_data": "0000000000ea305500dca79ab1e98e49a086010000000000045359530000000000" 89 }, 90 "elapsed": 6, 91 "cpu_usage": 0, 92 "console": "", 93 "total_cpu_usage": 0, 94 "trx_id": "b09395d938e594b838277453cea832ddc5d57ab5e92d8763ea011df9e35d7b34", 95 "inline_traces": [] 96 } 97 ] 98}

8. history/get_actions(请求actions的信息)

应用场景:

合约执行流水

POST:

http://127.0.0.1:8888/v1/history/get_actions

BODY: 其中account_name如果没有在config中filter设置过,response就什么都拿不到

{
  "pos":0,
  "offset":1000,
  "account_name": "dabingguozi"
}

RESPONSE:

1{ 2 "actions": [ 3 { 4 "global_action_seq": 19298, 5 "account_action_seq": 0, 6 "block_num": 19240, 7 "block_time": "2018-07-22T02:55:42.000", 8 "action_trace": { 9 "receipt": { 10 "receiver": "dabingguozi", 11 "act_digest": "f8ce7062290be813e6484e50c7c0e3c22a9898e3240bab76f7e11b99c07abe52", 12 "global_sequence": 19298, 13 "recv_sequence": 5, 14 "auth_sequence": [ 15 [ 16 "eosio", 17 19293 18 ] 19 ], 20 "code_sequence": 1, 21 "abi_sequence": 1 22 }, 23 "act": { 24 "account": "eosio.token", 25 "name": "transfer", 26 "authorization": [ 27 { 28 "actor": "eosio", 29 "permission": "active" 30 } 31 ], 32 "data": { 33 "from": "eosio", 34 "to": "dabingguozi", 35 "quantity": "10.0000 SYS", 36 "memo": "" 37 }, 38 "hex_data": "0000000000ea305500dca79ab1e98e49a086010000000000045359530000000000" 39 }, 40 "elapsed": 6, 41 "cpu_usage": 0, 42 "console": "", 43 "total_cpu_usage": 0, 44 "trx_id": "b09395d938e594b838277453cea832ddc5d57ab5e92d8763ea011df9e35d7b34", 45 "inline_traces": [] 46 } 47 }, 48 { 49 "global_action_seq": 21095, 50 "account_action_seq": 1, 51 "block_num": 21034, 52 "block_time": "2018-07-22T03:10:39.000", 53 "action_trace": { 54 "receipt": { 55 "receiver": "dabingguozi", 56 "act_digest": "72ae6a2af84b85d4b4e20190a56904f53afa2a79ab4c47ca2f15874c4c309205", 57 "global_sequence": 21095, 58 "recv_sequence": 6, 59 "auth_sequence": [ 60 [ 61 "eosio", 62 21090 63 ] 64 ], 65 "code_sequence": 1, 66 "abi_sequence": 1 67 }, 68 "act": { 69 "account": "eosio.token", 70 "name": "transfer", 71 "authorization": [ 72 { 73 "actor": "eosio", 74 "permission": "active" 75 } 76 ], 77 "data": { 78 "from": "eosio", 79 "to": "dabingguozi", 80 "quantity": "2.0000 SYS", 81 "memo": "" 82 }, 83 "hex_data": "0000000000ea305500dca79ab1e98e49204e000000000000045359530000000000" 84 }, 85 "elapsed": 6, 86 "cpu_usage": 0, 87 "console": "", 88 "total_cpu_usage": 0, 89 "trx_id": "e1cafa2561470a0b489a4e2032375a5c88665f75e5172bac7b574cd051079d42", 90 "inline_traces": [] 91 } 92 } 93 ], 94 "last_irreversible_block": 64270 95}

致此,一些目前常用的HTTP API,就列在这里了,之后会有进阶版举例其他API

下一篇是时候总结和讨论一下eos的结构了,接连接:

(在编辑。。。)

ps. 因为我没有在插件中设置wallet-api,所以wallet相关的HTTP API就不可用

点赞
收藏

评论区

加载中...

相关推荐

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

PPDB:今晚老齐直播

【今晚老齐直播】今晚(本周三晚)20:0021:00小白开始“用”飞桨(https://www.oschina.net/action/visit/ad?id1185)由PPDE(飞桨(https://www.oschina.net/action/visit/ad?id1185)开发者专家计划)成员老齐,为深度学习小白指点迷津。

JAVA并发编程1

新手小白学习JAVA并发编程,写个博客记录一下而已(可能会有错的内容,毕竟小白)。首先有一个打印数字的类,publicclassCounter{privateintcount;publicvoidadd(){try{for(inti0;i<10;i){

SpringCloud Hystrix源码解析(一)

SpringCloudHystrix源码解析看本篇之前请看五分钟学会SpringCloudHystrix:服务容错保护(小白必看,一看就会系列教程)(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fblog.csdn.net%2Fweixin_443022

EOS智能合约开发(二):EOS创建和管理钱包

上节介绍了EOS智能合约开发之EOS环境搭建及启动节点(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fwww.jianshu.com%2Fp%2Fae8e72a05a2f)那么,节点启动后我们要做的第一件事儿是什么呢?就是我们首先要有账号,但是有账号的前提是什么呢?倒不是先创建账号

Ubuntu虚拟机EOS安装教程

EOS安装一、源码下载注意事项:二、编译源码注意事项:三、安装1.install安装2.测试(可跳过)四、运行总结一、源码下载gitclonehttps://github.com