# NewBlocks

### Introduction

`NewBlocks`is used to subscribe to the block data stream in the high-performance network.

### Endpoint

<table><thead><tr><th width="160">Region</th><th>Availability Zone(AWS)</th><th>Relay Address</th></tr></thead><tbody><tr><td>Frankfurt</td><td>euc1-az2</td><td>35.157.64.49:50051</td></tr><tr><td>Tokyo</td><td>apne1-az4</td><td>54.249.93.63:50051</td></tr><tr><td>Ireland</td><td>euw1-az1</td><td>3.248.65.151:50051</td></tr><tr><td>Virginia</td><td>use1-az4</td><td>52.205.173.134:50051</td></tr></tbody></table>

### Price

The price is $500 per data stream per month. Please go to the [Pricing](https://blockrazor.io/#/pricing) page to purchase.

### Request Parameters

<table><thead><tr><th width="164">Parameters</th><th width="117">Mandatory</th><th width="102">Format</th><th width="94">Example</th><th>Description</th></tr></thead><tbody><tr><td>NodeValidation</td><td>Mandatory</td><td>boolean</td><td>false</td><td>This field currently only supports being set to <code>false</code>, and the relay will push all new blocks (unchecked) with lower latency.</td></tr></tbody></table>

### Request Example

<https://github.com/BlockRazorinc/relay_example>

{% tabs %}
{% tab title="Go" %}

```go
package main

import (
	"context"
	"fmt"

	// directory of the generated code using the provided relay.proto file
	pb "github.com/BlockRazorinc/relay_example/protobuf"
	"google.golang.org/grpc"
)

// auth will be used to verify the credential
type Authentication struct {
	apiKey string
}

func (a *Authentication) GetRequestMetadata(context.Context, ...string) (map[string]string, error) {
	return map[string]string{"apiKey": a.apiKey}, nil
}

func (a *Authentication) RequireTransportSecurity() bool {
	return false
}

func main() {

	// BlockRazor relay endpoint address
	blzrelayEndPoint := "ip:port"

	// auth will be used to verify the credential
	auth := Authentication{
		"your auth token",
	}

	// open gRPC connection to BlockRazor relay
	var err error
	conn, err := grpc.Dial(blzrelayEndPoint, grpc.WithInsecure(), grpc.WithPerRPCCredentials(&auth), grpc.WithWriteBufferSize(0), grpc.WithInitialConnWindowSize(128*1024))
	if err != nil {
		fmt.Println("error: ", err)
		return
	}

	// use the Gateway client connection interface
	client := pb.NewGatewayClient(conn)

	// create context and defer cancel of context
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	// create a subscription using the stream-specific method and request
	stream, err := client.NewBlocks(ctx, &pb.BlocksRequest{NodeValidation: false})
	if err != nil {
		fmt.Println("failed to subscribe new block: ", err)
		return
	}

	for {

		reply, err := stream.Recv()
		if err != nil {
			fmt.Println("stream receive error: ", err)
		}

		fmt.Println("recieve new block, block hash is ", reply.Hash)
	}
}
```

{% endtab %}
{% endtabs %}

#### Proto

The code of `relay.proto` is as follows:

```
syntax = "proto3";

package blockchain;

option go_package = "/Users/code/relay/grpcServer"; 
service Gateway {
  rpc SendTx (SendTxRequest) returns (SendTxReply) {}
  rpc SendTxs (SendTxsRequest) returns (SendTxsReply) {}
  rpc NewTxs (TxsRequest) returns (stream TxsReply){}
  rpc NewBlocks (BlocksRequest) returns (stream BlocksReply){}
}

message TxsRequest{
  bool node_validation = 1;
}

message Tx{
  bytes from = 1;
  int64 timestamp = 2;
  bytes raw_tx = 3;
}

message TxsReply{
   Tx tx = 1;
}

message BlocksRequest{
  bool node_validation = 1;
}

message BlockHeader{
  string parent_hash = 1;
  string sha3_uncles = 2;
  string miner = 3;
  string state_root = 4;
  string transactions_root = 5;
  string receipts_root = 6;
  string logs_bloom = 7;
  string difficulty = 8;
  string number = 9;
  uint64 gas_limit = 10;
  uint64 gas_used = 11;
  uint64 timestamp = 12;
  bytes extra_data = 13;
  string mix_hash = 14;
  uint64 nonce = 15;
  uint64 base_fee_per_gas = 16;
  string withdrawals_root = 17;
  uint64 blob_gas_used = 18;
  uint64 excess_blob_gas = 19;
  string parent_beacon_block_root = 20;
}

message NextValidator{
  string block_height = 1;
  string coinbase = 2;
}

message BlocksReply{
  string hash = 1;
  BlockHeader header = 2;
  repeated NextValidator nextValidator = 3;
  repeated Tx txs = 4;
}

message Transaction {
  string content = 1;
}

message Transactions {
  repeated Transaction transactions = 1;
}

message SendTxRequest {
  string transaction = 1;
}

message SendTxsRequest {
  string transactions = 1;
}

message SendTxReply {
  string tx_hash = 1;
}

message SendTxsReply {
  repeated string tx_hashs = 1;
}
```

### Response Example

**Success**

```json
{
	"hash": "0xe4a85aaa8cf4c85c4abf59c06b744ae680941e7ffba351fd4c166f0264e860de",
	"header": {
		"parent_hash": "0x0105992a6c305b0bbfbf7b4eebbbc92c4dca1bb2a18c1f93c551afc2c73c0668",
		"sha3_uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
		"miner": "0x9f1b7FAE54BE07F4FEE34Eb1aaCb39A1F7B6FC92",
		"state_root": "0xce2a7e35a643e5840e510df9eea8ba9177dd62fe743439ef159d7d9e783afd28",
		"transactions_root": "0x63c952adbe28ef60d8e723acec299ca62a915b51d05b060cb6fe97bb28814ab3",
		"receipts_root": "0xd3232a5308a69591dda132bd4ce1c1dbd5968ed9feee5f1385a5e7ad1b10527b",
		"logs_bloom": "8477149424673580296520836103527692456522284192111573121045681184670018737794069194486118998020237483301054022136573687133364882576385281526094331485603954025070865625599001965016471857986082361337851986790329901990002923474000909032395056767065187980257808021700240863783968353544053840361314138235944346718686049569138609472702141575196319415411746602993576034439427711191239874622732325947862558346553652593648034520192193214092215911630192819139737571343595880627533215841996399050061528845101804940660169259391681335118771766679784629118424769368884717750281985023526825099358014255162966726322082309693440030370",
		"difficulty": "2",
		"number": "40370748",
		"gas_limit": 139997863,
		"gas_used": 12180159,
		"timestamp": 1720674742,
		"extra_data": "2IMBBAqEZ2V0aIhnbzEuMjEuNYVsaW51eAAAAEj6ewX4tYMf//+4YKyfFdynrjSSLQKJj9FdhVSwaDFtnAdMnqNzKeVm2agkWE79uSpjZ2Wbrxt2eCFSvBRuPLIhONzRYpQgx/DeH/Xrhsz/A+EZw4BFaOVV3ch76i1QdJy1CADUqoc/XEaBHvhMhAJoAjqg3GksrNaxsaC5pxx8JS0YFpA6OQh7ofh7pTmra2Ve7lOEAmgCO6ABBZkqbDBbC7+/e07ru8ksTcobsqGMH5PFUa/CxzwGaIBHk8oYx40FGg4hnpMSQsTiOEAObH2DV3ytkUGOdEk4KENXgVf0/xsCA56w2r/VIqP7ux7HCD9vrh7H7fjxdU3xAA==",
		"mix_hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
		"noncpe":0,
		"base_fee_per_gas":0,
		"withdrawals_root":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
		"blob_gas_used": 131072,
		"excess_blob_gas":0,
		"parent_beacon_block_root":""
	
	},
	"nextValidator": [{
		"block_height": "40370749",
		"coinbase": "0xbdcc079bbb23c1d9a6f36aa31309676c258abac7"
	}, {
		"block_height": "40370750",
		"coinbase": "0xc2d534f079444e6e7ff9dabb3fd8a26c607932c8"
	}],
	"txs": [{
		"raw_tx": "+K6DzSWShQEqBfIAgwEwY5R2021E3EWV6NLrOtdF8XXtoTQoT4C4RKkFnLsAAAAAAAAAAAAAAAAFWjs3lXv70zRb7Zlo5+jdVtZwZgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGBV8GygaywAAgZOguQQg9l/3+bmldXAcm9lsSsgxwq8m+wqcXh/KwbKJ7E+gAS8g6ZuII8KJWFBFpVzTcyptzqfro00WDKR3oi1ly7g="
	}, {
		"raw_tx": "+QVPgxUyKIUBKgXyAIMHoSCUE3kk18NoFuDcrwFuthfMLJLAV4KAuQTkyYB1OQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAQEBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoAAAAAAAAAAAAAAAGQptag/qdv1AH5JjIvJ4fgACqZ4AQoECA4FDA0HAQsPAgAJBgMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAAA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NaAIu8AYupoFgRK+X8L9sYxgVNJobVpne44NbM/wQTYLLDGqanoAeH"
	}]
}
```

**Error**

```
rpc error: code = Unknown desc = data streams have exceeded its max limit [5]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.blockrazor.io/streams/block-stream/bsc/newblocks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
