Gas
The RPC API enables you to query the gas price for a specific block or hash.
Quick Reference
Parameter | Type | Description |
---|---|---|
block_height | number | Specific block height to query gas price for |
block_hash | string | Specific block hash to query gas price for |
null | null | Returns gas price for the latest block |
Gas Price
Description
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]
Example
null
example:
- JSON
- JavaScript
- HTTPie
- Lantstool
{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "gas_price",
"params": [null]
}
const response = await near.connection.provider.gasPrice(null);
http POST https://rpc.testnet.near.org \
jsonrpc=2.0 \
id=dontcare \
method=gas_price \
params:='[null]'
Try it out on Lantstool
Loading...
block_height
example:
- JSON
- JavaScript
- HTTPie
- Lantstool
{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "gas_price",
"params": [187310138]
}
const response = await near.connection.provider.gasPrice(187310138);
http POST https://archival-rpc.testnet.near.org \
jsonrpc=2.0 \
id=dontcare \
method=gas_price \
params:='[187310138]'
Try it out on Lantstool
Loading...
block_hash
example:
- JSON
- JavaScript
- HTTPie
- Lantstool
{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "gas_price",
"params": ["6RWmTYhXCzjMjoY3Mz1rfFcnBm8E6XeDDbFEPUA4sv1w"]
}
const response = await near.connection.provider.gasPrice(
'6RWmTYhXCzjMjoY3Mz1rfFcnBm8E6XeDDbFEPUA4sv1w',
);
http POST https://archival-rpc.testnet.near.org \
jsonrpc=2.0 \
id=dontcare \
method=gas_price \
params:='["6RWmTYhXCzjMjoY3Mz1rfFcnBm8E6XeDDbFEPUA4sv1w"]'
Try it out on Lantstool
Loading...
Example response:
{
"jsonrpc": "2.0",
"id": "dontcare",
"result": {
"gas_price": "100000000"
}
}
Error handling:
When making RPC API requests, you may encounter various errors related to network configuration, rate limiting, or request formatting. For comprehensive information about error types, causes, and solutions, see the RPC Errors documentation.