EOSIO 指南(鏈API)

鏈API

get_info

返回包含區塊鏈的各類詳細信息的對象。json

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

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/get_info' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

響應

{
    "server_version": "d9ad8eec",
    "head_block_num": 8592,
    "last_irreversible_block_num": 8591,
    "head_block_id": "00002190e805475db152be7d3f4f1a075efaed42827cd551b0e23c7feabbedac",
    "head_block_time": "2018-04-27T17:40:34",
    "head_block_producer": "eosio"
}

get_block

返回包含有關區塊鏈上特定塊的各類詳細信息的對象。數組

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

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/get_block' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
block_num_or_id string 提供塊編號或塊ID 5

響應

{
    "previous": "00000004471d48fe40706e73ce27f9cf7bac1704ae55279c7a58c0173718a711",
    "timestamp": "2018-04-18T16:24:23.500",
    "transaction_mroot": "e366c0cc3519bb0f2ddaec20928fa4d6aae546194bb1c4205c67be429147ed4a",
    "action_mroot": "77e5e91b594ab4ebc44ebc8c7ecdc9d26409c5a07452d3b20a4840562fdeb658",
    "block_mroot": "4ef85b0d212f3fffabdd65680d32dd7dded3461d9df226a6e3dc232e42978f8b",
    "producer": "eosio",
    "schedule_version": 0,
    "new_producers": null,
    "producer_signature": "EOSJzEdFDsueKCerL7a6AdxMxiT851cEiugFB7ux1PAGn5eMmco8j32NsaKupxibheQGVFEqyEdjMub67VZjKmsLzuNxxKtUA",
    "regions": [{
        "region": 0,
        "cycles_summary": [
            [{
                "read_locks": [],
                "write_locks": [],
                "transactions": [{
                    "status": "executed",
                    "kcpu_usage": 2,
                    "net_usage_words": 38,
                    "id": "9880c128683e24845ccd282ebe026bd522f7fa9c6278d885f6ed35164c680669"
                }]
            }]
        ]
    }],
    "input_transactions": [],
    "id": "000000056d75b0581b4fbb96affa36669a37173d21f46f8cb974f760e94bbe14",
    "block_num": 5,
    "ref_block_prefix": 2528857883
}

get_block_header_state

http://127.0.0.1:8888/v1/chain/get_block_header_state

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/get_block_header_state' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
block_num_or_id string 提供塊編號或塊ID 1

get_account

返回一個對象,其中包含有關區塊鏈上特定賬戶的各類詳細信息。區塊鏈

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

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/get_account' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
account_name string 提供賬戶名稱 eosio

響應

{
    "account_name": "eosio",
    "permissions": [{
        "perm_name": "active",
        "parent": "owner",
        "required_auth": {
            "threshold": 1,
            "keys": [{
                "key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
                "weight": 1
            }],
            "accounts": []
        }
    }, {
        "perm_name": "owner",
        "parent": "",
        "required_auth": {
            "threshold": 1,
            "keys": [{
                "key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
                "weight": 1
            }],
            "accounts": []
        }
    }]
}

get_abi

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

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/get_abi' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
account_name string 要檢索ABI的賬戶名稱 eosio.token

get_code

返回一個對象,其中包含有關區塊鏈上特定智能合約的各類詳細信息。ui

http://127.0.0.1:8888/v1/chain/get_code

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/get_code' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
account_name string 提供智能合約賬戶名稱 currency

響應

{
  "name":"currency",
  "code_hash":"a1c8c84b4700c09c8edb83522237439e33cf011a4d7ace51075998bd002e04c9",
  "wast":"(module\n  (type $0 (func (param i64 i64 i32) (result i32)))\n ...truncated",
  "abi": {
  "types": [{
      "new_type_name": "account_name",
      "type": "name"
    }
  ],
  "structs": [{
      "name": "transfer",
      "base": "",
      "fields": [
        {"name":"from", "type":"account_name"},
        {"name":"to", "type":"account_name"},
        {"name":"quantity", "type":"uint64"}
      ]
    },{
      "name": "account",
      "base": "",
      "fields": [
        {"name":"key", "type":"name"},
        {"name":"balance", "type":"uint64"}
      ]
    }
  ],
  "actions": [{
      "name": "transfer",
      "type": "transfer"
    }
  ],
  "tables": [{
      "name": "account",
      "type": "account",
      "index_type": "i64",
      "key_names" : ["key"],
      "key_types" : ["name"]
    }
  ]
}
code_as_wasm自1.2.2起已棄用。

get_raw_code_and_abi

http://127.0.0.1:8888/v1/chain/get_raw_code_and_abi

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/get_raw_code_and_abi' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
account_name string 賬戶名稱以獲取代碼和abi eosio

get_table_rows

返回包含指定表中行的對象。url

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

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/get_table_rows' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
scope string 數據範圍所在的賬戶名稱 inita
code string 控制提供的表的智能合約的名稱 currency
table stirng 要查詢的表的名稱 account
table_key string inita
json boolean 返回json對象或返回格式化的響應 true
lower_bound string 過濾結果以返回不小於集合中提供的值的第一個元素
upper_bound string 過濾結果以返回大於集合中提供的值的第一個元素
limit int32 限制響應中返回的結果 10
index_position string 使用的索引的位置,例如,1表示主索引,2表示次要索引,等等 1
key_type string index_position指定的鍵的類型(例如:uint64_tname
encode_type string dec

響應

{
  "rows": [
    {
      "account": "account",
      "balance": 1000
    }
  ],
  "more": false
}

get_table_by_scope

http://127.0.0.1:8888/v1/chain/get_table_by_scope

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/get_table_by_scope' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
code string 返回表數據的合同的name
table string 按表過濾結果 0
lower_bound string 過濾結果以返回不小於集合中提供的值的第一個元素
upper_bound string 過濾結果以返回大於集合中提供的值的第一個元素
limit int32 限制響應中返回的結果 10

get_currency_balance

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

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/get_currency_balance' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

查詢參數

參數名 參數類型 描述 必要 示例
code string
account string 獲取餘額的帳戶
symbol string 要查詢的符號

abi_json_to_bin

將json序列化爲二進制十六進制,生成的二進制十六進制一般用於push_transaction中的數據字段。3d

http://127.0.0.1:8888/v1/chain/abi_json_to_bin

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/abi_json_to_bin' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
code string 提供賬戶名稱 currency
action string 提供操做參數 transfer
args json 提供json參數 {"from":"eosio","to":"eosio","quantity":1000}

響應

{
  "binargs": "000000008093dd74000000000094dd74e803000000000000",
  "required_scope": [],
  "required_auth": []
}

abi_bin_to_json

將二進制十六進制序列化爲json。code

http://127.0.0.1:8888/v1/chain/abi_bin_to_json

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/abi_bin_to_json' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
code string 提供賬戶名稱 currency
action string 提供操做名稱 transfer
binargs string 提供二進制參數

響應

{
  "args": {
    "from": "initb",
    "to": "initc",
    "quantity": 1000
  },
  "required_scope": [],
  "required_auth": []
}

get_required_keys

返回簽名交易所需的密鑰。server

http://127.0.0.1:8888/v1/chain/get_required_keys

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/get_required_keys' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
transaction json 提供交易對象
available_keys 字符串數組 提供可用的密鑰

響應

{
  "required_keys": [
    "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
  ]
}

示例

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"]

get_currency_stats

http://127.0.0.1:8888/v1/chain/get_currency_stats

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/get_currency_stats' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
code string
symbol string 獲取統計數據的貨幣符號 SYS

get_producers

http://127.0.0.1:8888/v1/chain/get_producers

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/get_producers' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
limit string 要檢索的生產者總數
lower_bound string
json boolean 以JSON格式返回結果? true

push_block

http://127.0.0.1:8888/v1/chain/push_block

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/push_block' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
timestamp date-time
producer string
confirmed int32 0
previous string
transaction_mroot string
action_mroot int32 0
version string
new_producers 字符串數組
header_extensions 字符串數組
producer_signature string
transactions array
block_extensions 字符串數組

push_transaction

此方法須要JSON格式的交易,並嘗試將其應用於區塊鏈。

http://127.0.0.1:8888/v1/chain/push_transaction

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/push_transaction' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
signatures 字符串數組 受權交易所需的簽名數組
compression string 使用壓縮,一般是false false
packed_context_free_data string json到十六進制
packed_trx string json十六進制

響應

{
    'transaction_id' = "1..."
}

push_transactions

此方法須要JSON格式的交易,並嘗試將其應用於區塊鏈,此方法一次推送多個交易。

http://127.0.0.1:8888/v1/chain/push_transactions

Node

var request = require("request");

var options = { method: 'POST',
  url: 'http://127.0.0.1:8888/v1/chain/push_transactions' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

body參數

參數名 參數類型 描述 必要 示例
body json 提供交易的受權

響應

{
    'transaction_id' = "1..."
}
這裏的 ref_block_numref_block_prefixlast_irreversible_block/v1/chain/get_block的結果,能夠經過調用 /v1/chain/get_info找到 last_irreversible_block,你還須要使用 /v1/wallet/sign_transaction來獲取正確的簽名。
相關文章
相關標籤/搜索