EthereumMethods

eth_getBlockByHash

The eth_getBlockByHash method returns information about a block whose hash is in the request.

eth_createAccessList

Overview

The 'eth_getBlockByHash' method returns information about a block whose hash is in the request.

Request

shell

curl --request POST \
     --url https://ethereum-mainnet-geth-archive.node.coinapi.io \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \     
     --header 'X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY' \
     --data '
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_getBlockByHash",
  "params": [
    "0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5",
    "0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5"
  ]
}
'

csharp

    using RestSharp; {

var options = new RestClientOptions("https://ethereum-mainnet-geth-archive.node.coinapi.io");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("accept", "application/json", "X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY");
request.AddJsonBody("{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_getBlockByHash\",\"params\":[\"0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5\",\"0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5\"]}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content); }

php

<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://ethereum-mainnet-geth-archive.node.coinapi.io",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 1,
'jsonrpc' => '2.0',
'method' => 'eth_getBlockByHash',
'params' => [
'0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5',
'0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5'
]
]),
CURLOPT_HTTPHEADER => [
"accept: application/json",
"content-type: application/json",
"X-CoinAPI-Key": "73034021-THIS-IS-SAMPLE-KEY"

],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>

python

 import requests

url = "https://ethereum-mainnet-geth-archive.node.coinapi.io"

payload = {
    "id": 1,
    "jsonrpc": "2.0",
    "method": "eth_getBlockByHash",
    "params": ["0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5", "0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5"]
}
headers = {
    "accept": "application/json",
    "content-type": "application/json",
        "X-CoinAPI-Key" : "73034021-THIS-IS-SAMPLE-KEY"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)

javascript

    const options = {
  method: 'POST',
  headers: {accept: 'application/json', 'content-type': 'application/json', 'X-CoinAPI-Key': '73034021-THIS-IS-SAMPLE-KEY'},
  body: JSON.stringify({
    id: 1,
    jsonrpc: '2.0',
    method: 'eth_getBlockByHash',
    params: [
      '0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5',
      '0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5'
    ]
  })
};

fetch('https://ethereum-mainnet-geth-archive.node.coinapi.io', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));

go

    package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://ethereum-mainnet-geth-archive.node.coinapi.io"

	payload := strings.NewReader("{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_getBlockByHash\",\"params\":[\"0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5\",\"0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5\"]}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("accept", "application/json")
	req.Header.Add("content-type", "application/json")
  req.Header.Add("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")


	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}

ruby

  require 'uri'
require 'net/http'

url = URI("https://ethereum-mainnet-geth-archive.node.coinapi.io")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["accept"] = 'application/json'
request["content-type"] = 'application/json'
request["X-CoinAPI-Key"] = '73034021-THIS-IS-SAMPLE-KEY'
request.body = "{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_getBlockByHash\",\"params\":[\"0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5\",\"0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5\"]}"

response = http.request(request)
puts response.read_body

java

    OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_getBlockByHash\",\"params\":[\"0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5\",\"0x63392b0dbab8cecbf16a8174f6ee7c2fd58a01d1f9bd5599aa422d0c782908d5\"]}");
Request request = new Request.Builder()
  .url("https://ethereum-mainnet-geth-archive.node.coinapi.io")
  .post(body)
  .addHeader("accept", "application/json")
  .addHeader("content-type", "application/json")
  .addHeader("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")
  .build();

Response response = client.newCall(request).execute();
}

Request Parameters

  • hash: (string) [ Required ] A string representing the hash (32 bytes) of a block.
  • transaction details flag: (boolean) [ Required ] If set to 'true', returns the full transaction objects, if 'false' returns only the hashes of the transactions.

Response

{
  "jsonrpc": "2.0",
  "id": 0,
  "result": {
    "difficulty": "0xbfabcdbd93dda",
    "extraData": "0x737061726b706f6f6c2d636e2d6e6f64652d3132",
    "gasLimit": "0x79f39e",
    "gasUsed": "0x79ccd3",
    "hash": "0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
    "logsBloom": "0x4848112002a2020aaa0812180045840210020005281600c80104264300080008000491220144461026015300100000128005018401002090a824a4150015410020140400d808440106689b29d0280b1005200007480ca950b15b010908814e01911000054202a020b05880b914642a0000300003010044044082075290283516be82504082003008c4d8d14462a8800c2990c88002a030140180036c220205201860402001014040180002006860810ec0a1100a14144148408118608200060461821802c081000042d0810104a8004510020211c088200420822a082040e10104c00d010064004c122692020c408a1aa2348020445403814002c800888208b1",
    "miner": "0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c",
    "mixHash": "0x3d1fdd16f15aeab72e7db1013b9f034ee33641d92f71c0736beab4e67d34c7a7",
    "nonce": "0x4db7a1c01d8a8072",
    "number": "0x5bad55",
    "parentHash": "0x61a8ad530a8a43e3583f8ec163f773ad370329b2375d66433eb82f005e1d6202",
    "receiptsRoot": "0x5eced534b3d84d3d732ddbc714f5fd51d98a941b28182b6efe6df3a0fe90004b",
    "sha3Uncles": "0x8a562e7634774d3e3a36698ac4915e37fc84a2cd0044cb84fa5d80263d2af4f6",
    "size": "0x41c7",
    "stateRoot": "0xf5208fffa2ba5a3f3a2f64ebd5ca3d098978bedd75f335f56b705d8715ee2305",
    "timestamp": "0x5b541449",
    "totalDifficulty": "0x12ac11391a2f3872fcd",
    "transactions": [
      "0x8784d99762bccd03b2086eabccee0d77f14d05463281e121a62abfebcf0d2d5f",
      "0x311be6a9b58748717ac0f70eb801d29973661aaf1365960d159e4ec4f4aa2d7f",
      "0xe42b0256058b7cad8a14b136a0364acda0b4c36f5b02dea7e69bfd82cef252a2",
      "0x4eb05376055c6456ed883fc843bc43df1dcf739c321ba431d518aecd7f98ca11",
      "0x994dd9e72b212b7dc5fd0466ab75adf7d391cf4f206a65b7ad2a1fd032bb06d7",
      "0xf6feecbb9ab0ac58591a4bc287059b1133089c499517e91a274e6a1f5e7dce53",
      "0x7e537d687a5525259480440c6ea2e1a8469cd98906eaff8597f3d2a44422ff97",
      "0xa762220e92bed6d77a2c19ffc60dad77d71bd5028c5230c896ab4b9552a39b50",
      "0xf1fa677edda7e5add8e794732c7554cd5459a5c12781dc71de73c7937dfb2775",
      "0x241d89f7888fbcfadfd415ee967882fec6fdd67c07ca8a00f2ca4c910a84c7dd"
    ],
    "transactionsRoot": "0xf98631e290e88f58a46b7032f025969039aa9b5696498efc76baf436fa69b262",
    "uncles": [
      "0x824cce7c7c2ec6874b9fa9a9a898eb5f27cbaf3991dfa81084c3af60d1db618c"
    ]
  }
}

A block object matching the hash in the request, or null when no block was found. The matched block contains the following keys and their values:

  • difficulty: A hexadecimal of the difficulty for this block.
  • extraData: The "extra data" field of this block.
  • gasLimit: Maximum gas allowed in this block.
  • gasUsed: Total used gas by all transactions in this block.
  • hash: 32 bytes. The hash of the block. Null when the returned block is the pending block.
  • logsBloom: 256 bytes. The bloom filter for the logs of the block. Null when the returned block is the pending block.
  • miner: 20 bytes. The address of the beneficiary to whom the mining rewards were given.
  • nonce: 8 bytes. The hash of the generated proof-of-work. Null when the returned block is the pending block.
  • number: The block number. Null when the returned block is the pending block.
  • parentHash: 32 bytes. The hash of the parent block.
  • receiptsRoot: 32 bytes. The root of the receipts trie of the block.
  • sha3Uncles: 32 bytes. The SHA3 of the uncles data in the block.
  • size: A hexadecimal of the size of this block in bytes.
  • stateRoot: 32 bytes. The root of the final state trie of the block.
  • timestamp: Unix timestamp for when the block was collated.
  • totalDifficulty: A hexadecimal of the total difficulty of the chain until this block.
  • transactions: [Array] An array of transaction objects, or 32 bytes transaction hashes depending on the last given parameter.
  • transactionsRoot: 32 bytes. The root of the transaction trie of the block.
  • uncles: [Array] An Array of uncle hashes.
Service StatusGitHub SDK