web3_clientVersion
curl --request POST \
--url https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7 \
--header 'Content-Type: application/json' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "web3_clientVersion",
"params": []
}
'import requests
url = "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7"
payload = {
"id": 1,
"jsonrpc": "2.0",
"method": "web3_clientVersion",
"params": []
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({id: 1, jsonrpc: '2.0', method: 'web3_clientVersion', params: []})
};
fetch('https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7",
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' => 'web3_clientVersion',
'params' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7"
payload := strings.NewReader("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"web3_clientVersion\",\n \"params\": []\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7")
.header("Content-Type", "application/json")
.body("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"web3_clientVersion\",\n \"params\": []\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"web3_clientVersion\",\n \"params\": []\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "<string>",
"id": 123,
"result": "<string>"
}Ethereum node API
web3_clientVersion | Ethereum
Ethereum API method that returns the client type and version running on the Ethereum node. web3_clientVersion on Ethereum via Chainstack.
POST
/
0a9d79d93fb2f4a4b1e04695da2b77a7
web3_clientVersion
curl --request POST \
--url https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7 \
--header 'Content-Type: application/json' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "web3_clientVersion",
"params": []
}
'import requests
url = "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7"
payload = {
"id": 1,
"jsonrpc": "2.0",
"method": "web3_clientVersion",
"params": []
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({id: 1, jsonrpc: '2.0', method: 'web3_clientVersion', params: []})
};
fetch('https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7",
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' => 'web3_clientVersion',
'params' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7"
payload := strings.NewReader("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"web3_clientVersion\",\n \"params\": []\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7")
.header("Content-Type", "application/json")
.body("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"web3_clientVersion\",\n \"params\": []\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"web3_clientVersion\",\n \"params\": []\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "<string>",
"id": 123,
"result": "<string>"
}Ethereum API method that returns the client type and version running on the Ethereum node. This information can be useful to developers to verify that a node they are connecting to is compatible with their needs.
Here is an implementation of this use case using ethers.js:
Let’s break down the code:
Get your own node endpoint todayStart for free and get your app to production levels immediately. No credit card required.You can sign up with your GitHub, X, Google, or Microsoft account.
Parameters
none
Response
string— a string identifying the type of client, version, operating system, and language version running on the node
web3_clientVersion code examples
Learn more about the
ChainstackProvider in ethers.js: ethers ChainstackProvider Documentation.const ethers = require("ethers");
// Create a ChainstackProvider instance for Ethereum mainnet
const chainstack = new ethers.ChainstackProvider("mainnet");
const clientVersion = async () => {
const version = await chainstack.send("web3_clientVersion");
console.log(`Client version: ${version}`);
};
clientVersion();
from web3 import Web3
node_url = "CHAINSTACK_NODE_URL"
web3 = Web3.HTTPProvider(node_url)
client_version = web3.provider.make_request('web3_clientVersion', [])
print(client_version)
Use case
A use case for theweb3_clientVersion method can be to verify which client is running to then decide which method to run.
Let’s say you have a DApp that needs to retrieve all of the transaction receipts in a block; the Erigon client has a method for this, eth_getBlockReceipts, but with Geth, this method is only available starting from V1.13.0. You can use the web3_clientVersion method in your logic to identify which client you are using to see if you have the method available.
Read Expanding your blockchain horizons: The eth_getBlockReceipts emulator to learn how to build a program to emulate
eth_getBlockReceipts on any EVM-compatible chain.index.js
const ethers = require("ethers");
// Create a ChainstackProvider instance for Ethereum mainnet
const chainstack = new ethers.ChainstackProvider("mainnet");
// Call eth_getBlockReceipts, which has no dedicated ethers helper
async function getBlockReceipts(blockNumber) {
return chainstack.send("eth_getBlockReceipts", [blockNumber]);
}
// Get client version
async function getClient() {
const client = await chainstack.send("web3_clientVersion", []);
return client;
}
// Extract the client's name and version
async function getClientName() {
const clientVersion = await getClient();
// Split the clientVersion string by '/'
let parts = clientVersion.split('/');
// Split the second part by '-' and take the first element
let version = parts[1].split('-')[0];
// Concatenate the client name and version
let clientNameWithVersion = parts[0] + '/' + version;
console.log(clientNameWithVersion);
return clientNameWithVersion;
}
// Parse version from version string
function parseVersion(versionString) {
const versionMatch = versionString.match(/(\d+\.\d+\.\d+)/);
return versionMatch ? versionMatch[1] : null;
}
// Compare versions
function isVersionGreaterThanOrEqual(v1, v2) {
const v1Parts = v1.split('.').map(Number);
const v2Parts = v2.split('.').map(Number);
for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
const num1 = v1Parts[i] || 0;
const num2 = v2Parts[i] || 0;
if (num1 > num2) return true;
if (num1 < num2) return false;
}
return true; // versions are equal
}
// Get the receipts based on the client
async function getAllReceipts(blockId) {
const clientNameWithVersion = await getClientName();
const [clientName, clientVersion] = clientNameWithVersion.split('/');
if (clientName === 'Geth') {
const version = parseVersion(clientVersion);
if (isVersionGreaterThanOrEqual(version, '1.13.0')) {
console.log('Client is Geth with supported version.');
const receipts = await getBlockReceipts(blockId);
return receipts;
} else {
console.log('Client is Geth, but version is not supported.');
}
} else if (clientName === 'erigon') {
console.log('Client is Erigon');
const receipts = await getBlockReceipts(blockId);
return receipts;
} else {
console.log('Client version is not Geth or Erigon');
}
}
async function main() {
try {
const receipts = await getAllReceipts('latest');
if (receipts !== undefined) {
console.log(receipts);
}
} catch (error) {
console.error(error);
}
}
main();
- The
getBlockReceiptsMethod:
ThegetBlockReceiptsfunction is a helper that calls theeth_getBlockReceiptsJSON-RPC method directly withchainstack.send, passing a single parameterblockNumber. Because ethers.js does not expose a dedicated helper for this method,provider.sendis used to issue the raw JSON-RPC call and return the resulting receipts. - The
getClientFunction:
This function retrieves the client version by calling theweb3_clientVersionJSON-RPC method without parameters throughchainstack.send. It returns the full client version string. - The
getClientNameFunction:
getClientNamecallsgetClientto get the complete client version string. It then extracts both the client’s name and its version by splitting the version string at the first/and-characters. The function concatenates these parts to form a string in the format “ClientName/Version”. - The
getAllReceiptsFunction:
This function usesgetClientNameto retrieve the name and version of the client in a combined format. It checks if the client isGethand, if so, further verifies whether its version is greater than or equal to1.13.0using theparseVersionandisVersionGreaterThanOrEqualfunctions. If the client isGethwith a supported version orErigon, the function proceeds to fetch block receipts using thegetBlockReceiptshelper. If the client is neither a supported version ofGethnorErigon, it logs a message indicating this. - Version Parsing and Comparison:
Additional functionsparseVersionandisVersionGreaterThanOrEqualare included for parsing the version string and comparing it against a specified minimum version.parseVersionextracts the semantic version number from the client version string, andisVersionGreaterThanOrEqualcompares this version against the specified minimum version,1.13.0in this case. - Main Function and Execution Flow:
Themainfunction serves as the entry point for execution. It attempts to callgetAllReceiptswith a specified block identifier, handling any exceptions and logging the results if available.
Last modified on June 25, 2026
Was this page helpful?