Docs
Supported ChainsTRONEthereum JSON-RPC APINetwork Methods

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

Request
dataDATA

The hex-encoded data to hash (must be 0x prefixed)

Response Body

Response
resultDATA

The Keccak-256 hash of the provided data (32 bytes, 0x prefixed)

Error Responses

Errors
Error Response-32602

Code Examples

Bash
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:

JavaScript
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:

JavaScript
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:

Python
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 CodeDescriptionSolution
-32602Invalid paramsEnsure data is a valid 0x-prefixed hex string
-32603Internal errorRetry with exponential backoff
-32005Rate limit exceededImplement rate limiting or compute hashes locally instead