getBlockHeight gRPC Method - Solana gRPC
Solana gRPC est inclus dans les plans Scale et Business. Pour les plans Build et Accelerate, il reste disponible via l'extension Solana gRPC.
Paramètres
Cette méthode n'accepte aucun paramètre
Renvoie
Blockheight
chaîne de caractères
Chargement...
Requête
1package main23import (4"context"5"crypto/tls"6"fmt"7"log"8"time"910pb "yellowstone/proto"111213"google.golang.org/grpc"14"google.golang.org/grpc/credentials"15"google.golang.org/grpc/encoding/gzip"16"google.golang.org/grpc/keepalive"17)1819// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token20// For eg: QN Endpoint: https://docs-demo.solana-mainnet.quiknode.pro/abcde12345678921// endpoint will be: docs-demo.solana-mainnet.quiknode.pro:10000 {10000 is the port number for gRPC}22// token will be : abcde1234567892324var (25endpoint = "YOUR_QN_ENDPOINT:10000"26token = "YOUR_TOKEN_NUMBER"27)2829func main() {30opts := []grpc.DialOption{31grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),32grpc.WithKeepaliveParams(kacp),33grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(1024*1024*1024), grpc.UseCompressor(gzip.Name)),34grpc.WithPerRPCCredentials(tokenAuth{token: token}),35}3637conn, err := grpc.NewClient(endpoint, opts...)38if err != nil {39log.Fatalf("Échec de la connexion : %v", err)40}41defer conn.Close()4243client := pb.NewGeyserClient(conn)4445ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)46defer cancel()4748blockheight, err := client.GetBlockHeight(ctx, &pb.GetBlockHeightRequest{})49if err != nil {50log.Fatalf("Failed to get block height: %v", err)51}52fmt.Printf(" Block Height: %+v\n", blockheight)5354}
1package main23import (4"context"5"crypto/tls"6"fmt"7"log"8"time"910pb "yellowstone/proto"111213"google.golang.org/grpc"14"google.golang.org/grpc/credentials"15"google.golang.org/grpc/encoding/gzip"16"google.golang.org/grpc/keepalive"17)1819// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token20// For eg: QN Endpoint: https://docs-demo.solana-mainnet.quiknode.pro/abcde12345678921// endpoint will be: docs-demo.solana-mainnet.quiknode.pro:10000 {10000 is the port number for gRPC}22// token will be : abcde1234567892324var (25endpoint = "YOUR_QN_ENDPOINT:10000"26token = "YOUR_TOKEN_NUMBER"27)2829func main() {30opts := []grpc.DialOption{31grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),32grpc.WithKeepaliveParams(kacp),33grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(1024*1024*1024), grpc.UseCompressor(gzip.Name)),34grpc.WithPerRPCCredentials(tokenAuth{token: token}),35}3637conn, err := grpc.NewClient(endpoint, opts...)38if err != nil {39log.Fatalf("Échec de la connexion : %v", err)40}41defer conn.Close()4243client := pb.NewGeyserClient(conn)4445ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)46defer cancel()4748blockheight, err := client.GetBlockHeight(ctx, &pb.GetBlockHeightRequest{})49if err != nil {50log.Fatalf("Failed to get block height: %v", err)51}52fmt.Printf(" Block Height: %+v\n", blockheight)5354}
1import Client from "@triton-one/yellowstone-grpc";23// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token4// For eg: QN Endpoint: https://docs-demo.solana-mainnet.quiknode.pro/abcde1234567895// endpoint will be: docs-demo.solana-mainnet.quiknode.pro:10000 {10000 is the port number for gRPC}6// token will be : abcde12345678978const POINT D'EXTRÉMITÉ = "VOTRE_POINT_D'ACCÈS_QN:10000";9const TOKEN = "VOTRE_NUMÉRO_DE_TOKEN";1011async function main() {12const client = new Client(ENDPOINT, TOKEN, {});1314essayer {15const blockheight = await client.getBlockHeight();16console.log(`Latest Blockheight: ${JSON.stringify(blockheight, null, 2)}`);17} catch (error) {18console.error("Error fetching Blockheight:", error);19}20}2122main()23.catch((err) => {24console.error("Erreur non gérée :", err);25process.exit(1);26});
1import Client from "@triton-one/yellowstone-grpc";23// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token4// For eg: QN Endpoint: https://docs-demo.solana-mainnet.quiknode.pro/abcde1234567895// endpoint will be: docs-demo.solana-mainnet.quiknode.pro:10000 {10000 is the port number for gRPC}6// token will be : abcde12345678978const POINT D'EXTRÉMITÉ = "VOTRE_POINT_D'ACCÈS_QN:10000";9const TOKEN = "VOTRE_NUMÉRO_DE_TOKEN";1011async function main() {12const client = new Client(ENDPOINT, TOKEN, {});1314essayer {15const blockheight = await client.getBlockHeight();16console.log(`Latest Blockheight: ${JSON.stringify(blockheight, null, 2)}`);17} catch (error) {18console.error("Error fetching Blockheight:", error);19}20}2122main()23.catch((err) => {24console.error("Erreur non gérée :", err);25process.exit(1);26});
Vous n'avez pas encore de compte ?
Créez votre endpoint Quicknode en quelques secondes et commencez à développer
Commencez gratuitement