For the complete documentation index, see llms.txt. This page is also available as Markdown.

GetRootHash - Polygon gRPC

Example code for the GetRootHash grpc method. Сomplete guide on how to use GetRootHash grpc in GetBlock.io Web3 documentation.

Computes the Merkle root over a Bor block range [startBlockNumber, endBlockNumber] in the exact form Heimdall uses to build checkpoint submissions to Ethereum L1. This is the equivalent of the bor_getRootHash JSON-RPC method as a strongly-typed gRPC call. The root hash is the value Heimdall validators sign and submit to Ethereum via the RootChain contract to anchor Polygon state to L1.

Request Parameters

Parameter
Type
Required
Description

startBlockNumber

uint64

Yes

First Bor block in the range (inclusive)

endBlockNumber

uint64

Yes

Last Bor block in the range (inclusive)

Request Example

grpcurl -H 'x-access-token: <ACCESS-TOKEN>' \
        -d '{"startBlockNumber": "90385120", "endBlockNumber": "90385122"}' \
        shared.ap-southeast-1.getblock.io:443 \
        bor.BorApi/GetRootHash
import * as grpc from '@grpc/grpc-js';
import protoLoader from '@grpc/proto-loader';

const GRPC_TARGET = 'shared.ap-southeast-1.getblock.io:443';
const ACCESS_TOKEN = '<ACCESS-TOKEN>';
const PROTO_PATH = './protos/bor/bor.proto';

const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
    keepCase: true,
    longs: String,
    enums: String,
    defaults: true,
    oneofs: true,
    includeDirs: ['./protos'],
});
const proto = grpc.loadPackageDefinition(packageDefinition);
const BorApiClient = proto.bor.BorApi;
const client = new BorApiClient(GRPC_TARGET, grpc.credentials.createSsl());

const metadata = new grpc.Metadata();
metadata.add('x-access-token', ACCESS_TOKEN);

const request = {
    "startBlockNumber": "90385120",
    "endBlockNumber": "90385122"
};

client.GetRootHash(request, metadata, (err, response) => {
    if (err) {
        console.error('gRPC error:', err.code, err.message);
        return;
    }
    console.log(JSON.stringify(response, null, 2));
});

Response Example

{
  "rootHash": "e9135010ac21a8dcdab1c4fd76a6ea1eefd41fab9f33b6cb834b40d8cf2f91f3"
}

H160 and H256 encoding. In JSON representations of protobuf messages, common.H160 (20-byte addresses) and common.H256 (32-byte hashes) are shown here as hex strings for readability. The actual JSON wire format from grpcurl or MessageToJson reflects the message structure defined in common/common.proto — typically a nested object encoding. Applications using the typed generated clients receive H160/H256 as strongly-typed message objects, not strings.

Response Fields

Field
Type
Description

rootHash

string

Hex-encoded Merkle root of the block range

Use Cases

  • Heimdall checkpoint construction (the primary consumer)

  • Independent verification of checkpoint submissions on Ethereum L1

  • Bridge audit tooling — reproducing the L1-submitted root from Bor data

Error Handling

gRPC Status (Code)
Message
Cause

UNAUTHENTICATED (16)

missing or invalid x-access-token

Access token missing from x-access-token gRPC metadata or invalid

PERMISSION_DENIED (7)

access denied

Access token doesn't have permission for this method or endpoint

INVALID_ARGUMENT (3)

invalid request

Request message is malformed or fails validation (e.g. invalid block number tag)

INTERNAL (13)

internal error

Server-side error while processing the request

UNAVAILABLE (14)

service unavailable

Bor node is temporarily unavailable (syncing, restart, or overload)

DEADLINE_EXCEEDED (4)

deadline exceeded

Request took longer than the client-configured timeout

RESOURCE_EXHAUSTED (8)

rate limit exceeded

Rate limit exceeded for your plan

INVALID_ARGUMENT (3)

invalid block range

endBlockNumber less than startBlockNumber, or range exceeds implementation limits

NOT_FOUND (5)

block range not available

One or both endpoint blocks are beyond the current chain tip

SDK Integration

Last updated

Was this helpful?