GetAllGasPriceStream

Introduction

GetAllGasPriceStream provides gas price subscription service on BSC. It pushes the gas price of BSC transactions in recent block to users at all percentile based on gRPC stream. The endpoint is: grpc.bsc-fee.blockrazor.me:443

Rate Limit

Tier 4
Tier 3
Tier 2
Tier 1
Tier 0

Streams

-

-

-

-

10

Request Parameter

Parameters
Mandatory
Format
Example
Remarks

blockRange

mandatory

int

20

Statistics of gas prices of transactions in the last N blocks, where N ranges from 1 to 20

Request Example

package main

import (
	"context"
	"crypto/tls"
	"log"

	pb "fee-test/bscfeepb"

	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials"
)

const (
	gRPCEndpoint = "grpc.bsc-fee.blockrazor.xyz:443"
	auth         = "your_auth"
)

func main() {
	conn, err := grpc.Dial(
		gRPCEndpoint,
		grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
		grpc.WithPerRPCCredentials(&Authentication{auth}),
	)
	if err != nil {
		panic(err)
	}
	defer conn.Close()

	client := pb.NewServerClient(conn)

	req := &pb.BlockRange{
		BlockRange: 5,
	}
	stream, err := client.GetAllGasPriceStream(context.Background(), req)
	if err != nil {
		panic(err)
	}

	for {
		message, err := stream.Recv()
		if err != nil {
			log.Printf("Failed to receive message: %v", err)
			break
		}
		log.Printf("Received Time: %s\n", message.Time.AsTime().Format("2006-01-02 15:04:05"))
		for _, gasPrice := range message.AllGasPrice {
			log.Printf("Received message percentile: %d\n", gasPrice.Percentile)
			log.Printf("Received message value: %s\n", gasPrice.Value)
		}
	}
}

type Authentication struct {
	auth string
}

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

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

Proto

Response Example

Last updated