Skip to content

weeaa/goyser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

25 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Geyser Yellowstone SDK

GoDoc Go Report Card License

This library contains tooling to interact with Yellowstone Geyser Plugin. Work in progress. ๐Ÿ‘ท

yellowstone

โ‡๏ธ Contents

๐Ÿ“ก Methods

  • SubscribeAccounts
    • AppendAccounts
    • UnsubscribeAccounts
    • UnsubscribeAccountsByID
    • UnsubscribeAllAccounts
  • SubscribeSlots
    • UnsubscribeSlots
  • SubscribeTransaction
    • UnsubscribeTransaction
  • SubscribeTransactionStatus
    • UnsubscribeTransactionStatus
  • SubscribeBlocks
    • UnsubscribeBlocks
  • SubscribeBlocksMeta
    • UnsubscribeBlocksMeta
  • SubscribeEntry
    • UnsubscribeEntry
  • SubscribeAccountDataSlice
    • UnsubscribeAccountDataSlice

It also contains a feature to convert Goyser types to github.com/gagliardetto/solana-go types :)

๐Ÿ’พ Installing

Go 1.22.0 or higher.

go get github.com/weeaa/goyser@latest

๐Ÿ’ป Examples

Subscribe to Account

Simple example on how to monitor an account for transactions with explanations.

package main

import (
  "context"
  "github.com/weeaa/goyser"
  "github.com/weeaa/goyser/pb"
  "log"
  "os"
  "time"
)

func main() {
  ctx := context.Background()

  // get the geyser rpc address
  geyserRPC := os.Getenv("GEYSER_RPC")

  // create geyser client
  client, err := goyser.New(ctx, geyserRPC, nil)
  if err != nil {
    log.Fatal(err)
  }

  // create a new subscribe client which is tied, for our example we will name it main
  // the created client is stored in client.Streams
  if err = client.NewSubscribeClient(ctx, "main"); err != nil {
    log.Fatal(err)
  }

  // get the stream client
  streamClient, ok := client.Streams["main"]
  if !ok {
    log.Fatal("client does not have a stream named main")
  }

  // subscribe to the account you want to see txns from and set a custom filter name to filter them out later
  if err = streamClient.SubscribeAccounts("accounts", &geyser_pb.SubscribeRequestFilterAccounts{
    Account: []string{"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"},
  }); err != nil {
    log.Fatal(err)
  }

  // loop through the stream and print the output
  for out := range streamClient.Ch {
    // u can filter the output by checking the filters
    go func() {
      filters := out.GetFilters()
      for _, filter := range filters {
        switch filter {
        case "accounts":
          log.Printf("account filter: %+v", out.GetAccount())
        default:
          log.Printf("unknown filter: %s", filter)
        }
      }
    }()
    break
  }

  // unsubscribe from the account
  if err = streamClient.UnsubscribeAccounts("accounts", ""); err != nil {
    log.Fatal(err)
  }

  time.Sleep(5 * time.Second)
}

๐Ÿ›Ÿ Support

If my work has been useful in building your for-profit services/infra/bots/etc, consider donating at EcrHvqa5Vh4NhR3bitRZVrdcUGr1Z3o6bXHz7xgBU2FB (SOL).

๐Ÿ“ƒ License

Apache-2.0 License.