Web3 Methods

The web3_* namespace contains methods specific to the web3 client implementation.

web3_clientVersion

Returns the current client version string.

Parameters

None

Returns

String - The current client version

Example

Request:

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

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "OPN/v1.0.0/linux-amd64/go1.19"
}

JavaScript Example:

web3_sha3

Returns Keccak-256 (not SHA3-256) hash of the given data.

Parameters

  1. DATA - The data to hash

Returns

DATA - The Keccak-256 hash of the given data

Example

Request:

Response:

JavaScript Examples:

Important Notes

  1. Not SHA3-256: This method returns Keccak-256, not the final SHA3-256 standard

  2. Ethereum Compatibility: Matches Ethereum's implementation exactly

  3. Input Format: Input must be hex-encoded with 0x prefix

Common Use Cases

Hashing Strings

Creating Function Selectors

Generating Deterministic Addresses

Error Handling

Both methods have minimal error conditions:

web3_clientVersion Errors

This method rarely fails, but possible errors:

web3_sha3 Errors

Common errors and their handling:

Performance Considerations

Batch Hashing

For multiple hash operations, consider batching:

Client-Side vs RPC

For better performance, use client-side hashing when possible:

Integration Examples

With Smart Contracts

Event Topic Generation

Compatibility Notes

Ethereum Compatibility

OPN Chain's implementation matches Ethereum exactly:

Library Support

All major libraries support these methods:

Security Considerations

Hash Collisions

While extremely unlikely, be aware of theoretical risks:

Input Validation

Always validate inputs before hashing:


Questions? Join our Discordarrow-up-right for help!

Last updated