web3_clientVersion | Ethereum
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.
Get you own node endpoint today
Start 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.
Use case
A use case for the web3_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.
Here is an implementation of this use case using web3.js:
Let’s break down the code:
- The
getBlockReceipts
Method:
ThegetBlockReceipts
function is a part of theExtraMethods
class, which extends the functionality of theweb3
object via theWeb3PluginBase
. This method usesthis.requestManager.send
to call theeth_getBlockReceipts
JSON-RPC method, passing a single parameterblockNumber
. The function formats the input and output values and returns the resulting receipts. This method is accessible throughweb3.extra.getBlockReceipts
due to the registration of theExtraMethods
plugin withweb3.registerPlugin(new ExtraMethods())
. - The
getClient
Function:
This function retrieves the client version using theweb3.eth.getNodeInfo
call, which internally calls theweb3_clientVersion
JSON-RPC method without parameters. It formats the returned value and provides the full client version string. - The
getClientName
Function:
getClientName
callsgetClient
to 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
getAllReceipts
Function:
This function usesgetClientName
to retrieve the name and version of the client in a combined format. It checks if the client isGeth
and, if so, further verifies whether its version is greater than or equal to1.13.0
using theparseVersion
andisVersionGreaterThanOrEqual
functions. If the client isGeth
with a supported version orErigon
, the function proceeds to fetch block receipts usingweb3.extra.getBlockReceipts
. If the client is neither a supported version ofGeth
norErigon
, it logs a message indicating this. - Version Parsing and Comparison:
Additional functionsparseVersion
andisVersionGreaterThanOrEqual
are included for parsing the version string and comparing it against a specified minimum version.parseVersion
extracts the semantic version number from the client version string, andisVersionGreaterThanOrEqual
compares this version against the specified minimum version,1.13.0
in this case. - Main Function and Execution Flow:
Themain
function serves as the entry point for execution. It attempts to callgetAllReceipts
with a specified block identifier, handling any exceptions and logging the results if available.