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:
_10import * as sdk from "@onflow/sdk"_10_10sdk.subscribeRaw(subscribeRawParams, opts)
Or import directly the specific function:
_10import { subscribeRaw } from "@onflow/sdk"_10_10subscribeRaw(subscribeRawParams, opts)
Usage
_34import * as fcl from "@onflow/fcl";_34import { SubscriptionTopic } from "@onflow/sdk";_34_34// Subscribe to raw event data without automatic decoding_34const 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_34const 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_34rawSubscription.unsubscribe();
Parameters
subscribeRawParams
- Type: SubscribeRawParams<T>
Properties:
- topic- Type:- T- The topic to subscribe to.
- args- Type:- SubscriptionArgs<T>- The arguments for the subscription.
- onData- Type:- (data: RawSubscriptionData<T>) => void- The callback to call when data is received.
- onError- Type:- (error: Error) => void- The callback to call when a fatal error occurs.
opts (optional)
- Type:
_10{_10  node?: string;_10  transport?: SdkTransport;_10}
- Description: Additional options for the subscription
Properties:
- node- Custom node endpoint to be used for the subscription
- transport- Custom transport implementation for handling the connection
Returns
_10{_10  unsubscribe: () => void;_10}
A subscription object with an unsubscribe method