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(options, opts)
Or import directly the specific function:
_10import { subscribeRaw } from "@onflow/sdk"_10_10subscribeRaw(options, 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
options
- Type:
SubscribeRawParams
_10export 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