web3_sha3 - TRON RPC Method
Compute the Keccak-256 hash of given data on TRON. 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 TRON.
Why TRON? Build on the TVM-compatible Layer 1 for TRC-20 payments, wallet APIs, and low-cost smart contract execution with TVM compatibility paired with native TRON wallet APIs, DPoS block production, and low-cost transaction flows.
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 TRON developers building payment rails, exchanges, and consumer crypto applications:
- 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
Request Parameters
The hex-encoded data to hash (must be 0x prefixed)
Response Body
The Keccak-256 hash of the provided data (32 bytes, 0x prefixed)
Error Responses
Code Examples
curl -X POST https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/jsonrpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "web3_sha3",
"params": ["0x68656c6c6f"],
"id": 1
}'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-tron-mainnet.n.dwellir.com/YOUR_API_KEY/jsonrpc'))
# 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 TRON node. Essential for compatibility checks, fleet monitoring, and debugging client-specific behavior.
Unichain - DeFi-Optimized L2 by Uniswap
Complete guide to Unichain RPC and API integration with Dwellir. Build on the fast, decentralized L2 designed for DeFi and cross-chain liquidity.