Docs
Docs
Home
Getting Started
Agent Tooling
CLI
Supported Chains
Acala
Aptos
Arbitrum
Arc
Asset Hub
Astar
Avalanche
Base
Berachain
Bifrost
Binance Smart Chain
Bittensor
Blast
Boba Network
Bridge Hub
Celo
Centrifuge
Chiliz
Cronos
Enjin
Ethereum
Etherlink
Flow EVM Gateway
Gnosis
Hydration
Hyperliquid
Immutable
Ink
IoTeX
Kusama
Linea
LISK
Manta Atlantic
Manta Pacific
Mantle
MegaETH
Monad
Movement
Neuroweb
opBNB
Optimism
Plasma
Polkadot
Polygon
Pulsechain
Robinhood
Ronin
Scroll
Sonic
Starknet
Taiko
Tempo
Sui
TRON
Unichain
Viction
World Chain
XDC Network
XX Network
Zetachain
zkSync Era
Zora
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.

TRON RPC endpoint: endpoint URLs, plans and pricing.

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

Best Practices

  • Input data must be hex-encoded with a 0x prefix; plain text strings will cause errors
  • Use for quick Keccak-256 hashing without a client-side library, but prefer local hashing for performance
  • Compute function selectors by taking the first 4 bytes of the hash result
JSON-RPC request
{
  "jsonrpc": "2.0",
  "method": "web3_sha3",
  "params": ["0x68656c6c6f"],
  "id": 1
}

Code Examples

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

Related Methods

  • eth_call - Execute a call without creating a transaction
  • eth_getCode - Get contract bytecode at an address
  • web3_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 RPC Endpoint: Chain ID 130, HTTPS and WebSocket

Unichain mainnet (chain ID 130) archive RPC endpoint from Dwellir over HTTPS and WebSocket. OP Stack L2 by Uniswap, free plan available, API key required.

On this page

When to Use This MethodBest PracticesCode ExamplesCommon Use Cases1. Function Selector Computation2. Hash Verification Between Local and RPC3. Event Topic Hash GenerationError HandlingRelated Methods