Quickstart
Get connected to ThorPulse and receiving Solana data in 5 minutes.
1
3
Connect and Subscribe
Create a file main.go:
package main
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/thorlabsDev/thorpulse-go"
)
func main() {
// Connect using credentials file
cfg := client.ConfigWithCredsFile(
"nats://ny-rpc.thornode.io:4223",
"thorpulse.creds",
)
// Add connection callbacks (optional)
cfg.OnDisconnect = func(err error) {
log.Printf("Disconnected: %v", err)
}
cfg.OnReconnect = func() {
log.Println("Reconnected!")
}
// Connect
c, err := client.Connect(cfg)
if err != nil {
log.Fatal("Connection failed:", err)
}
defer c.Close()
fmt.Println("Connected to ThorPulse!")
// Subscribe to slot updates
err = c.SubscribeSlots(func(slot *client.SlotUpdate) {
fmt.Printf("Slot %d: %s\n", slot.Slot, slot.Status)
})
if err != nil {
log.Fatal("Subscribe failed:", err)
}
fmt.Println("Subscribed to slots. Press Ctrl+C to exit.")
// Wait for interrupt signal
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
<-sig
fmt.Println("Shutting down...")
}4
5
Try Other Subscriptions
Subscribe to Transactions
// All transactions for a program
err = c.SubscribeProgram("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
func(tx *client.TransactionUpdate) {
fmt.Printf("TX: %x (slot %d)\n", tx.Signature[:8], tx.Slot)
})
// Transactions involving a specific account
err = c.SubscribeAccount("So11111111111111111111111111111111111111112",
func(tx *client.TransactionUpdate) {
fmt.Printf("SOL TX: %x\n", tx.Signature[:8])
})Subscribe to Account Updates
err = c.SubscribeAccounts(func(acc *client.AccountUpdate) {
fmt.Printf("Account %x updated: %d lamports\n",
acc.Pubkey[:8], acc.Lamports)
})Use Channel-Based API
import "context"
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
slots, err := c.SlotChan(ctx, 100)
if err != nil {
log.Fatal(err)
}
for slot := range slots {
fmt.Printf("Slot %d\n", slot.Slot)
}Next Steps
Authentication Guide - Understand JWT credentials
Topic Reference - Complete topic schema
Subscription Reference - Subscription patterns and filters
Troubleshooting
Last updated