XRP — gateway, noripple, Methods, ledger (2/2)
API reference for XRP. All methods ->
Part 2 of 2: 1 · 2
ledger_closed
Retrieves the latest closed ledger version.
The ledger_closed method returns the unique identifiers of the most recently closed ledger. (This ledger is not necessarily validated and immutable yet.)
Parameters
id(integer; required): a request ID (example: 1).jsonrpc(string; required): a JSON RPC spec used (example: 2.0).method(string; required): a method used for the request.params(array; required): none.
Returns
The response follows the standard format, with a successful result containing the following fields:
ledger_hash(string): The unique Hash of this ledger version, in hexadecimal.ledger_index(unsigned integer): The ledger index of this ledger version.
Request example
curl 'https://rpc.ankr.com/xrp_mainnet/YOUR_ANKR_API_KEY' \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "ledger_closed",
"params": [
{}
]
}'
Response example
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"ledger_hash": "3E6CF37B032E232ED6D77900C937647A275C8FE1F9F784F361B1022BB4608172",
"ledger_index": 100204931,
"status": "success"
}
}
ledger_current
Retrieves the current working ledger version.
The ledger_current method returns the unique identifiers of the current in-progress ledger. This command is mostly useful for testing, because the ledger returned is still in flux.
Parameters
id(integer; required): a request ID (example: 1).jsonrpc(string; required): a JSON RPC spec used (example: 2.0).method(string; required): a method used for the request.params(array; required): none.
Returns
The response follows the standard format, with a successful result containing the following field:
ledger_current_index(unsigned integer — ledger index): The ledger index of this ledger version.
Request example
curl 'https://rpc.ankr.com/xrp_mainnet/YOUR_ANKR_API_KEY' \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "ledger_current",
"params": [
{}
]
}'
Response example
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"ledger_current_index": 100205074,
"status": "success"
}
}
ledger_data
Retrieves the raw contents of a ledger version.
The ledger_data method retrieves contents of the specified ledger. You can iterate through several calls to retrieve the entire contents of a single ledger version.
Parameters
-
id(integer; required): a request ID (example: 1). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request. -
params(array; required):ledger_hash(string — hash; optional): A 20-byte hex string identifying the ledger version to use.ledger_index(number or string; optional): The ledger index of the ledger to use, or a shortcut string to choose a ledger automatically. (See Specifying Ledgers.)binary(boolean; optional): Iftrue, return ledger entries as hexadecimal strings instead of JSON. The default isfalse.limit(number; optional): Limit the number of ledger entries to retrieve. The server may return fewer than this number of entries. Cannot be more than 2048 (when requesting binary) or 256 (when requesting JSON). Positive values outside this range are replaced with the closest valid option. The default is the maximum.marker(string — marker; optional): Value from a previous paginated response. Resume retrieving data where that response left off.type(string; optional): Filter results to a specific type of ledger entry. This field accepts canonical names of ledger entry types (case-insensitive) or short names. If omitted, return ledger entries of all types.
Returns
The response follows the standard format, with a successful result containing the following fields:
ledger_index(unsigned integer — ledger index): The ledger index of this ledger version.ledger_hash(string — hash): Unique identifying hash of this ledger version.state(array): Array of JSON objects containing data from the ledger's state tree, as defined below.marker(string — marker): Server-defined value indicating the response is paginated. Pass this to the next call to resume where this call left off.
If a type field is mentioned in the request, the state array will be empty if the first set of array objects does not match the type requested. In such cases, you can use the marker from this response to paginate and retrieve further data.
The format of each object in the state array depends on whether binary was set to true or not in the request. Each state object may include the following fields:
data(string): (Only included if"binary": true) Hex representation of the requested data.LedgerEntryType(string): (Only included if"binary": false) String indicating what type of ledger object this object represents. See ledger object types for the full list.- (Additional fields) (various): (Only included if
"binary": false) Additional fields describing this object, depending on which ledger object type it is. index(string): Unique identifier for this ledger entry, as hex.
Request example
curl 'https://rpc.ankr.com/xrp_mainnet/YOUR_ANKR_API_KEY' \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "ledger_data",
"params": [
{
"binary": true,
"ledger_hash": "842B57C1CC0613299A686D3E9F310EC0422C84D3911E5056389AA7E5808A93C8",
"limit": 5
}
]
}'
Response example
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"error": "lgrNotFound",
"error_code": 21,
"error_message": "ledgerNotFound",
"request": {
"binary": true,
"command": "ledger_data",
"ledger_hash": "842B57C1CC0613299A686D3E9F310EC0422C84D3911E5056389AA7E5808A93C8",
"limit": 5
},
"status": "error"
}
}