跳到主要内容

Node API

节点在单个监听器上提供JSON-RPC 2.0服务,默认绑定到127.0.0.1端口3413,分为两个接口层。

接口路径服务
Owner/v2/owner节点管理,八个方法
Foreign/v2/foreign链读取、交易提交、区块模板,十七个方法

凭据及哪些端点需要凭据,统一在身份验证与TLS中说明。

同一监听器还在/v1下提供REST接口。参见v1 REST接口

JSON-RPC方法分布

/v2/owner仅用于节点管理:

get_status, validate_chain, compact_chain, get_peers, get_connected_peers, ban_peer, unban_peer, get_onion_addresses.

/v2/foreign用于其他所有操作,包括所有链读取和交易提交:

get_header, get_block, get_blocks, get_tip, get_version, get_kernel, get_last_n_kernels, get_outputs, get_unspent_outputs, get_pmmr_indices, get_pool_size, get_stempool_size, get_unconfirmed_transactions, push_transaction, get_block_template, finalize_block_template, submit_block.

因此,读取区块是Foreign API调用,在默认安装下无需凭据:

curl -s -d '{"jsonrpc":"2.0","method":"get_tip","params":[],"id":1}' \
http://127.0.0.1:3413/v2/foreign

检查同步状态是Owner接口的调用,需要节点凭据

响应结构

total_difficulty是以工作量证明(proof-of-work)算法为键的对象,而非整数:

{
"total_difficulty": {
"cuckaroo": 0,
"cuckatoo": 1234,
"randomx": 5678,
"progpow": 9012
}
}

区块头用两个字段描述其证明:proof为命名算法的字符串,solution为外部标记联合类型,其结构随算法而变。

Status以整数EPIC而非freemen表示supplymax_supply,以区块数表示blocks_to_next_halving。奖励步进并非全部为减半;参见发行

内核(kernel)在不同方法中以两种形式出现。get_block返回扁平化形式,而get_kernelget_last_n_kernels返回带有外部标记features字段的原始类型。两种形式均需处理。

HTTP挖矿

Foreign接口提供三步区块提交流程,作为Stratum的替代方案:get_block_templatefinalize_block_templatesubmit_block。该接口为HTTP上的JSON-RPC。参见Stratum

v1 REST接口

节点在同一进程、同一端口上,于/v1下提供REST服务,于/v2下提供JSON-RPC服务。编号代表两种接口风格,而非两代接口:/v1注册于api/src/handlers.rs:536/v2注册于api/src/handlers.rs:135api/src/handlers.rs:155

区别在于操作名称的位置。

/v1/v2
风格RESTJSON-RPC 2.0
操作由以下内容命名URL路径请求体中的method字段
HTTP动词GETPOST用于变更POST
URL每个操作一个/v2/foreign, /v2/owner, /v2/tor
结果载荷本身result.Ok内的载荷
凭据通过/v1前缀进行Basic auth每个接口各自独立

两个接口返回相同的载荷。/v2/owner上的GET /v1/statusget_status产生相同的响应体,因此JSON-RPC页面记录了两者的响应结构。

GET /GET /v1/GET /v2/api/src/handlers.rs:446返回v1路由列表。

路由

HTTP动词以节点路由索引所报告的为准。右列为返回相同内容的JSON-RPC方法及其所属接口层。

每条v1路由及其对应的JSON-RPC方法

路由器注册了19个模式,其中三个为通配符。

路由动词JSON-RPC等效方法
/v1/GET无,此为路由索引
/v1/statusGETget_status,owner
/v1/chainGETget_tip,foreign
/v1/chain/validateGETvalidate_chain,owner
/v1/chain/compactPOSTcompact_chain,owner
/v1/blocks/<hash|height>GETget_block,foreign
/v1/headers/<hash|height|commit>GETget_header,foreign
/v1/chain/kernels/<excess>?min_height=&max_height=GETget_kernel,foreign
/v1/chain/outputs/byids?id=GETget_outputs,foreign
/v1/chain/outputs/byheight?start_height=&end_height=GETget_outputs,foreign
/v1/txhashset/rootsGET
/v1/txhashset/lastoutputs?n=GET
/v1/txhashset/lastrangeproofsGET
/v1/txhashset/lastkernelsGETget_last_n_kernels,foreign
/v1/txhashset/outputs?start_index=&max=GETget_unspent_outputs,foreign
/v1/txhashset/merkleproof?n=GETinclude_merkle_proofget_outputs 上,foreign
/v1/poolGETget_pool_sizeget_stempool_size,foreign
/v1/pool/push_txPOSTpush_transaction,foreign
/v1/peers/allGETget_peers,owner
/v1/peers/connectedGETget_connected_peers,owner
/v1/peers/<addr>GETget_peers 附带 peer_addr,owner
/v1/peers/<addr>/banPOSTban_peer,owner
/v1/peers/<addr>/unbanPOSTunban_peer,owner
/v1/peers/onion_addressesGETget_onion_addresses,owner
/v1/versionGETget_version,foreign
/v1/mining/block_templateGETget_block_template,foreign
/v1/kerneldownloadGET

/v1调用,在整个前缀范围内使用节点凭据:

curl -s -u epic:$(cat ~/.epic/main/.api_secret) http://127.0.0.1:3413/v1/status
{
"protocol_version": 2,
"user_agent": "MW/Epic 4.0.3",
"connections": 0,
"tip": {
"height": 1439,
"last_block_pushed": "9abbd80483f9b082a9362ebac0aba5619bdba7cf647cb15f5ed33102faf3cd1b",
"prev_block_to_last": "6ceed7ff0ff7da1d44b01dc03189edeb1323bfa6d3625768520dd1a0498a0735",
"total_difficulty": {"cuckaroo": 1440, "cuckatoo": 1440, "randomx": 1440, "progpow": 1440}
},
"sync_status": "no_sync",
"supply": 23024,
"max_supply": 21000000,
"blocks_to_next_halving": 479521
}

于2026-08-24在高度1439的本地usernet链上捕获。

完整方法参考

来源

下一步