Geyser SDK is a Go client library for interacting with the Geyser API. It provides both gRPC and WebSocket clients to connect to Geyser nodes and subscribe to Solana blockchain events such as transactions, accounts, slots, blocks, and more.
- gRPC Client: Connect to Geyser nodes using gRPC and subscribe to various Solana blockchain events.
- Enhanced WebSocket Client: Use Geyser Enhanced WebSocket connections to subscribe to events in real-time.
- Event Subscriptions: Subscribe to transactions, accounts, slots, blocks, block metadata, and entries.
- Data Conversion: Convert Geyser transaction and block data into Solana Go SDK types.
- Automated Protobuf Generation: Use Docker to automate the generation of Go code from protobuf definitions.
To use the Geyser SDK in your Go project, add it to your module dependencies:
go get github.com/Prophet-Solutions/geyser-sdk
Ensure you have Go version 1.20 or higher installed.
Create a new gRPC client by specifying the context, gRPC server URL, and optional compression and metadata. The client allows you to interact with the Geyser node using gRPC calls.
Use the client to create a stream and subscribe to various events like accounts, transactions, slots, blocks, and more. You can manage subscriptions by adding, modifying, or removing them as needed.
Set up channels to receive updates and errors from the stream. Implement your logic to process incoming data and handle any errors that occur during the streaming process.
Always close the client when it's no longer needed to gracefully terminate the connection and free up resources.
Instantiate the Enhanced WebSocket client with the Geyser node's WebSocket endpoint (tested with Helius). Establish the connection to start interacting with the node in real-time.
Subscribe to transactions and account updates by specifying filters and options. The client supports various subscription methods to cater to your application's needs.
Listen to the channels provided by the subscriptions to receive real-time updates. Process the data according to your application's requirements.
Close the Enhanced WebSocket client to terminate the connection and ensure that all resources are properly released.
The Geyser SDK uses protobuf definitions from the yellowstone-grpc project. A Docker setup is provided to automate the generation of Go code from the protobuf files.
-
Build the Docker Image
Build the Docker image using the provided
Dockerfile
.docker build -t geyser-sdk-protoc .
-
Run the Protobuf Generation
Run the Docker container to generate the protobuf code.
docker run --rm -v $(pwd)/pb:/app/pb geyser-sdk-protoc
This command mounts the local
pb
directory to the container and outputs the generated Go files there.
-
Dockerfile
Sets up the Docker environment with Go and the necessary tools to generate protobuf files.
-
generate.sh
A script that pulls the latest protobuf definitions and generates the Go code.
Contributions are welcome! Please open an issue or submit a pull request on GitHub to contribute to the project.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.