package main
import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
"log"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
txtypes "celestia-grpc/celestia/core/v1/tx"
)
// QuickNode endpoints consist of two crucial components: the endpoint name and the corresponding token
// For eg: QN Endpoint: https://docs-demo.celestia-mainnet.quiknode.pro/abcde123456789
// endpoint will be: docs-demo.celestia-mainnet.quiknode.pro:9090 {9090 is the port number for Celestia gRPC}
// token will be : abcde123456789
var token = "YOUR_TOKEN"
var endpoint = "YOUR_ENDPOINT:9090"
type auth struct {
token string
}
func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
return map[string]string{
"x-token": a.token,
}, nil
}
func (a *auth) RequireTransportSecurity() bool {
return false
}
func main() {
opts := []grpc.DialOption{
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
grpc.WithPerRPCCredentials(&auth{token}),
}
// Create gRPC connection
conn, err := grpc.Dial(endpoint, opts...)
if err != nil {
log.Fatalf("Failed to connect to Celestia gRPC server: %v", err)
}
defer conn.Close()
client := txtypes.NewTxClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Example transaction hash (64 characters hex string)
// Replace with an actual transaction hash
txHash := "3ae0d131ce0e50de8fedf4041ae2ca4bc7be0d208cd7e39baad526ac3794fe09"
resp, err := client.TxStatus(ctx, &txtypes.TxStatusRequest{
TxId: txHash,
})
if err != nil {
log.Fatalf("Failed to query transaction status: %v", err)
}
jsonData, err := json.MarshalIndent(resp, "", " ")
if err != nil {
log.Printf("Error converting to JSON: %v", err)
} else {
fmt.Println("\nOutput:")
fmt.Println(string(jsonData))
}
}