nonestring — a string identifying the type of client, version, operating system, and language version running on the nodeweb3_clientVersion code examplesChainstackProvider in ethers.js: ethers ChainstackProvider Documentation.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.
eth_getBlockReceipts on any EVM-compatible chain.getBlockReceipts Method:getBlockReceipts function is a part of the ExtraMethods class, which extends the functionality of the web3 object via the Web3PluginBase. This method uses this.requestManager.send to call the eth_getBlockReceipts JSON-RPC method, passing a single parameter blockNumber. The function formats the input and output values and returns the resulting receipts. This method is accessible through web3.extra.getBlockReceipts due to the registration of the ExtraMethods plugin with web3.registerPlugin(new ExtraMethods()).getClient Function:web3.eth.getNodeInfo call, which internally calls the web3_clientVersion JSON-RPC method without parameters. It formats the returned value and provides the full client version string.getClientName Function:getClientName calls getClient 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”.getAllReceipts Function:getClientName to retrieve the name and version of the client in a combined format. It checks if the client is Geth and, if so, further verifies whether its version is greater than or equal to 1.13.0 using the parseVersion and isVersionGreaterThanOrEqual functions. If the client is Geth with a supported version or Erigon, the function proceeds to fetch block receipts using web3.extra.getBlockReceipts. If the client is neither a supported version of Geth nor Erigon, it logs a message indicating this.parseVersion and isVersionGreaterThanOrEqual 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, and isVersionGreaterThanOrEqual compares this version against the specified minimum version, 1.13.0 in this case.main function serves as the entry point for execution. It attempts to call getAllReceipts with a specified block identifier, handling any exceptions and logging the results if available.