sui icon indicating copy to clipboard operation
sui copied to clipboard

is there a gRPC for streaming transactions or events

Open hoangong opened this issue 6 months ago • 7 comments

I am looking for a method to streaming events? As I see that gRPC specs does not define such services. Is there an alternative way or sample code to do that? Also, websocket does not work as a few people reported here, so I can't use websocket method.

hoangong avatar Jun 04 '25 11:06 hoangong

Thank you for opening this issue, a team member will review it shortly. Until then, please do not interact with any users that claim to be from Sui support and do not click on any links!

github-actions[bot] avatar Jun 04 '25 11:06 github-actions[bot]

We don't have such a service yet; it is planned but there's no ETA yet cc @bmwill & @abhinavg6.

Alternatively, you could try one of the community projects:

  • https://github.com/fluxus-labs/fluxus-source-sui
  • https://github.com/lispking/fluxus

stefan-mysten avatar Jun 04 '25 17:06 stefan-mysten

@stefan-mysten thanks for clarify. But I think the above libraries are not exactly what I am looking for because they are still polling at low level implementation

hoangong avatar Jun 04 '25 17:06 hoangong

Yes exactly, those libraries are also based on polling APIs under the hood - those are just abstracting the details and exposing streams in a nice way. As @stefan-mysten indicated, we'll have streaming subscription with gRPC beta soon, hopefully next month. We'll share in the relevant forums and channels.

abhinavg6 avatar Jun 04 '25 17:06 abhinavg6

@hoangong we do have a subscription gRPC api that you can play with, its defined here. You'll note that as of right now we only have a way to subscribe at the checkpoint granularity and there is no server-side filtering. You can provide a FieldMask to limit the fields returned to be just the events for each transaction, although it'll return all events so you'll still need to do client side filtering of events for the events you're interested in.

bmwill avatar Jun 04 '25 17:06 bmwill

I have a problem. It seems the stream disconnect after 30 seconds with this error "status: Internal, message: "h2 protocol error: error reading a body from connection", details: [], metadata: MetadataMap { headers: {} }". This is my rust code

let tls = ClientTlsConfig::new()
        .with_webpki_roots()
        .assume_http2(true);

    let endpoint = "https://fullnode.mainnet.sui.io:443";
    let channel = Channel::from_static(endpoint)
        .tls_config(tls)?
        .keep_alive_timeout(Duration::from_secs(5))
        .keep_alive_while_idle(true)
        .http2_keep_alive_interval(Duration::from_secs(10))
        .connect()
        .await?;

    let mut client = SubscriptionServiceClient::new(channel);
    let mut stream = client
        .subscribe_checkpoints(SubscribeCheckpointsRequest {
            read_mask: Some(FieldMask {
                paths: vec!["transactions.events".to_string()],
            }),
        })
        .await?
        .into_inner();
    while let Some(item) = stream.next().await {...}

is there a limitation of public node?

hoangong avatar Jun 07 '25 17:06 hoangong

Public rpc has an explicit 30s timeout given it's not intended to be used in production

bmwill avatar Jun 07 '25 21:06 bmwill

@bmwill Does your last comment mean that when gRPC is in production (post beta) that all subscriptions will timeout after 30s or is this temporary? Thanks

FrankC01 avatar Jun 26 '25 20:06 FrankC01

Public rpc is still planned to have 30s timeout. That's not baked into the service though so if you ran your own node or used a provider the expectation there would be different.

bmwill avatar Jun 26 '25 20:06 bmwill

Good to know so I can document for users... thanks.

FrankC01 avatar Jun 27 '25 08:06 FrankC01