web3
The web3 namespace provides RPC endpoints for retrieving information about the client and performing basic cryptographic functions. These endpoints allow you to query the node’s client version and compute hashes using Keccak-256, which is essential for various dApp operations and smart contract interactions.
web3_version
Description: Returns an object containing version information for the API, Ethereum client, network, node, and Whisper (if available). It also includes functions to retrieve these values via callbacks.
Sample Request:
Expected Response:
Parameters: None.
web3_getEthereum
Description: Retrieves the Ethereum client version via a callback.
Sample Request:
Expected Response: The callback returns the Ethereum client version (if available).
Parameters: None.
web3_getNetwork
Description: Retrieves the network identifier via a callback.
Sample Request:
Expected Response: The callback returns the network value (e.g. "135").
Parameters: None.
web3_getNode
Description: Retrieves the node client version information via a callback.
Sample Request:
Expected Response: The callback returns the node string (e.g. "r5-core/v1.0.0-stable-9c0438ba/windows-amd64/go1.19").
Parameters: None.
web3_getWhisper
Description: Retrieves the Whisper client version via a callback, if available.
Sample Request:
Expected Response: The callback returns the Whisper version or null if not available.
Parameters: None.
web3_BigNumber
Description: Creates a BigNumber instance from a given input. This function is used for handling very large numbers (e.g., balances in wei).
Usage Example (JavaScript):
Parameters:
input (string | number): The numeric value to be converted into a BigNumber.
Expected Output: A BigNumber object representing the provided value.
web3_createBatch
Description: Creates a batch object to group multiple JSON-RPC requests into a single HTTP request. This is useful for reducing overhead when making multiple calls.
Sample Usage (JavaScript):
Parameters: None.
Expected Output: A batch object that supports adding multiple requests and executing them together.
web3_fromAscii
Description: Converts a string to its hexadecimal representation using ASCII encoding.
Sample Request:
Parameters:
str (string): The ASCII string to convert.
Expected Output: A hexadecimal string representing the input (prefixed with "0x").
web3_fromDecimal
Description: Converts a decimal value to a hexadecimal string.
Sample Request:
Parameters:
value (string or number): The decimal value to convert.
Expected Output: A hexadecimal representation of the value.
web3_fromICAP
Description: Converts an IBAN-compatible ICAP string to a hexadecimal address.
Sample Request:
Parameters:
icap (string): The ICAP string.
Expected Output: A hexadecimal address.
web3_fromUtf8
Description: Converts a UTF‑8 string to its hexadecimal representation.
Sample Request:
Parameters:
str (string): The UTF‑8 string to convert.
Expected Output: A hexadecimal string.
web3_fromWei
Description: Converts a value in wei to another unit (e.g., ether).
Sample Request:
Parameters:
number (string or number): The value in wei.
unit (string): The target unit (e.g., "ether", "gwei").
Expected Output: A string representing the value in the specified unit.
web3_isAddress
Description: Determines whether a given string is a valid Ethereum address.
Sample Request:
Parameters:
address (string): The address to validate.
Expected Output: A boolean indicating validity.
web3_isChecksumAddress
Description: Verifies whether an address is checksummed correctly.
Sample Request:
Parameters:
address (string): The address to verify.
Expected Output: A boolean indicating whether the address has the correct checksum.
web3_isConnected
Description: Checks if the client is currently connected to a node.
Sample Request:
Parameters: None.
Expected Output: A boolean indicating connection status.
web3_padLeft
Description: Pads a string on the left with a specified character until it reaches a certain length.
Sample Request:
Parameters:
string (string): The original string.
chars (number): The desired total length.
sign (string): The character to pad with.
Expected Output: The padded string.
web3_padRight
Description: Pads a string on the right with a specified character until it reaches a specified length.
Sample Request:
Parameters:
string (string): The original string.
chars (number): The desired total length.
sign (string): The character to pad with.
Expected Output: The padded string.
web3_reset
Description: Resets the web3 instance, optionally preserving the isSyncing status.
Sample Request:
Parameters:
keepIsSyncing (boolean): Indicates whether to keep the current syncing status.
Expected Output: The web3 instance is reset; no JSON-RPC response is typically returned.
web3_setProvider
Description: Sets the current provider for web3, allowing the connection to a different node or network.
Sample Request:
Parameters:
provider (string or object): The new provider URL or provider object.
Expected Output: The web3 instance now uses the new provider.
web3_sha3
Description: Computes the Keccak-256 hash of the provided input. Options may specify legacy behavior.
Sample Request:
Parameters:
string (string): The input string.
options (object, optional): Options for the hash function (if applicable).
Expected Output: A hexadecimal string representing the Keccak-256 hash.
web3_toAscii
Description: Converts a hexadecimal string to an ASCII string.
Sample Request:
Parameters:
hex (string): The hexadecimal string.
Expected Output: An ASCII string.
web3_toBigNumber
Description: Converts a number (string or numeric) into a BigNumber instance.
Sample Request:
Parameters:
number (string or number): The number to convert.
Expected Output: A BigNumber object.
web3_toChecksumAddress
Description: Converts an Ethereum address to its checksummed version.
Sample Request:
Parameters:
address (string): The address to convert.
Expected Output: A checksummed address string.
web3_toDecimal
Description: Converts a hexadecimal string to a decimal number.
Sample Request:
Parameters:
value (string): The hexadecimal value.
Expected Output: A decimal representation (as a string or number).
web3_toHex
Description: Converts a value to its hexadecimal representation.
Sample Request:
Parameters:
val (string | number): The value to convert.
Expected Output: A hexadecimal string.
web3_toUtf8
Description: Converts a hexadecimal string to a UTF‑8 string.
Sample Request:
Parameters:
hex (string): The hexadecimal string.
Expected Output: A UTF‑8 encoded string.
web3_toWei
Description: Converts a value from a specified unit to wei.
Sample Request:
Parameters:
number (string | number): The numeric value.
unit (string): The unit of the number (e.g., "ether", "gwei").
Expected Output: A string representing the value in wei.
Last updated