Skip to main content

subscribeRaw

Subscribe to a topic without decoding the data.

This function creates a raw subscription to Flow blockchain data streams without automatic decoding. It's useful when you need more control over data processing or want to handle raw responses directly. For most use cases, consider using the subscribe() function instead which provides automatic decoding.

Available topics include: events, blocks, block_headers, block_digests, transaction_statuses, account_statuses.

Import

You can import the entire package and access the function:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.subscribeRaw(options, opts)

Or import directly the specific function:


_10
import { subscribeRaw } from "@onflow/sdk"
_10
_10
subscribeRaw(options, opts)

Usage


_34
import * as fcl from "@onflow/fcl";
_34
import { SubscriptionTopic } from "@onflow/sdk";
_34
_34
// Subscribe to raw event data without automatic decoding
_34
const rawSubscription = fcl.subscribeRaw({
_34
topic: SubscriptionTopic.EVENTS,
_34
args: {
_34
eventTypes: ["A.7e60df042a9c0868.FlowToken.TokensWithdrawn"]
_34
},
_34
onData: (rawData) => {
_34
console.log("Raw event data:", rawData);
_34
// Handle raw data manually - no automatic decoding
_34
},
_34
onError: (error) => {
_34
console.error("Raw subscription error:", error);
_34
}
_34
});
_34
_34
// Subscribe to raw block data
_34
const blockSubscription = fcl.subscribeRaw({
_34
topic: SubscriptionTopic.BLOCKS,
_34
args: {
_34
blockStatus: "finalized"
_34
},
_34
onData: (rawBlock) => {
_34
console.log("Raw block data:", rawBlock);
_34
},
_34
onError: (error) => {
_34
console.error("Error:", error);
_34
}
_34
});
_34
_34
// Unsubscribe when done
_34
rawSubscription.unsubscribe();

Parameters

options

  • Type: SubscribeRawParams

_10
export type SubscribeRawParams<T extends SubscriptionTopic> = {
_10
topic: T
_10
args: SubscriptionArgs<T>
_10
onData: (data: RawSubscriptionData<T>) => void
_10
onError: (error: Error) => void
_10
}

opts (optional)

  • Type: SdkTransport;
  • Description: Additional options for the subscription

Returns

object


Rate this page