getSlot gRPC Method - Solana gRPC
Solana gRPC is included with Scale plans and up. Learn more on our pricing page.
參數
commitment
字串
載入中...
PROCESSED
字串
載入中...
CONFIRMED
字串
載入中...
FINALIZED
字串
載入中...
退貨
slot
字串
載入中...
請求
1套件 主函式23匯入 (4"上下文"5"crypto/tls"6"fmt"7"log"8「時間」910pb "yellowstone/proto"111213"google.golang.grpc"14"google.golang.grpc"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:443 {443 is the port number for gRPC}22// token will be : abcde1234567892324var (25endpoint = "YOUR_QN_ENDPOINT:443"26token = "YOUR_TOKEN_NUMBER"27)2829var kacp = keepalive.ClientParameters{30Time: 10 * time.Second,31Timeout: time.Second,32PermitWithoutStream: true,33}3435type tokenAuth struct {36代幣 字串37}3839func (t tokenAuth) GetRequestMetadata(ctx context.Context, in ...string) (map[string]string, error) {40返回 地圖[字串]字串{41"x-token": t.token,42}, nil43}4445func (tokenAuth) RequireTransportSecurity() bool {46return true47}4849func main() {50opts := []grpc.DialOption{51grpc.WithTransportCredentials(憑證.NewTLS(&tls.Config{})),52grpc.WithKeepaliveParams(kacp),53grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(1024*1024*1024), grpc.UseCompressor(gzip.Name)),54grpc.WithPerRPCCredentials(tokenAuth{token: token}),55}5657conn, err := grpc.NewClient(endpoint, opts...)58如果 err != nil {59log.Fatalf("Failed to connect: %v", err)60}61延後 延遲連接.關閉()6263client := pb.NewGeyserClient(conn)6465ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)66defer cancel()6768getSlot, err := client.GetSlot(ctx, &pb.GetSlotRequest{})69如果 err != nil {70log.Fatalf("Failed to get slot: %v", err)71}72fmt.Printf(" Get Slot: %+v\n", getSlot)7374}75
1套件 主函式23匯入 (4"上下文"5"crypto/tls"6"fmt"7"log"8「時間」910pb "yellowstone/proto"111213"google.golang.grpc"14"google.golang.grpc"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:443 {443 is the port number for gRPC}22// token will be : abcde1234567892324var (25endpoint = "YOUR_QN_ENDPOINT:443"26token = "YOUR_TOKEN_NUMBER"27)2829var kacp = keepalive.ClientParameters{30Time: 10 * time.Second,31Timeout: time.Second,32PermitWithoutStream: true,33}3435type tokenAuth struct {36代幣 字串37}3839func (t tokenAuth) GetRequestMetadata(ctx context.Context, in ...string) (map[string]string, error) {40返回 地圖[字串]字串{41"x-token": t.token,42}, nil43}4445func (tokenAuth) RequireTransportSecurity() bool {46return true47}4849func main() {50opts := []grpc.DialOption{51grpc.WithTransportCredentials(憑證.NewTLS(&tls.Config{})),52grpc.WithKeepaliveParams(kacp),53grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(1024*1024*1024), grpc.UseCompressor(gzip.Name)),54grpc.WithPerRPCCredentials(tokenAuth{token: token}),55}5657conn, err := grpc.NewClient(endpoint, opts...)58如果 err != nil {59log.Fatalf("Failed to connect: %v", err)60}61延後 延遲連接.關閉()6263client := pb.NewGeyserClient(conn)6465ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)66defer cancel()6768getSlot, err := client.GetSlot(ctx, &pb.GetSlotRequest{})69如果 err != nil {70log.Fatalf("Failed to get slot: %v", err)71}72fmt.Printf(" Get Slot: %+v\n", getSlot)7374}75
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: https://docs-demo.solana-mainnet.quiknode.pro:443 {443 is the port number for gRPC}6// token will be : abcde12345678978const ENDPOINT = "https://YOUR_QN_ENDPOINT:443";9const TOKEN = "YOUR_TOKEN_NUMBER";1011async 函式 main() {12const client = new Client(ENDPOINT, TOKEN, {13grpcDefaultCompressionAlgorithm: 0, // 0 = gzip, 1 = zstd14});15await client.connect();1617const commitment = CommitmentLevel.CONFIRMED;1819try {20const slot = await client.getSlot(commitment);21console.log(`Slot Number: ${JSON.stringify(slot, null, 2)}`);2223} catch (error) {24console.error("Error fetching current slot:", error);25}26}2728main()29.catch((err) => {30console.error("Unhandled error:", err);31process.exit(1);32});33
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: https://docs-demo.solana-mainnet.quiknode.pro:443 {443 is the port number for gRPC}6// token will be : abcde12345678978const ENDPOINT = "https://YOUR_QN_ENDPOINT:443";9const TOKEN = "YOUR_TOKEN_NUMBER";1011async 函式 main() {12const client = new Client(ENDPOINT, TOKEN, {13grpcDefaultCompressionAlgorithm: 0, // 0 = gzip, 1 = zstd14});15await client.connect();1617const commitment = CommitmentLevel.CONFIRMED;1819try {20const slot = await client.getSlot(commitment);21console.log(`Slot Number: ${JSON.stringify(slot, null, 2)}`);2223} catch (error) {24console.error("Error fetching current slot:", error);25}26}2728main()29.catch((err) => {30console.error("Unhandled error:", err);31process.exit(1);32});33