web3_sha3 - Optimism
Example code for the web3_sha3 json-rpc method. Сomplete guide on how to use web3_sha3 json-rpc in GetBlock.io Web3 documentation.
This method computes and returns the Keccak-256 hash (NOT standard SHA3-256) of the input data. Keccak-256 is the hash function used throughout Ethereum and Optimism to compute addresses, transaction hashes, and other cryptographic values. The input must be a hexadecimal string.
Parameters
data
DATA
The data to hash, as a hexadecimal string.
Yes
Request Sample
curl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "web3_sha3",
"params": ["0x68656c6c6f"],
"id": "getblock.io"
}'const axios = require('axios');
const url = 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/';
// "hello world" in hex
const payload = {
jsonrpc: '2.0',
method: 'web3_sha3',
params: ['0x68656c6c6f'],
id: 'getblock.io'
};
axios.post(url, payload, {
headers: { 'Content-Type': 'application/json' }
})
.then(response => console.log('Hash:', response.data.result))
.catch(error => console.error(error));Response
A successful response returns the following:
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"
}Response Parameters
id: A unique request identifier, matching theidsent in the request body.jsonrpc: Specifies the use of JSON-RPC version 2.0.result: The Keccak-256 hash of the input data as a 32-byte hexadecimal string.
Use Case
The web3_sha3 method is commonly used for:
Data hashing
Signature verification
Address computation
Cryptographic operations
Error Handling
-32602
Invalid params - malformed hex
-32603
Internal error
Web3 Integration
Last updated
Was this helpful?