Get you 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.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
- The
getBlockReceiptsMethod:
ThegetBlockReceiptsfunction is a part of theExtraMethodsclass, which extends the functionality of theweb3object via theWeb3PluginBase. This method usesthis.requestManager.sendto call theeth_getBlockReceiptsJSON-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.getBlockReceiptsdue to the registration of theExtraMethodsplugin withweb3.registerPlugin(new ExtraMethods()). - The
getClientFunction:
This function retrieves the client version using theweb3.eth.getNodeInfocall, which internally calls theweb3_clientVersionJSON-RPC method without parameters. It formats the returned value and provides 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 usingweb3.extra.getBlockReceipts. 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.
Body
application/json