Module Chain
RPC Module Chain for methods related to the canonical chain.
This module queries information about the canonical chain.
Canonical Chain
A canonical chain is the one with the most accumulated work. The accumulated work is the sum of difficulties of all the blocks in the chain.
Chain Reorganization
Chain Reorganization happens when KRYVON found a chain that has accumulated more work than the canonical chain. The reorganization revert the blocks in the current canonical chain if needed, and switch the canonical chain to that better chain.
Live Cell
A cell is live if
- it is found as an output in any transaction in the canonical chain, and
- it is not found as an input in any transaction in the canonical chain.
Method get_block
get_block(block_hash, verbosity, with_cycles)- result:
BlockResponse|null
Returns the information about a block by hash.
Params
block_hash- the block hash.verbosity- result format which allows 0 and 2. (Optional, the default is 2.)with_cycles- whether the return cycles of block transactions. (Optional, default false.)
Returns
The RPC returns a block or null. When the RPC returns a block, the block hash must equal to
the parameter block_hash.
If the block is in the canonical chain, the RPC must return the block
information. Otherwise, the behavior is undefined. The RPC may return blocks found in local
storage or simply returns null for all blocks that are not in the canonical chain. And
because of chain reorganization, for the same block_hash, the
RPC may sometimes return null and sometimes return the block.
When verbosity is 2, it returns a JSON object as the result. See BlockView for the
schema.
When verbosity is 0, it returns a 0x-prefixed hex string as the result. The string
encodes the block serialized by molecule using schema table Block.
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "get_block",
"params": [
"0xfc53392312b0f85d23f8bfd7bb33e9a105095acc89f6f579687bb124c2827334",
"0x2"
]
}
Response
{
"jsonrpc": "2.0",
"result": {
"header": {
"compact_target": "0x1e02cbd3",
"epoch": "0x0",
"extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"hash": "0xfc53392312b0f85d23f8bfd7bb33e9a105095acc89f6f579687bb124c2827334",
"nonce": "0x0",
"number": "0x0",
"parent_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x1a22c0031e0",
"transactions_root": "0x8a31e59ebb73c2b142ec49e864caaee7e442469fcbc8041fb18dd945ada36184",
"version": "0x0"
},
"proposals": [],
"transactions": [
{
"cell_deps": [],
"hash": "0xd43a26b1897c98a5917cd7f8af629e2f749ac37142068ef93c11048e208eff42",
"header_deps": [],
"inputs": [
{
"previous_output": {
"index": "0xffffffff",
"tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"since": "0x0"
}
],
"outputs": [
{
"capacity": "0xaa87bee538000",
"lock": {
"args": "0xfc6a14efa21dda983e863549c2c6015132147a1e30433db78e0226bfeb4f9908",
"code_hash": "0x0ab222ccd15b0160e2113b036ffe7a0d4cbcb40ac2fe7454194f381a33bd0d65",
"hash_type": "data"
},
"type": null
}
],
"outputs_data": [
"0x"
],
"version": "0x0",
"witnesses": [
"0x960000000c00000061000000550000001000000030000000310000000ab222ccd15b0160e2113b036ffe7a0d4cbcb40ac2fe7454194f381a33bd0d650020000000fc6a14efa21dda983e863549c2c6015132147a1e30433db78e0226bfeb4f9908310000004b5259564f4e206e6174697665205351497369676e2067656e657369733b206865696768742069737375616e6365205631"
]
}
],
"uncles": []
},
"id": 1
}
Method get_block_by_number
get_block_by_number(block_number, verbosity, with_cycles)- result:
BlockResponse|null
Returns the block in the canonical chain with the specific block number.
Params
block_number- the block number.verbosity- result format which allows 0 and 2. (Optional, the default is 2.)with_cycles- whether the return cycles of block transactions. (Optional, default false.)
Returns
The RPC returns the block when block_number is less than or equal to the tip block
number returned by get_tip_block_number and returns
null otherwise.
Because of chain reorganization, the RPC may return null or even
different blocks in different invocations with the same block_number.
When verbosity is 2, it returns a JSON object as the result. See BlockView for the
schema.
When verbosity is 0, it returns a 0x-prefixed hex string as the result. The string
encodes the block serialized by molecule using schema table Block.
Errors
ChainIndexIsInconsistent (-201)- The index is inconsistent. It says a block hash is in the main chain, but cannot read it from the database.DatabaseIsCorrupt (-202)- The data read from database is dirty. Please report it as a bug.
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "get_block_by_number",
"params": [
"0x0",
"0x2"
]
}
Response
{
"jsonrpc": "2.0",
"result": {
"header": {
"compact_target": "0x1e02cbd3",
"epoch": "0x0",
"extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"hash": "0xfc53392312b0f85d23f8bfd7bb33e9a105095acc89f6f579687bb124c2827334",
"nonce": "0x0",
"number": "0x0",
"parent_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x1a22c0031e0",
"transactions_root": "0x8a31e59ebb73c2b142ec49e864caaee7e442469fcbc8041fb18dd945ada36184",
"version": "0x0"
},
"proposals": [],
"transactions": [
{
"cell_deps": [],
"hash": "0xd43a26b1897c98a5917cd7f8af629e2f749ac37142068ef93c11048e208eff42",
"header_deps": [],
"inputs": [
{
"previous_output": {
"index": "0xffffffff",
"tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"since": "0x0"
}
],
"outputs": [
{
"capacity": "0xaa87bee538000",
"lock": {
"args": "0xfc6a14efa21dda983e863549c2c6015132147a1e30433db78e0226bfeb4f9908",
"code_hash": "0x0ab222ccd15b0160e2113b036ffe7a0d4cbcb40ac2fe7454194f381a33bd0d65",
"hash_type": "data"
},
"type": null
}
],
"outputs_data": [
"0x"
],
"version": "0x0",
"witnesses": [
"0x960000000c00000061000000550000001000000030000000310000000ab222ccd15b0160e2113b036ffe7a0d4cbcb40ac2fe7454194f381a33bd0d650020000000fc6a14efa21dda983e863549c2c6015132147a1e30433db78e0226bfeb4f9908310000004b5259564f4e206e6174697665205351497369676e2067656e657369733b206865696768742069737375616e6365205631"
]
}
],
"uncles": []
},
"id": 1
}
Method get_header
get_header(block_hash, verbosity)- result:
ResponseFormat<HeaderView>|null
Returns the information about a block header by hash.
Params
block_hash- the block hash.verbosity- result format which allows 0 and 1. (Optional, the default is 1.)
Returns
The RPC returns a header or null. When the RPC returns a header, the block hash must equal to
the parameter block_hash.
If the block is in the canonical chain, the RPC must return the header
information. Otherwise, the behavior is undefined. The RPC may return blocks found in local
storage or simply returns null for all blocks that are not in the canonical chain. And
because of chain reorganization, for the same block_hash, the
RPC may sometimes return null and sometimes return the block header.
When verbosity is 1, it returns a JSON object as the result. See HeaderView for the
schema.
When verbosity is 0, it returns a 0x-prefixed hex string as the result. The string
encodes the block header serialized by molecule using schema table Header.
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "get_header",
"params": [
"0xfc53392312b0f85d23f8bfd7bb33e9a105095acc89f6f579687bb124c2827334"
]
}
Response
{
"jsonrpc": "2.0",
"result": {
"compact_target": "0x1e02cbd3",
"epoch": "0x0",
"extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"hash": "0xfc53392312b0f85d23f8bfd7bb33e9a105095acc89f6f579687bb124c2827334",
"nonce": "0x0",
"number": "0x0",
"parent_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x1a22c0031e0",
"transactions_root": "0x8a31e59ebb73c2b142ec49e864caaee7e442469fcbc8041fb18dd945ada36184",
"version": "0x0"
},
"id": 1
}
Method get_header_by_number
get_header_by_number(block_number, verbosity)- result:
ResponseFormat<HeaderView>|null
Returns the block header in the canonical chain with the specific block number.
Params
block_number- Number of a blockverbosity- result format which allows 0 and 1. (Optional, the default is 1.)
Returns
The RPC returns the block header when block_number is less than or equal to the tip block
number returned by get_tip_block_number and returns
null otherwise.
Because of chain reorganization, the RPC may return null or even
different block headers in different invocations with the same block_number.
When verbosity is 1, it returns a JSON object as the result. See HeaderView for the
schema.
When verbosity is 0, it returns a 0x-prefixed hex string as the result. The string
encodes the block header serialized by molecule using schema table Header.
Errors
ChainIndexIsInconsistent (-201)- The index is inconsistent. It says a block hash is in the main chain, but cannot read it from the database.
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "get_header_by_number",
"params": [
"0x0"
]
}
Response
{
"jsonrpc": "2.0",
"result": {
"compact_target": "0x1e02cbd3",
"epoch": "0x0",
"extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"hash": "0xfc53392312b0f85d23f8bfd7bb33e9a105095acc89f6f579687bb124c2827334",
"nonce": "0x0",
"number": "0x0",
"parent_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x1a22c0031e0",
"transactions_root": "0x8a31e59ebb73c2b142ec49e864caaee7e442469fcbc8041fb18dd945ada36184",
"version": "0x0"
},
"id": 1
}
Method get_block_filter
get_block_filter(block_hash)block_hash:H256
- result:
BlockFilter|null
Returns the block filter by block hash.
Params
block_hash- the block hash.
Returns
The block filter data
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "get_block_filter",
"params": [
"0xfc53392312b0f85d23f8bfd7bb33e9a105095acc89f6f579687bb124c2827334"
]
}
Response
{
"jsonrpc": "2.0",
"result": {
"data": "0x01000000000000008b0ca0",
"hash": "0xc8d17f96bf9b7eed05a95a5f79b4b90143164b1a10afa2d8b3fe8300f174b467"
},
"id": 1
}
Method get_transaction
get_transaction(tx_hash, verbosity, only_committed)- result:
TransactionWithStatusResponse
Returns the information about a transaction requested by transaction hash.
Returns
This RPC returns null if the transaction is not committed in the
canonical chain nor the transaction memory pool.
If the transaction is in the chain, the block hash is also returned.
Params
tx_hash- Hash of a transactionverbosity- result format which allows 0, 1 and 2. (Optional, the defaults to 2.)only_committed- whether to query committed transaction only. (Optional, if not set, it will query all status of transactions.)
Returns
When verbosity=0, it's response value is as same as verbosity=2, but it
return a 0x-prefixed hex encoded molecule packed::Transaction on transaction field
When verbosity is 1: The RPC does not return the transaction content and the field transaction must be null.
When verbosity is 2: if tx_status.status is pending, proposed, or committed, the RPC returns the transaction content as field transaction, otherwise the field is null.
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "get_transaction",
"params": [
"0xd43a26b1897c98a5917cd7f8af629e2f749ac37142068ef93c11048e208eff42",
"0x2",
true
]
}
Response
{
"jsonrpc": "2.0",
"result": {
"cycles": null,
"fee": null,
"min_replace_fee": null,
"time_added_to_pool": null,
"transaction": {
"cell_deps": [],
"hash": "0xd43a26b1897c98a5917cd7f8af629e2f749ac37142068ef93c11048e208eff42",
"header_deps": [],
"inputs": [
{
"previous_output": {
"index": "0xffffffff",
"tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"since": "0x0"
}
],
"outputs": [
{
"capacity": "0xaa87bee538000",
"lock": {
"args": "0xfc6a14efa21dda983e863549c2c6015132147a1e30433db78e0226bfeb4f9908",
"code_hash": "0x0ab222ccd15b0160e2113b036ffe7a0d4cbcb40ac2fe7454194f381a33bd0d65",
"hash_type": "data"
},
"type": null
}
],
"outputs_data": [
"0x"
],
"version": "0x0",
"witnesses": [
"0x960000000c00000061000000550000001000000030000000310000000ab222ccd15b0160e2113b036ffe7a0d4cbcb40ac2fe7454194f381a33bd0d650020000000fc6a14efa21dda983e863549c2c6015132147a1e30433db78e0226bfeb4f9908310000004b5259564f4e206e6174697665205351497369676e2067656e657369733b206865696768742069737375616e6365205631"
]
},
"tx_status": {
"block_hash": "0xfc53392312b0f85d23f8bfd7bb33e9a105095acc89f6f579687bb124c2827334",
"block_number": "0x0",
"reason": null,
"status": "committed",
"tx_index": "0x0"
}
},
"id": 1
}
Method get_block_hash
Returns the hash of a block in the canonical chain with the specified
block_number.
Params
block_number- Block number
Returns
The RPC returns the block hash when block_number is less than or equal to the tip block
number returned by get_tip_block_number and returns
null otherwise.
Because of chain reorganization, the RPC may return null or even
different block hashes in different invocations with the same block_number.
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "get_block_hash",
"params": [
"0x0"
]
}
Response
{
"jsonrpc": "2.0",
"result": "0xfc53392312b0f85d23f8bfd7bb33e9a105095acc89f6f579687bb124c2827334",
"id": 1
}
Method get_tip_header
get_tip_header(verbosity)verbosity:Uint32|null
- result:
ResponseFormat<HeaderView>
Returns the header with the highest block number in the canonical chain.
Because of chain reorganization, the block number returned can be less than previous invocations and different invocations may return different block headers with the same block number.
Params
verbosity- result format which allows 0 and 1. (Optional, the default is 1.)
Returns
When verbosity is 1, the RPC returns a JSON object as the result. See HeaderView for the
schema.
When verbosity is 0, it returns a 0x-prefixed hex string as the result. The string
encodes the header serialized by molecule using schema table Header.
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "get_tip_header",
"params": []
}
Response
{
"jsonrpc": "2.0",
"result": {
"compact_target": "0x1e02cbd3",
"epoch": "0x0",
"extra_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"hash": "0xfc53392312b0f85d23f8bfd7bb33e9a105095acc89f6f579687bb124c2827334",
"nonce": "0x0",
"number": "0x0",
"parent_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x1a22c0031e0",
"transactions_root": "0x8a31e59ebb73c2b142ec49e864caaee7e442469fcbc8041fb18dd945ada36184",
"version": "0x0"
},
"id": 1
}
Method get_live_cell
get_live_cell(out_point, with_data, include_tx_pool)out_point:OutPointwith_data:booleaninclude_tx_pool:boolean|null
- result:
CellWithStatus
Returns the status of a cell. The RPC returns extra information if it is a live cell.
Returns
This RPC tells whether a cell is live or not.
If the cell is live, the RPC will return details about the cell. Otherwise, the field cell is
null in the result.
If the cell is live and with_data is set to false, the field cell.data is null in the
result.
Params
out_point- Reference to the cell by transaction hash and output index.with_data- Whether the RPC should return cell data. Cell data can be huge, if the client does not need the data, it should set this tofalseto save bandwidth.include_tx_pool- Whether the RPC check live cell in TxPool, default is false.
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "get_live_cell",
"params": [
{
"tx_hash": "0xd43a26b1897c98a5917cd7f8af629e2f749ac37142068ef93c11048e208eff42",
"index": "0x0"
},
false
]
}
Response
{
"jsonrpc": "2.0",
"result": {
"block_hash": "0xfc53392312b0f85d23f8bfd7bb33e9a105095acc89f6f579687bb124c2827334",
"cell": {
"data": null,
"output": {
"capacity": "0xaa87bee538000",
"lock": {
"args": "0xfc6a14efa21dda983e863549c2c6015132147a1e30433db78e0226bfeb4f9908",
"code_hash": "0x0ab222ccd15b0160e2113b036ffe7a0d4cbcb40ac2fe7454194f381a33bd0d65",
"hash_type": "data"
},
"type": null
}
},
"status": "live"
},
"id": 1
}
Method get_tip_block_number
-
get_tip_block_number() -
result:
Uint64
Returns the highest block number in the canonical chain.
Because of chain reorganization, the returned block number may be less than a value returned in the previous invocation.
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "get_tip_block_number",
"params": []
}
Response
{
"jsonrpc": "2.0",
"result": "0x0",
"id": 1
}
Method get_current_epoch
-
get_current_epoch() -
result:
EpochView
Returns the epoch with the highest number in the canonical chain.
Pay attention that like blocks with the specific block number may change because of chain reorganization, This RPC may return different epochs which have the same epoch number.
Example
Request
{
"jsonrpc": "2.0",
"id": 1,
"method": "get_current_epoch",
"params": []
}
Response
{
"jsonrpc": "2.0",
"result": {
"compact_target": "0x1e02cbd3",
"length": "0xf0",
"number": "0x0",
"start_number": "0x0"
},
"id": 1
}