Skip to content

Public Mempool

Introduction

NewTxs is used to subscribe to the transaction data stream in the high-performance network.

Endpoint

RegionAvailability Zone(AWS)Relay Address
Frankfurteuc1-az235.157.64.49:50051
Tokyoapne1-az454.249.93.63:50051
Irelandeuw1-az13.248.65.151:50051
Virginiause1-az452.205.173.134:50051

Rate Limit

Tier 4 Tier 3 Tier 2 Tier 1 Tier 0
Parallel data streams - 1 5 10 30

Request Parameters

ParametersMandatoryFormatExampleDescription
NodeValidationMandatorybooleanfalseThis field currently only supports being set to false, and the relay will push all new transactions (unchecked) with lower latency.

Request Example

https://github.com/BlockRazorinc/relay_example

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

package main

import (
    "context"
    "fmt"

    // directory of the generated code using the provided relay.proto file
    pb "github.com/BlockRazorinc/relay_example/protobuf"
    "github.com/ethereum/go-ethereum/core/types"
    "github.com/ethereum/go-ethereum/rlp"
    "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.NewTxs(ctx, &pb.TxsRequest{NodeValidation: false})
    if err != nil {
        fmt.Println("failed to subscribe new tx: ", err)
        return
    }

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

        err = rlp.DecodeBytes(reply.Tx.RawTx, tx)
        if err != nil {
            continue
        }

        fmt.Println("recieve new tx, tx hash is ", tx.Hash().String())

    }
}

{% 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

{
  "tx":[
     {
        "raw_tx":"+QH0gjOthDuaygCDBrbAlKoP7P6dEOH8IzwtDAw9whDVeHKRhwFrzEHpAAC5AYTVQ9H9AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAmsrt4HBPm7jWohanh7XmbX9S/gRLrth87fXF3H2gC0FAAAAAAAAAAAAAAAAbsa1rd5IJ6lr43ixr1+LWmT/OhgAAAAAAAAAAAAAAABV05gyb5kFn/d1SFJGmZAnsxl5VQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABVkLNFR0SQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGZ7qkBM09jlPtkQprbOV2bITVAfdbvzTltwBYjUJu6OIzF3aAAAAAAAAAAAAAAAAHqXLqcmW4qO1ZEAZXn2nYI/dKV1AAAAAAAAAAAAAAAAVdOYMm+ZBZ/3dUhSRpmQJ7MZeVUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASvCnY7scAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABme6pAgZOgy2LsKlIqPeeM7d520T3eAwIVk9O+vY4wT+zifYp0GGOgTY7Z5J3zs/YCj1HvVXOZF9Q2rj5x421GBG9CrKmxVGo="
     }
   ]
}

Error

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