EthereumMethods

eth_blockNumber

The eth_blockNumber method returns the current latest block number.

eth_blockNumber

Overview

The 'eth_blockNumber' method returns the current latest block number.

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_blockNumber"
}'

csharp

using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Post,
    RequestUri = new Uri("https://ethereum-mainnet-geth-archive.node.coinapi.io"),
    Headers =
    {
        { "accept", "application/json" },
    },
    Content = new StringContent("{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_blockNumber\"}")
    {
        Headers =
        {
            ContentType = new MediaTypeHeaderValue("application/json")
        }
    }
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}

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_blockNumber'
]),
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_blockNumber"
}
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_blockNumber'})
};

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_blockNumber\"}")

	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_blockNumber\"}"

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

java

AsyncHttpClient client = new DefaultAsyncHttpClient();
client.prepare("POST", "https://ethereum-mainnet-geth-archive.node.coinapi.io")
  .setHeader("accept", "application/json")
  .setHeader("content-type", "application/json")
  .setHeader("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")
  .setBody("{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_blockNumber\"}")
  .execute()
  .toCompletableFuture()
  .thenAccept(System.out::println)
  .join();

client.close();

You can also replace mainnet with any other supported network

Response

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x1126d53"
}

A hexadecimal of an integer representing the current block number the client is on.

Service StatusGitHub SDK