Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BlockSubscribe no data output. #196

Open
kenneyLee opened this issue Apr 18, 2024 · 1 comment
Open

BlockSubscribe no data output. #196

kenneyLee opened this issue Apr 18, 2024 · 1 comment

Comments

@kenneyLee
Copy link

I used BlockSubscribe, but found that there was no data output.But with the same endpoint, LogsSubscribe is running normally.
`package main

import (
"context"
"fmt"
"math"
"sync"

bin "github.com/gagliardetto/binary"
"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/programs/serum"
"github.com/gagliardetto/solana-go/rpc"

"github.com/gagliardetto/solana-go/programs/token"
"github.com/gagliardetto/solana-go/rpc/ws"

)

func main() {
client, err := ws.Connect(context.Background(), rpc.MainNetBeta_WS)

if err != nil {
	panic(err)
}

filter := ws.NewBlockSubscribeFilterAll()
opts := &ws.BlockSubscribeOpts{
	Commitment: rpc.CommitmentConfirmed,
}

sub, err := client.BlockSubscribe(filter, opts)
if err != nil {

	panic(err)
}
defer sub.Unsubscribe()

for {
	res, err := sub.Recv()
	if err != nil {
		fmt.Println("BlockSubscribe error:", err)
		panic(err)
	}

	fmt.Println("Received block:", res.Value.Block)

	for _, transaction := range res.Value.Block.Transactions {
		fmt.Println("Transaction:", transaction)
	}
}

}`

@gagliardetto
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants