Chain Data
Get Hedera's chain information using Arkhia's Json-RPC Relay.
info
To configure your web3Provider, please refer to the Getting Started Docs:
eth_chainId
Get chain id.
Parameters
None
Returns
Hex string or Integer: Current chain id
- Web3.js
- Node.js (Axios)
- Curl
web3Provider.eth.getChainId() .then((res) => console.log(`-> get chain ID`, res)) .catch(e => console.log('-> get chain ID error: ' + e));
import axios from 'axios';const data = JSON.stringify({ "jsonrpc": "2.0", "method": "eth_chainId", "params": [], "id": 0});const config = { method: 'post', url: '<JSON_RPC_URL>/<YOUR_API_KEY>', headers: { 'Content-Type': 'application/json'}, data : data};async function main() { await axios(config) .then(function (response) { console.log(response.data)); }); .catch(function (error) { console.log(error); });}
curl --location --request POST '<JSON_RPC_URL>/<YOUR_API_KEY>' \--header 'Content-Type: application/json' \--data-raw '{ "jsonrpc": "2.0", "method": "eth_chainId", "params":[], "id": 0}'
eth_blockNumber
Get the current block number.
Parameters
None
Returns
Hex string or Integer: Current block number
- Web3.js
- Node.js (Axios)
- Curl
web3Provider.eth.getBlockNumber() .then((res) => console.log(`-> get block number`, res)) .catch(e => console.log('-> get block number error: ' + e));
import axios from 'axios';const data = JSON.stringify({ "jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": 0});const config = { method: 'post', url: '<JSON_RPC_URL>/<YOUR_API_KEY>', headers: { 'Content-Type': 'application/json'}, data : data};async function main() { await axios(config) .then(function (response) { console.log(response.data)); }); .catch(function (error) { console.log(error); });}
curl --location --request POST '<JSON_RPC_URL>/<YOUR_API_KEY>' \--header 'Content-Type: application/json' \--data-raw '{ "jsonrpc": "2.0", "method": "eth_blockNumber", "params":[], "id": 0}'
eth_gasPrice
Get the current gas price.
Parameters
None
Returns
String: Current gas price
- Web3.js
- Node.js (Axios)
- Curl
web3Provider.eth.getGasPrice() .then((res) => console.log(`-> get gas price`, res)) .catch(e => console.log('-> get gas price error: ' + e));
import axios from 'axios';const data = JSON.stringify({ "jsonrpc": "2.0", "method": "eth_gasPrice", "params": [], "id": 0});const config = { method: 'post', url: '<JSON_RPC_URL>/<YOUR_API_KEY>', headers: { 'Content-Type': 'application/json'}, data : data};async function main() { await axios(config) .then(function (response) { console.log(response.data)); }); .catch(function (error) { console.log(error); });}
curl --location --request POST '<JSON_RPC_URL>/<YOUR_API_KEY>' \--header 'Content-Type: application/json' \--data-raw '{ "jsonrpc": "2.0", "method": "eth_gasPrice", "params":[], "id": 0}'
eth_estimateGas
Get the current gas price.
Parameters
Transaction: Transaction object
Required
from
-String|Number
: The address for the sending account. Uses the web3.eth.defaultAccount property, if not specified. Or an address or index of a local wallet in web3.eth.accounts.wallet.to
-String
: (optional) The destination address of the message, left undefined for a contract-creation transaction.value
-Number|String|BN|BigNumber
: (optional) The value transferred for the transaction in wei, also the endowment if it’s a contract-creation transaction.gas
-Number
: (optional, default: To-Be-Determined) The amount of gas to use for the transaction (unused gas is refunded).gasPrice
-Number|String|BN|BigNumber
: (optional) The price of gas for this transaction in wei, defaults to web3.eth.gasPrice.data
-String
: (optional) Either a ABI byte string containing the data of the function call on a contract, or in the case of a contract-creation transaction the initialisation code.nonce
-Number
: (optional) Integer of the nonce. This allows to overwrite your own pending transactions that use the same nonce.chain
-String
: (optional) Defaults to mainnet.
Block: Integer block number, or the string "latest", "earliest" or "pending", see the default block parameter
Returns
Hex string or Integer: estimated gas for the transaction
- Web3.js
- Node.js (Axios)
- Curl
web3Provider.eth.estimateGas({ from: "0x0030002e0030002e003400320032003700350035"}) .then((res) => console.log(`-> get Gas`, res)) .catch(e => console.log('-> get Gas error: ' + e));
import axios from 'axios';const data = JSON.stringify({ "jsonrpc": "2.0", "method": "eth_estimateGas", "params": [ { "from": "0x0030002e0030002e003400320032003700350035" } ], "id": 0});const config = { method: 'post', url: '<JSON_RPC_URL>/<YOUR_API_KEY>', headers: { 'Content-Type': 'application/json'}, data : data};async function main() { await axios(config) .then(function (response) { console.log(response.data)); }); .catch(function (error) { console.log(error); });}
curl --location --request POST '<JSON_RPC_URL>/<YOUR_API_KEY>' \--header 'Content-Type: application/json' \--data-raw '{ "jsonrpc": "2.0", "method": "eth_estimateGas", "params":[{ "from": "0x0030002e0030002e003400320032003700350035" } ], "id": 0}'
eth_getBlockByHash
Get block details using the block hash.
Parameters
- Block hash: Hash of the block
Required
Returns
The block information
- Web3.js
- Node.js (Axios)
- Curl
/*<BLOCK_HASH> can be found on hashscan https://hashscan.io/#/mainnet/dashboardfor example: 0x8b7de6e435b5a1f0f9b3dd49a7943bc654b86930abecf22792e45e203e3fe8fac17d7c93af28e079bf71908babf0d5f8*/web3Provider.eth.getBlock(`<BLOCK_HASH>`) .then((res) => console.log(`-> get block by hash`, res)) .catch(e => console.log('-> get block by hash error: ' + e));
/*<BLOCK_HASH> can be found on hashscan https://hashscan.io/#/mainnet/dashboardfor example: 0x8b7de6e435b5a1f0f9b3dd49a7943bc654b86930abecf22792e45e203e3fe8fac17d7c93af28e079bf71908babf0d5f8*/import axios from 'axios';const data = JSON.stringify({ "jsonrpc": "2.0", "method": "eth_getBlockByHash", "params": [ "<BLOCK_HASH>" ], "id": 0});const config = { method: 'post', url: '<JSON_RPC_URL>/<YOUR_API_KEY>', headers: { 'Content-Type': 'application/json'}, data : data};async function main() { await axios(config) .then(function (response) { console.log(response.data)); }); .catch(function (error) { console.log(error); });}
# <BLOCK_HASH> can be found on hashscan https://hashscan.io/#/mainnet/dashboard# for example: 0x8b7de6e435b5a1f0f9b3dd49a7943bc654b86930abecf22792e45e203e3fe8fac17d7c93af28e079bf71908babf0d5f8curl --location --request POST '<JSON_RPC_URL>/<YOUR_API_KEY>' \--header 'Content-Type: application/json' \--data-raw '{ "jsonrpc": "2.0", "method": "eth_getBlockByHash", "params":["<BLOCK_HASH>"], "id": 0}'
eth_getBlockByNumber
Get block details using the block number.
Parameters
- Block number: Number of the block or block tag (earliest, latest, pending)
Required
Returns
The block information
- Web3.js
- Node.js (Axios)
- Curl
/*<BLOCK_NUMBER> can be found on hashscan https://hashscan.io/#/mainnet/dashboardfor example: 38453581*/web3Provider.eth.getBlock(`<BLOCK_NUMBER>`) .then((res) => console.log(`-> get block by number`, res)) .catch(e => console.log('-> get block by number error: ' + e));
/*<BLOCK_NUMBER> can be found on hashscan https://hashscan.io/#/mainnet/dashboardfor example: 38453581*/import axios from 'axios';const data = JSON.stringify({ "jsonrpc": "2.0", "method": "eth_getBlockByNumber", "params": [ "<BLOCK_NUMBER>" ], "id": 0});const config = { method: 'post', url: '<JSON_RPC_URL>/<YOUR_API_KEY>', headers: { 'Content-Type': 'application/json'}, data : data};async function main() { await axios(config) .then(function (response) { console.log(response.data)); }); .catch(function (error) { console.log(error); });}
# <BLOCK_NUMBER> can be found on hashscan https://hashscan.io/#/mainnet/dashboard# for example: 38453581curl --location --request POST '<JSON_RPC_URL>/<YOUR_API_KEY>' \--header 'Content-Type: application/json' \--data-raw '{ "jsonrpc": "2.0", "method": "eth_getBlockByNumber", "params":["<BLOCK_NUMBER>"], "id": 0}'