getBlockHeight gRPC Method
Please note that this RPC method requires the Yellowstone gRPC add-on enabled on your QuickNode endpoint.
Parameters
This method does not accept any parameters
Returns
Blockheight
string
The latest block height
Request
package main import ( "context" "crypto/tls" "fmt" "log" "time" pb "yellowstone/proto" "google.golang.org/grpc" "google.golang.org/grpc/credentials" "google.golang.org/grpc/encoding/gzip" "google.golang.org/grpc/keepalive" ) // QuickNode endpoints consist of two crucial components: the endpoint name and the corresponding token // For eg: QN Endpoint: https://docs-demo.solana-mainnet.quiknode.pro/abcde123456789 // endpoint will be: docs-demo.solana-mainnet.quiknode.pro:10000 {10000 is the port number for gRPC} // token will be : abcde123456789 var ( endpoint = "YOUR_QN_ENDPOINT:10000" token = "YOUR_TOKEN_NUMBER" ) func main() { opts := []grpc.DialOption{ grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})), grpc.WithKeepaliveParams(kacp), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(1024*1024*1024), grpc.UseCompressor(gzip.Name)), grpc.WithPerRPCCredentials(tokenAuth{token: token}), } conn, err := grpc.NewClient(endpoint, opts...) if err != nil { log.Fatalf("Failed to connect: %v", err) } defer conn.Close() client := pb.NewGeyserClient(conn) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() blockheight, err := client.GetBlockHeight(ctx, &pb.GetBlockHeightRequest{}) if err != nil { log.Fatalf("Failed to get block height: %v", err) } fmt.Printf(" Block Height: %+v\n", blockheight) }
import Client from "@triton-one/yellowstone-grpc"; // QuickNode endpoints consist of two crucial components: the endpoint name and the corresponding token // For eg: QN Endpoint: https://docs-demo.solana-mainnet.quiknode.pro/abcde123456789 // endpoint will be: docs-demo.solana-mainnet.quiknode.pro:10000 {10000 is the port number for gRPC} // token will be : abcde123456789 const ENDPOINT = "YOUR_QN_ENDPOINT:10000"; const TOKEN = "YOUR_TOKEN_NUMBER"; async function main() { const client = new Client(ENDPOINT, TOKEN, {}); try { const blockheight = await client.getBlockHeight(); console.log(`Latest Blockheight: ${JSON.stringify(blockheight, null, 2)}`); } catch (error) { console.error("Error fetching Blockheight:", error); } } main() .catch((err) => { console.error("Unhandled error:", err); process.exit(1); });
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free