Método gRPC «getLatestBlockhash» - Solana gRPC
Solana gRPC está incluido en los planes Scale y Business. En los planes Build y Accelerate, sigue estando disponible a través del complemento Solana gRPC.
Parámetros
Este método no admite ningún parámetro
Devoluciones
ranura
cadena
Cargando...
blockhash
cadena
Cargando...
última altura de bloque válida
cadena
Cargando...
Solicitud
1paquete principal23import (4«contexto»5«crypto/tls»6«fmt»7«registro»8«tiempo»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 (25punto final = "TU_QN_ENDPOINT:10000"26token = "TU_NÚMERO_DE_TOKEN"27)2829func main() {30opts := []grpc.DialOption{31grpc.WithTransportCredentials(credenciales.NewTLS(&tls.Config{})),32grpc.WithKeepaliveParams(kacp),33grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(1024*1024*1024), grpc.UseCompressor(gzip.Nombre)),34grpc.WithPerRPCCredentials(tokenAuth{token: token}),35}3637conn, err := grpc.NewClient(punto de conexión, opts...)38si err != nil {39registro.Fatalf(«Error al conectarse: %v», err)40}41aplazar conn.Cerrar()4243cliente := pb.NewGeyserClient(conn)4445ctx, cancel := contexto.WithTimeout(contexto.Background(), 10*vez.Segundo)46aplazar cancelar()4748latestBlockHash, err := client.GetLatestBlockhash(ctx, &pb.GetLatestBlockhashRequest{})49si err != nil {50registro.Fatalf(«No se ha podido obtener el último hash de bloque: %v», err)51}5253fmt.Printf("Última información sobre el hash del bloque:\n")54fmt.Printf(" Blockhash: %+v\n", últimoHashDelBloque)5556}
1paquete principal23import (4«contexto»5«crypto/tls»6«fmt»7«registro»8«tiempo»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 (25punto final = "TU_QN_ENDPOINT:10000"26token = "TU_NÚMERO_DE_TOKEN"27)2829func main() {30opts := []grpc.DialOption{31grpc.WithTransportCredentials(credenciales.NewTLS(&tls.Config{})),32grpc.WithKeepaliveParams(kacp),33grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(1024*1024*1024), grpc.UseCompressor(gzip.Nombre)),34grpc.WithPerRPCCredentials(tokenAuth{token: token}),35}3637conn, err := grpc.NewClient(punto de conexión, opts...)38si err != nil {39registro.Fatalf(«Error al conectarse: %v», err)40}41aplazar conn.Cerrar()4243cliente := pb.NewGeyserClient(conn)4445ctx, cancel := contexto.WithTimeout(contexto.Background(), 10*vez.Segundo)46aplazar cancelar()4748latestBlockHash, err := client.GetLatestBlockhash(ctx, &pb.GetLatestBlockhashRequest{})49si err != nil {50registro.Fatalf(«No se ha podido obtener el último hash de bloque: %v», err)51}5253fmt.Printf("Última información sobre el hash del bloque:\n")54fmt.Printf(" Blockhash: %+v\n", últimoHashDelBloque)5556}
1import Client, { CommitmentLevel } 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 PUNTO FINAL = "TU_QN_ENDPOINT:10000";9const TOKEN = "TU_NÚMERO_DE_TOKEN";1011asíncrono función main() {12const client = new Client(ENDPOINT, TOKEN, {});1314const compromiso = NivelDeCompromiso.CONFIRMADO;1516prueba {17const respuesta = await cliente.getLatestBlockhash(compromiso);18console.log(`Latest Blockhash: ${JSON.stringify(response, null, 2)}`);19} catch (error) {20consola.error(«Error al recuperar el último hash de bloque:», error);21}22}2324principal()25.captura((err) => {26consola.error(«Error no gestionado:», err);27proceso.salir(1);28});
1import Client, { CommitmentLevel } 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 PUNTO FINAL = "TU_QN_ENDPOINT:10000";9const TOKEN = "TU_NÚMERO_DE_TOKEN";1011asíncrono función main() {12const client = new Client(ENDPOINT, TOKEN, {});1314const compromiso = NivelDeCompromiso.CONFIRMADO;1516prueba {17const respuesta = await cliente.getLatestBlockhash(compromiso);18console.log(`Latest Blockhash: ${JSON.stringify(response, null, 2)}`);19} catch (error) {20consola.error(«Error al recuperar el último hash de bloque:», error);21}22}2324principal()25.captura((err) => {26consola.error(«Error no gestionado:», err);27proceso.salir(1);28});
¿Aún no tienes una cuenta?
Crea tu punto de conexión de Quicknode en cuestión de segundos y empieza a desarrollar
Empieza gratis