Skip to main content

isBlockhashValid gRPC Method

Checks whether a given blockhash is still valid on the Solana blockchain.

Updated on
Oct 25, 2024

isBlockhashValid gRPC Method

Please note that this RPC method requires the Yellowstone gRPC add-on enabled on your QuickNode endpoint.

Parameters

blockhash
bytes
REQUIRED
The blockhash you want to validate

Returns

valid
boolean
A boolean value (true or false) indicating whether the blockhash is still valid
slot
string
The slot number associated with the blockhash
Request
1
package main
2
3
import (
4
"context"
5
"crypto/tls"
6
"fmt"
7
"log"
8
"time"
9
10
pb "yellowstone/proto"
11
12
13
"google.golang.org/grpc"
14
"google.golang.org/grpc/credentials"
15
"google.golang.org/grpc/encoding/gzip"
16
"google.golang.org/grpc/keepalive"
17
)
18
19
// QuickNode endpoints consist of two crucial components: the endpoint name and the corresponding token
20
// For eg: QN Endpoint: https://docs-demo.solana-mainnet.quiknode.pro/abcde123456789
21
// endpoint will be: docs-demo.solana-mainnet.quiknode.pro:10000 {10000 is the port number for gRPC}
22
// token will be : abcde123456789
23
24
var (
25
endpoint = "YOUR_QN_ENDPOINT:10000"
26
token = "YOUR_TOKEN_NUMBER"
27
)
28
29
func main() {
30
opts := []grpc.DialOption{
31
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
32
grpc.WithKeepaliveParams(kacp),
33
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(1024*1024*1024), grpc.UseCompressor(gzip.Name)),
34
grpc.WithPerRPCCredentials(tokenAuth{token: token}),
35
}
36
37
conn, err := grpc.NewClient(endpoint, opts...)
38
if err != null {
39
log.Fatalf("Failed to connect: %v", err)
40
}
41
defer conn.Close()
42
43
client := pb.NewGeyserClient(conn)
44
45
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
46
defer cancel()
47
48
const BLOCKHASH_TO_CHECK = "FJcV9hJycVRkyHWf3P8qjxE2vLs6dF38RTZzZBNvNM1z"
49
50
isBlockhashValid, err := client.IsBlockhashValid(ctx, &pb.IsBlockhashValidRequest{
51
Blockhash: BLOCKHASH_TO_CHECK,
52
})
53
if err != null {
54
log.Fatalf("Failed to check blockhash validity: %v", err)
55
}
56
57
58
fmt.Printf("Slot: %d\n", isBlockhashValid.Slot)
59
fmt.Printf("Valid: %v\n", isBlockhashValid.Valid)
60
61
62
}
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free