getSlot 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
slot
string
The current slot number on the Solana blockchain
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() getSlot, err := client.GetSlot(ctx, &pb.GetSlotRequest{}) if err != nil { log.Fatalf("Failed to get slot: %v", err) } fmt.Printf(" Get Slot: %+v\n", getSlot) }
import Client, { CommitmentLevel } 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, {}); const commitment = CommitmentLevel.CONFIRMED; try { const slot = await client.getSlot(commitment); console.log(`Slot Number: ${JSON.stringify(slot, null, 2)}`); } catch (error) { console.error("Error fetching current slot:", 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