Skip to main content
POST
web3_sha3
curl --request POST \
  --url https://rpc.testnet.tempo.xyz/ \
  --header 'Content-Type: application/json' \
  --data '
{
  "jsonrpc": "2.0",
  "method": "web3_sha3",
  "params": [
    "0x68656c6c6f"
  ],
  "id": 1
}
'
{
  "jsonrpc": "<string>",
  "id": 123,
  "result": "<string>"
}
Tempo API method that returns the Keccak-256 hash of the given data. This is the same hashing algorithm used by Ethereum for various purposes.

Parameters

  • data — the data to hash (hex encoded)

Response

  • result — the Keccak-256 hash of the input data

Use case

The web3_sha3 method is useful for:
  • Computing function selectors (first 4 bytes of keccak256 of function signature)
  • Computing event topics
  • General-purpose hashing

web3_sha3 code examples

const ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);

const sha3Example = async () => {
    // Hash hex-encoded data via RPC
    const hash = await provider.send("web3_sha3", ["0x68656c6c6f"]); // "hello" in hex
    console.log(`Hash of 'hello': ${hash}`);

    // Compare with ethers.js local computation
    const localHash = ethers.keccak256("0x68656c6c6f");
    console.log(`Local hash: ${localHash}`);
    console.log(`Hashes match: ${hash === localHash}`);

    // Compute a function selector
    const transferSelector = await provider.send("web3_sha3", [
      ethers.toUtf8Bytes("transfer(address,uint256)").reduce(
        (hex, byte) => hex + byte.toString(16).padStart(2, '0'),
        '0x'
      )
    ]);
    console.log(`\nTransfer function selector: ${transferSelector.slice(0, 10)}`);
  };

sha3Example();

Body

application/json
jsonrpc
string
default:2.0
method
string
default:web3_sha3
params
any[]

Data to hash (hex encoded)

id
integer
default:1

Response

200 - application/json

Keccak-256 hash

jsonrpc
string
id
integer
result
string

The Keccak-256 hash of the given data