web3_sha3
Returns Keccak-256 (not the standardized SHA3-256) of the given data.
Parameters
See Ethereum JSON-RPC spec for parameters of web3_sha3
.
Examples
- cURL
- Ethers.js v6
- Viem
- web3.py
curl -X POST https://api-chiliz-mainnet-archive.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "web3_sha3",
"params": [
"0x68656c6c6f20776f726c64"
],
"id": 1
}'
import { JsonRpcProvider, keccak256, toUtf8Bytes } from 'ethers';
const provider = new JsonRpcProvider(
'https://api-chiliz-mainnet-archive.n.dwellir.com/YOUR_API_KEY'
);
// Compute keccak256 hash
const data = '0x68656c6c6f20776f726c64'; // "hello world" in hex
const hash = await provider.send('web3_sha3', [data]);
console.log(`Hash: ${hash}`);
// Alternative using ethers utils
const localHash = keccak256(toUtf8Bytes('hello world'));
console.log(`Local hash: ${localHash}`);
import { createPublicClient, http, defineChain, keccak256, toHex } from 'viem';
const chiliz = defineChain({
id: 88888,
name: 'Chiliz',
nativeCurrency: {
decimals: 18,
name: 'CHZ',
symbol: 'CHZ',
},
rpcUrls: {
default: {
http: ['https://api-chiliz-mainnet-archive.n.dwellir.com/YOUR_API_KEY'],
},
},
blockExplorers: {
default: { name: 'ChilizScan', url: 'https://chiliscan.com' },
},
});
const client = createPublicClient({
chain: chiliz,
transport: http('https://api-chiliz-mainnet-archive.n.dwellir.com/YOUR_API_KEY'),
});
// Compute keccak256 hash
const data = '0x68656c6c6f20776f726c64';
const hash = await client.request({
method: 'web3_sha3',
params: [data]
});
console.log(`Hash: ${hash}`);
// Alternative using viem utils
const localHash = keccak256(toHex('hello world'));
console.log(`Local hash: ${localHash}`);
from web3 import Web3
w3 = Web3(Web3.HTTPProvider(
'https://api-chiliz-mainnet-archive.n.dwellir.com/YOUR_API_KEY'
))
# Compute keccak256 hash
data = '0x68656c6c6f20776f726c64' # "hello world" in hex
hash_result = w3.manager.request_blocking('web3_sha3', [data])
print(f"Hash: {hash_result}")
# Alternative using web3 utils
local_hash = w3.keccak(text='hello world')
print(f"Local hash: {local_hash.hex()}")
Response
Returns the Keccak-256 hash of the input data. Common error responses:
{"code": -32700, "message": "Parse error"}
- Invalid JSON{"code": -32602, "message": "Invalid params"}
- Invalid parameters{"code": -32603, "message": "Internal error"}
- Server error