HyperCore APIs are in beta. Message fields, limits, and behavior may change, including breaking changes.
streams.v1.BlockStream/StreamBlocks is a server-streaming method. It sends one message per HyperCore block, in ascending block order, until you cancel the call or the server ends it with a status.
See the overview for the endpoint, authentication, and the full blocks.proto.
message StreamBlocksRequest {
optional uint64 start_block = 1;
}| Field | Type | Required | Description |
|---|---|---|---|
start_block | uint64 | No | Block number to start from, inclusive. Omit it to receive only new blocks. |
| Request | Result |
|---|---|
start_block omitted | The stream starts with the next new block. |
start_block inside the retained window | The server replays from start_block through the latest block, then continues with new blocks. There are no gaps or duplicates between the replayed and new blocks. |
start_block older than the retained window | The call fails with NOT_FOUND. No messages are sent. |
start_block newer than the latest block | The stream starts at the latest block, which can be lower than start_block. Skip blocks you don't need. |
Replay only covers a short window of recent blocks (a few seconds of mainnet), so it is for reconnecting clients rather than history.
A start_block the server can't replay as a continuous range returns NOT_FOUND, even if the block is recent. This also happens when the window has no blocks yet.
The stream is for live data and short reconnects. It doesn't serve historical ranges.
message BlockMessage {
uint64 block_number = 1;
bytes data = 2;
}| Field | Type | Description |
|---|---|---|
block_number | uint64 | Block height. Matches the top-level height in data. It is not the consensus round (abci_block.round). |
data | bytes | The block as UTF-8 JSON, passed through unchanged. Parse it with a JSON parser. |
data decodes to a JSON object with these top-level keys:
| Key | Contents |
|---|---|
abci_block | Block header and contents: time, round, parent_round, proposer, hardfork, and signed_action_bundles. |
resps | Responses to the block's actions. |
height | Block height, equal to block_number. |
The block format comes from the Hyperliquid node, not from this API, and can change when the node changes. Ignore keys you don't use.
- Messages arrive in ascending
block_numberorder, with no duplicates within a stream. - Block numbers are normally consecutive. If a number is skipped, the skipped block isn't available on the stream, and a resume into that range returns
NOT_FOUND.
Block sizes vary widely. Most are hundreds of kilobytes, and some are several megabytes. Set your client's maximum receive message size well above the common 4 MB default.
Every error ends the stream with a gRPC status. There are no error messages inside the stream. Branch on the status code; message text may change.
| Code | When | Message | What to do |
|---|---|---|---|
UNAUTHENTICATED | At call start | Must be authenticated! | Send x-token: <API_KEY> metadata. Don't retry until the key is fixed. |
NOT_FOUND | At call start | start_block is older than the retained block window | The missed blocks are no longer retained. Call again without start_block to resume live. |
ABORTED | During the stream | block stream fell behind live blocks | Your client read too slowly. Reconnect from your last block plus one, and read faster. |
UNAVAILABLE | At call start or during the stream | For example block feed not ready, block stream connection limit reached, or server draining | Temporary. Reconnect with backoff from your last block plus one. |
DEADLINE_EXCEEDED | When your call deadline expires | Set by your client | Don't set a deadline on this call. Reconnect. |
The server buffers a small number of blocks for each stream. If your client stops reading and that buffer fills, the server ends the stream with ABORTED.
To avoid this, read messages continuously and process them off the receive path, for example through a bounded queue. Because the retained window is short, a reconnect after a long stall returns NOT_FOUND.
- Record
block_numberafter you process each message. - When the stream ends with
ABORTED,UNAVAILABLE, or a network error, call again withstart_blockset to your lastblock_numberplus one. Use exponential backoff with jitter. - If the call returns
NOT_FOUND, the blocks you missed are no longer retained. Fetch them from another source if you need them, then call withoutstart_blockto resume live. - On
UNAUTHENTICATED, stop and fix the API key.
start_block is inclusive. If you resume from your last block_number instead of the next one, you receive that block again; drop it.
The server doesn't support reflection, so pass blocks.proto from the overview. Don't set -max-time; it ends the stream when it expires.
grpcurl \
-proto blocks.proto \
-H "x-token: $ALCHEMY_API_KEY" \
-max-msg-sz 67108864 \
-d '{}' \
hypercore-mainnet.g.alchemy.com:443 \
streams.v1.BlockStream/StreamBlocksTo resume, pass a block number:
grpcurl \
-proto blocks.proto \
-H "x-token: $ALCHEMY_API_KEY" \
-max-msg-sz 67108864 \
-d '{"start_block": 1194130000}' \
hypercore-mainnet.g.alchemy.com:443 \
streams.v1.BlockStream/StreamBlocksgrpcurl prints each message as JSON, with blockNumber as a string and data as base64:
{
"blockNumber": "1194129990",
"data": "eyJhYmNpX2Jsb2NrIjp7InRpbWUiOiIyMDI2LTEwLTIzVDA4OjMxOjMyLjc4MDg2MDc2OSIs..."
}Uses @grpc/grpc-js and @grpc/proto-loader, with blocks.proto in the working directory. The client resumes from the next block after a disconnect.
const grpc = require("@grpc/grpc-js");
const protoLoader = require("@grpc/proto-loader");
const definition = protoLoader.loadSync("blocks.proto", { longs: String });
const { BlockStream } = grpc.loadPackageDefinition(definition).streams.v1;
const client = new BlockStream(
"hypercore-mainnet.g.alchemy.com:443",
grpc.credentials.createSsl(),
{ "grpc.max_receive_message_length": 64 * 1024 * 1024 },
);
let lastBlock = null; // block_number of the last processed block, as a string
function connect() {
const metadata = new grpc.Metadata();
metadata.set("x-token", process.env.ALCHEMY_API_KEY);
const request =
lastBlock === null ? {} : { startBlock: (BigInt(lastBlock) + 1n).toString() };
const call = client.StreamBlocks(request, metadata);
call.on("data", (message) => {
const block = JSON.parse(message.data.toString("utf8"));
console.log(message.blockNumber, block.abci_block.time);
lastBlock = message.blockNumber;
});
// "status" fires exactly once when the call ends, whether it failed or the
// server completed it normally, so reconnect from here.
call.on("error", () => {}); // failures are handled in "status" below
call.on("status", (status) => {
if (status.code !== grpc.status.OK) {
console.error(grpc.status[status.code], status.details);
}
if (status.code === grpc.status.UNAUTHENTICATED) return; // fix the API key
if (status.code === grpc.status.NOT_FOUND) lastBlock = null; // resume live
setTimeout(connect, 1000); // use exponential backoff with jitter in production
});
}
connect();