R5 Network
WebsiteR5 LabsGitHub
  • Getting Started
    • Hello & Welcome!
  • About R5
    • Overview
    • R5 Components
    • Consensus Mechanism
    • zkNet (Privacy)
  • R5 Coin
  • R5 Tokenomics
  • Tutorials & Guides
    • Connect & Use R5
      • R5 Desktop Wallet
      • MetaMask
      • Rabby Wallet
      • Coinbase Wallet
    • zkNet Web Wallet
    • R5 Desktop Wallet
      • Interface Overview
      • Send a Transaction
      • Receive a Transaction
      • Backup Your Wallet
      • Retrieve Your Private Key
    • How To: Deploy a Node
    • How To: Mine R5
    • How To: GPU Mine R5
    • How To: Build R5 From Source
    • How To: Connect Local Nodes
  • For Developers
    • R5 SDK
      • R5 Relayer
      • R5 Console
      • JS Console
      • CLI Wallet
      • SCdev
      • SSL Proxy
    • Hardware Requirements
    • R5 Testnet
    • R5 Devnet
    • Local Networks
    • JSON-RPC API
      • admin
      • debug
      • ethash
      • miner
      • net
      • r5 (eth)
      • rpc
      • txpool
      • web3
    • Indexer API
    • zkNet API
    • Node Configuration
    • Ethash-R5
    • Smart Contracts
    • Wrapped R5 (Native)
    • Tokens & NFTs
  • Bug Bounty Program
  • Resources
    • Website
    • R5 Labs
    • R5 Labs GitHub
Powered by GitBook
On this page
  • web3_version
  • web3_getEthereum
  • web3_getNetwork
  • web3_getNode
  • web3_getWhisper
  • web3_BigNumber
  • web3_createBatch
  • web3_fromAscii
  • web3_fromDecimal
  • web3_fromICAP
  • web3_fromUtf8
  • web3_fromWei
  • web3_isAddress
  • web3_isChecksumAddress
  • web3_isConnected
  • web3_padLeft
  • web3_padRight
  • web3_reset
  • web3_setProvider
  • web3_sha3
  • web3_toAscii
  • web3_toBigNumber
  • web3_toChecksumAddress
  • web3_toDecimal
  • web3_toHex
  • web3_toUtf8
  • web3_toWei
  1. For Developers
  2. JSON-RPC API

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:

{
  "jsonrpc": "2.0",
  "method": "web3_version",
  "params": [],
  "id": 1
}

Expected Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "api": "0.20.1",
    "ethereum": null,
    "network": "135",
    "node": "r5-core/v1.0.0-stable-9c0438ba/windows-amd64/go1.19",
    "whisper": null
  }
}

Parameters: None.


web3_getEthereum

Description: Retrieves the Ethereum client version via a callback.

Sample Request:

{
  "jsonrpc": "2.0",
  "method": "web3_getEthereum",
  "params": [],
  "id": 1
}

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:

{
  "jsonrpc": "2.0",
  "method": "web3_getNetwork",
  "params": [],
  "id": 1
}

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:

{
  "jsonrpc": "2.0",
  "method": "web3_getNode",
  "params": [],
  "id": 1
}

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:

{
  "jsonrpc": "2.0",
  "method": "web3_getWhisper",
  "params": [],
  "id": 1
}

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):

let bn = web3.BigNumber("12345678901234567890");

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):

let batch = web3.createBatch();
// batch.add(web3.eth.getBalance.request(...));

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:

let hexString = web3.fromAscii("hello");
console.log(hexString); // Output: "0x68656c6c6f"

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:

let hexValue = web3.fromDecimal("12345");
console.log(hexValue); // Output: "0x3039"

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:

let hexAddress = web3.fromICAP("XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS");
console.log(hexAddress); // Output: "0x..."

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:

let hexValue = web3.fromUtf8("hello");
console.log(hexValue); // Output: "0x68656c6c6f"

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:

let etherValue = web3.fromWei("1000000000000000000", "ether");
console.log(etherValue); // Output: "1"

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:

let valid = web3.isAddress("0x1234567890abcdef1234567890abcdef12345678");
console.log(valid); // Output: true or false

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:

let validChecksum = web3.isChecksumAddress("0x1234567890abcdef1234567890abcdef12345678");
console.log(validChecksum); // Output: true or false

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:

let connected = web3.isConnected();
console.log(connected); // Output: true or false

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:

let padded = web3.padLeft("123", 5, "0");
console.log(padded); // Output: "00123"

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:

let padded = web3.padRight("123", 5, "0");
console.log(padded); // Output: "12300"

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:

web3.reset(true);

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:

web3.setProvider("http://127.0.0.1:8545");

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:

let hash = web3.sha3("hello");
console.log(hash); // Output: "0x06d55f0d64f4e79e1e3e2b3a9eac0f3c9ef5e51a6f0fefcd6c43e1fd57e7bd47"

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:

let ascii = web3.toAscii("0x68656c6c6f");
console.log(ascii); // Output: "hello"

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:

let bn = web3.toBigNumber("12345678901234567890");
console.log(bn.toString()); // Output: "12345678901234567890"

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:

let checksum = web3.toChecksumAddress("0x1234567890abcdef1234567890abcdef12345678");
console.log(checksum);

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:

let dec = web3.toDecimal("0x3039");
console.log(dec); // Output: "12345"

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:

let hex = web3.toHex(255);
console.log(hex); // Output: "0xff"

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:

let utf8 = web3.toUtf8("0x68656c6c6f");
console.log(utf8); // Output: "hello"

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:

let weiValue = web3.toWei("1", "ether");
console.log(weiValue); // Output: "1000000000000000000"

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.

PrevioustxpoolNextIndexer API

Last updated 2 months ago