web3_sha3 - zkSync RPC Method
Compute the Keccak-256 hash of given data on zkSync Era. Useful for hash verification, smart contract development, and data integrity checks.
Returns the Keccak-256 hash (not standard SHA3-256) of the given data on zkSync Era.
Why zkSync? Build on Matter Labs' flagship zkEVM powering the Elastic Network of interoperable hyperchains with ZK Stack modular framework, hyperchain interoperability, native account abstraction, and $1.9B in tokenized real-world assets.
Important: Despite the method name, web3_sha3 computes Keccak-256, which differs from the NIST-standardized SHA3-256. Ethereum adopted Keccak before NIST finalized the SHA-3 standard with different padding.
When to Use This Method
web3_sha3 is helpful for ZK developers, RWA tokenization teams, and builders launching custom L2/L3 chains:
- Hash Verification — Confirm that your local Keccak-256 implementation matches the node's output
- Smart Contract Development — Compute function selectors and event topic hashes needed for ABI encoding
- Data Integrity Checks — Hash data server-side via RPC and compare against expected values
- Debugging — Verify hashing results when troubleshooting transaction or contract interactions
Code Examples
Common Use Cases
1. Function Selector Computation
Compute Solidity function selectors for ABI encoding:
async function getFunctionSelector(provider, signature) {
// Convert signature to hex
const hexSignature = '0x' + Buffer.from(signature).toString('hex');
// Hash via RPC
const hash = await provider.send('web3_sha3', [hexSignature]);
// Function selector is the first 4 bytes
const selector = hash.slice(0, 10);
console.log(`${signature} => ${selector}`);
return selector;
}
// Example: compute selectors for common ERC-20 functions
const selectors = {
'transfer(address,uint256)': await getFunctionSelector(provider, 'transfer(address,uint256)'),
'balanceOf(address)': await getFunctionSelector(provider, 'balanceOf(address)'),
'approve(address,uint256)': await getFunctionSelector(provider, 'approve(address,uint256)'),
};2. Hash Verification Between Local and RPC
Verify your local hashing matches the node to catch library misconfigurations:
async function verifyHashingConsistency(provider) {
const testCases = [
{ input: '0x', label: 'empty bytes' },
{ input: '0x68656c6c6f', label: '"hello"' },
{ input: '0x0123456789abcdef', label: 'hex data' },
];
for (const { input, label } of testCases) {
const rpcHash = await provider.send('web3_sha3', [input]);
const localHash = keccak256(input);
const match = rpcHash === localHash;
console.log(`${label}: ${match ? 'PASS' : 'FAIL'}`);
if (!match) {
console.error(` RPC: ${rpcHash}`);
console.error(` Local: ${localHash}`);
}
}
}3. Event Topic Hash Generation
Generate event topic hashes for filtering logs:
from web3 import Web3
def get_event_topic(w3, event_signature):
"""Generate the topic hash for an event signature."""
hex_sig = '0x' + event_signature.encode().hex()
result = w3.provider.make_request('web3_sha3', [hex_sig])
return result['result']
w3 = Web3(Web3.HTTPProvider('https://api-zksync-era-mainnet-full.n.dwellir.com/YOUR_API_KEY'))
# Common ERC-20 event topics
topics = {
'Transfer(address,address,uint256)': get_event_topic(w3, 'Transfer(address,address,uint256)'),
'Approval(address,address,uint256)': get_event_topic(w3, 'Approval(address,address,uint256)'),
}
for sig, topic in topics.items():
print(f'{sig}\n => {topic}')Error Handling
| Error Code | Description | Solution |
|---|---|---|
| -32602 | Invalid params | Ensure data is a valid 0x-prefixed hex string |
| -32603 | Internal error | Retry with exponential backoff |
| -32005 | Rate limit exceeded | Implement rate limiting or compute hashes locally instead |
Related Methods
eth_call— Execute a call without creating a transactioneth_getCode— Get contract bytecode at an addressweb3_clientVersion— Get node client version
web3_clientVersion
Get the client software version of your zkSync Era node. Essential for compatibility checks, fleet monitoring, and debugging client-specific behavior.
eth_protocolVersion
Get the current Ethereum protocol version on zkSync Era. Useful for client compatibility checks and identifying version-gated features.