Skip to main content

Gas

The RPC API enables you to query the gas price for a specific block or hash.


Gas Price

Returns gas price for a specific block_height or block_hash.

  • Using [null] will return the most recent block's gas price.
  • method: gas_price
  • params: [block_height], ["block_hash"], or [null]

[block_height]

{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "gas_price",
"params": [17824600]
}

["block_hash"]

{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "gas_price",
"params": ["AXa8CHDQSA8RdFCt12rtpFraVq4fDUgJbLPxwbaZcZrj"]
}

[null]

{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "gas_price",
"params": [null]
}
Example response:

{
"jsonrpc": "2.0",
"result": {
"gas_price": "100000000"
},
"id": "dontcare"
}

What could go wrong?

When API request fails, RPC server returns a structured error response with a limited number of well-defined error variants, so client code can exhaustively handle all the possible error cases. Our JSON-RPC errors follow verror convention for structuring the error response:

{
"error": {
"name": <ERROR_TYPE>,
"cause": {
"info": {..},
"name": <ERROR_CAUSE>
},
"code": -32000,
"data": String,
"message": "Server error",
},
"id": "dontcare",
"jsonrpc": "2.0"
}

Heads up

The fields code, data, and message in the structure above are considered legacy ones and might be deprecated in the future. Please, don't rely on them.

Here is the exhaustive list of the error variants that can be returned by gas_price method:

ERROR_TYPE
error.name

ERROR_CAUSE
error.cause.name
ReasonSolution
HANDLER_ERRORUNKNOWN_BLOCKThe requested block has not been produced yet or it has been garbage-collected (cleaned up to save space on the RPC node)
  • Check that the requested block is legit
  • If the block had been produced more than 5 epochs ago, try to send your request to an archival node
REQUEST_VALIDATION_ERRORPARSE_ERRORPassed arguments can't be parsed by JSON RPC server (missing arguments, wrong format, etc.)
  • Check the arguments passed and pass the correct ones
  • Check error.cause.info for more details
INTERNAL_ERRORINTERNAL_ERRORSomething went wrong with the node itself or overloaded
  • Try again later
  • Send a request to a different node
  • Check error.cause.info for more details

Was this page helpful?