Hooks
Many of these hooks are built using @tanstack/react-query, which provides powerful caching, revalidation, and background refetching features. As a result, you'll see return types like UseQueryResult and UseMutationResult throughout this section. Other types—such as Account, Block, and CurrentUser—are from the Flow Client Library (FCL) TypeDefs. Refer to their respective documentation for full type definitions and usage patterns.
Cadence Hooks
useFlowCurrentUser
_10import { useFlowCurrentUser } from "@onflow/react-native-sdk"
Parameters
flowClient?: FlowClient- OptionalFlowClientinstance
Returns:
user: CurrentUser– The current user object from FCLauthenticate: () => Promise<CurrentUser>– Triggers wallet authenticationunauthenticate: () => void– Logs the user out
_22import { View, Text, TouchableOpacity } from 'react-native';_22_22function AuthComponent() {_22 const { user, authenticate, unauthenticate } = useFlowCurrentUser()_22_22 return (_22 <View>_22 {user?.loggedIn ? (_22 <View>_22 <Text>Logged in as {user?.addr}</Text>_22 <TouchableOpacity onPress={unauthenticate}>_22 <Text>Logout</Text>_22 </TouchableOpacity>_22 </View>_22 ) : (_22 <TouchableOpacity onPress={authenticate}>_22 <Text>Login</Text>_22 </TouchableOpacity>_22 )}_22 </View>_22 )_22}
useFlowAccount
_10import { useFlowAccount } from "@onflow/react-native-sdk"
Parameters:
address?: string– Flow address (with or without0xprefix)query?: UseQueryOptions<Account | null, Error>– Optional TanStackQuery optionsflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseQueryResult<Account | null, Error>
_22import { View, Text, TouchableOpacity } from 'react-native';_22_22function AccountDetails() {_22 const { data: account, isLoading, error, refetch } = useFlowAccount({_22 address: "0x1cf0e2f2f715450",_22 query: { staleTime: 5000 },_22 })_22_22 if (isLoading) return <Text>Loading account...</Text>_22 if (error) return <Text>Error fetching account: {error.message}</Text>_22 if (!account) return <Text>No account data</Text>_22_22 return (_22 <View>_22 <Text>Account: {account.address}</Text>_22 <Text>Balance: {account.balance}</Text>_22 <TouchableOpacity onPress={() => refetch()}>_22 <Text>Refetch</Text>_22 </TouchableOpacity>_22 </View>_22 )_22}
useFlowBlock
_10import { useFlowBlock } from "@onflow/react-native-sdk"
Parameters:
sealed?: boolean– Iftrue, fetch latest sealed blockid?: string– Block by IDheight?: number– Block by heightquery?: UseQueryOptions<Block | null, Error>– Optional TanStackQuery optionsflowClient?: FlowClient- OptionalFlowClientinstance
Only one of sealed, id, or height should be provided.
Returns: UseQueryResult<Block | null, Error>
_16import { View, Text } from 'react-native';_16_16function LatestBlock() {_16 const { data: block, isLoading, error } = useFlowBlock({ query: { staleTime: 10000 } })_16_16 if (isLoading) return <Text>Loading...</Text>_16 if (error) return <Text>Error: {error.message}</Text>_16 if (!block) return <Text>No block data.</Text>_16_16 return (_16 <View>_16 <Text>Block {block.height}</Text>_16 <Text>ID: {block.id}</Text>_16 </View>_16 )_16}
useFlowChainId
_10import { useFlowChainId } from "@onflow/react-native-sdk"
This hook retrieves the Flow chain ID, which is useful for identifying the current network.
Parameters:
query?: Omit<UseQueryOptions<string | null>, "queryKey" | "queryFn">– Optional TanStack Query options likestaleTime,enabled, etc.flowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseQueryResult<string | null, Error>
Valid chain IDs include: testnet (Flow Testnet), mainnet (Flow Mainnet), and emulator (Flow Emulator). The flow- prefix will be stripped from the chain ID returned by the access node (e.g. flow-testnet will return testnet).
_12import { View, Text } from 'react-native';_12_12function ChainIdExample() {_12 const { data: chainId, isLoading, error } = useFlowChainId({_12 query: { staleTime: 10000 },_12 })_12_12 if (isLoading) return <Text>Loading chain ID...</Text>_12 if (error) return <Text>Error fetching chain ID: {error.message}</Text>_12_12 return <Text>Current Flow Chain ID: {chainId}</Text>_12}
useFlowClient
This hook returns the FlowClient for the current <FlowProvider /> context.
Parameters:
flowClient?: FlowClient- OptionalFlowClientinstance to override the result
useFlowConfig
_10import { useFlowConfig } from "@onflow/react-native-sdk"
Returns: FlowConfig
_12import { View, Text } from 'react-native';_12_12function MyComponent() {_12 const config = useFlowConfig()_12_12 return (_12 <View>_12 <Text>Current network: {config.flowNetwork}</Text>_12 <Text>Current access node: {config.accessNodeUrl}</Text>_12 </View>_12 )_12}
useFlowEvents
_10import { useFlowEvents } from "@onflow/react-native-sdk"
Parameters:
startBlockId?: string– Optional ID of the block to start listening fromstartHeight?: number– Optional block height to start listening fromeventTypes?: string[]– Array of event type strings (e.g.,A.0xDeaDBeef.Contract.EventName)addresses?: string[]– Filter by Flow addressescontracts?: string[]– Filter by contract identifiersopts?: { heartbeatInterval?: number }– Options for subscription heartbeatonEvent: (event: Event) => void– Callback for each event receivedonError?: (error: Error) => void– Optional error handlerflowClient?: FlowClient- OptionalFlowClientinstance
Example:
_11import { View, Text } from 'react-native';_11_11function EventListener() {_11 useFlowEvents({_11 eventTypes: ["A.0xDeaDBeef.SomeContract.SomeEvent"],_11 onEvent: (event) => console.log("New event:", event),_11 onError: (error) => console.error("Error:", error),_11 })_11_11 return <Text>Listening for events...</Text>_11}
useFlowQuery
_10import { useFlowQuery } from "@onflow/react-native-sdk"
Parameters:
cadence: string– Cadence script to runargs?: (arg, t) => unknown[]– Function returning FCL argumentsquery?: UseQueryOptions<unknown, Error>– Optional TanStackQuery optionsflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseQueryResult<unknown, Error>
_26import { View, Text, TouchableOpacity } from 'react-native';_26_26function QueryExample() {_26 const { data, isLoading, error, refetch } = useFlowQuery({_26 cadence: `_26 access(all)_26 fun main(a: Int, b: Int): Int {_26 return a + b_26 }_26 `,_26 args: (arg, t) => [arg(1, t.Int), arg(2, t.Int)],_26 query: { staleTime: 10000 },_26 })_26_26 if (isLoading) return <Text>Loading query...</Text>_26 if (error) return <Text>Error: {error.message}</Text>_26_26 return (_26 <View>_26 <Text>Result: {data}</Text>_26 <TouchableOpacity onPress={() => refetch()}>_26 <Text>Refetch</Text>_26 </TouchableOpacity>_26 </View>_26 )_26}
useFlowQueryRaw
_10import { useFlowQueryRaw } from "@onflow/react-native-sdk"
This hook is identical to useFlowQuery but returns the raw, non-decoded response data from the Flow blockchain. This is useful when you need access to the original response structure or want to handle decoding manually.
Parameters:
cadence: string– Cadence script to runargs?: (arg, t) => unknown[]– Function returning FCL argumentsquery?: UseQueryOptions<unknown, Error>– Optional TanStackQuery optionsflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseQueryResult<unknown, Error>
The returned data will be in its raw, non-decoded format as received from the Flow access node.
_26import { View, Text, TouchableOpacity } from 'react-native';_26_26function QueryRawExample() {_26 const { data: rawData, isLoading, error, refetch } = useFlowQueryRaw({_26 cadence: `_26 access(all)_26 fun main(a: Int, b: Int): Int {_26 return a + b_26 }_26 `,_26 args: (arg, t) => [arg(1, t.Int), arg(2, t.Int)],_26 query: { staleTime: 10000 },_26 })_26_26 if (isLoading) return <Text>Loading query...</Text>_26 if (error) return <Text>Error: {error.message}</Text>_26_26 return (_26 <View>_26 <Text>Raw Result: {JSON.stringify(rawData, null, 2)}</Text>_26 <TouchableOpacity onPress={() => refetch()}>_26 <Text>Refetch</Text>_26 </TouchableOpacity>_26 </View>_26 )_26}
useFlowMutate
_10import { useFlowMutate } from "@onflow/react-native-sdk"
Parameters:
mutation?: UseMutationOptions<string, Error, FCLMutateParams>– Optional TanStackQuery mutation optionsflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseMutationResult<string, Error, FCLMutateParams>
_36import { View, Text, TouchableOpacity } from 'react-native';_36import * as fcl from '@onflow/fcl';_36_36function CreatePage() {_36 const { mutate, isPending, error, data: txId } = useFlowMutate({_36 mutation: {_36 onSuccess: (txId) => console.log("TX ID:", txId),_36 },_36 })_36_36 const sendTransaction = () => {_36 mutate({_36 cadence: `transaction() {_36 prepare(acct: &Account) {_36 log(acct.address)_36 }_36 }`,_36 args: (arg, t) => [],_36 proposer: fcl.currentUser,_36 payer: fcl.currentUser,_36 authorizations: [],_36 limit: 100,_36 })_36 }_36_36 return (_36 <View>_36 <TouchableOpacity onPress={sendTransaction} disabled={isPending}>_36 <Text>Send Transaction</Text>_36 </TouchableOpacity>_36 {isPending && <Text>Sending transaction...</Text>}_36 {error && <Text>Error: {error.message}</Text>}_36 {txId && <Text>Transaction ID: {txId}</Text>}_36 </View>_36 )_36}
useFlowRevertibleRandom
_10import { useFlowRevertibleRandom } from "@onflow/react-native-sdk"
Parameters:
min?: string– Minimum random value (inclusive), as a UInt256 decimal string. Defaults to"0".max: string– Maximum random value (inclusive), as a UInt256 decimal string. Required.count?: number– Number of random values to fetch (must be at least 1). Defaults to1.query?: Omit<UseQueryOptions<any, Error>, "queryKey" | "queryFn">– Optional TanStack Query settings likestaleTime,enabled,retry, etc.flowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseQueryResult<RevertibleRandomResult[], Error>
Each RevertibleRandomResult includes:
blockHeight: string— The block height from which the random value was generated.value: string— The random UInt256 value, returned as a decimal string.
_30import { View, Text, TouchableOpacity, FlatList } from 'react-native';_30_30function RandomValues() {_30 const { data: randoms, isLoading, error, refetch } = useFlowRevertibleRandom({_30 min: "0",_30 max: "1000000000000000000000000",_30 count: 3,_30 query: { staleTime: 10000 },_30 })_30_30 if (isLoading) return <Text>Loading random numbers...</Text>_30 if (error) return <Text>Error fetching random numbers: {error.message}</Text>_30 if (!randoms) return <Text>No random values generated.</Text>_30_30 return (_30 <View>_30 <Text>Generated Random Numbers</Text>_30 <FlatList_30 data={randoms}_30 keyExtractor={(_, idx) => idx.toString()}_30 renderItem={({ item }) => (_30 <Text>Block {item.blockHeight}: {item.value}</Text>_30 )}_30 />_30 <TouchableOpacity onPress={() => refetch()}>_30 <Text>Regenerate</Text>_30 </TouchableOpacity>_30 </View>_30 )_30}
Notes:
- Randomness is generated using the onchain
revertibleRandomfunction on Flow, producing pseudorandom values tied to block and script execution. - Values are deterministic: The values returned for identical calls within the same block will be identical.
- If
countis larger than one, the returned values are distinct. - This hook is designed for simple use cases that don't require unpredictability, such as randomized UIs. Since the hook uses script executions on existing blocks, the random source is already public and the randoms are predictable.
- For more advanced use cases that do require onchain randomness logic via transactions, Flow provides built-in support using Cadence's
revertibleRandomand commit-reveal scheme.
useFlowTransaction
_10import { useFlowTransaction } from "@onflow/react-native-sdk"
Fetches a Flow transaction by ID and returns the decoded transaction object.
Parameters:
txId?: string– The Flow transaction ID or scheduled transaction ID to fetch.query?: Omit<UseQueryOptions<Transaction | null, Error>, "queryKey" | "queryFn">– Optional TanStack Query options likestaleTime,enabled, etc.flowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseQueryResult<Transaction | null, Error>
_23import { View, Text, TouchableOpacity } from 'react-native';_23_23function TransactionDetails({ txId }: { txId: string }) {_23 const { data: transaction, isLoading, error, refetch } = useFlowTransaction({_23 txId,_23 query: { staleTime: 10000 },_23 })_23_23 if (isLoading) return <Text>Loading transaction...</Text>_23 if (error) return <Text>Error fetching transaction: {error.message}</Text>_23 if (!transaction) return <Text>No transaction data.</Text>_23_23 return (_23 <View>_23 <Text>Transaction ID: {transaction.id}</Text>_23 <Text>Gas Limit: {transaction.gasLimit}</Text>_23 <Text>Arguments: {JSON.stringify(transaction.arguments, null, 2)}</Text>_23 <TouchableOpacity onPress={() => refetch()}>_23 <Text>Refetch</Text>_23 </TouchableOpacity>_23 </View>_23 )_23}
useFlowTransactionStatus
_10import { useFlowTransactionStatus } from "@onflow/react-native-sdk"
Parameters:
id: string– Transaction ID or scheduled transaction ID to subscribe toflowClient?: FlowClient- OptionalFlowClientinstance
Returns:
transactionStatus: TransactionStatus | nullerror: Error | null
_10import { View, Text } from 'react-native';_10_10function TransactionStatusComponent() {_10 const txId = "your-transaction-id-here"_10 const { transactionStatus, error } = useFlowTransactionStatus({ id: txId })_10_10 if (error) return <Text>Error: {error.message}</Text>_10_10 return <Text>Status: {transactionStatus?.statusString}</Text>_10}
useFlowNftMetadata
_10import { useFlowNftMetadata } from "@onflow/react-native-sdk"
This hook fetches NFT metadata including display information, traits, rarity, and collection details.
Parameters:
accountAddress?: string– Flow address of the account holding the NFTtokenId?: string | number– The NFT token IDpublicPathIdentifier?: string– Public path identifier for the collectionquery?: UseQueryOptions<unknown, Error>– Optional TanStack Query optionsflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseQueryResult<NftViewResult | null, Error>
Where NftViewResult is defined as:
_12interface NftViewResult {_12 name: string_12 description: string_12 thumbnailUrl: string_12 externalUrl?: string_12 collectionName?: string_12 collectionExternalUrl?: string_12 tokenID: string_12 traits?: Record<string, string>_12 rarity?: string_12 serialNumber?: string_12}
_32import { View, Text, Image, FlatList } from 'react-native';_32_32function NftMetadataExample() {_32 const { data: nft, isLoading, error } = useFlowNftMetadata({_32 accountAddress: "0x1cf0e2f2f715450",_32 tokenId: "123",_32 publicPathIdentifier: "exampleNFTCollection",_32 query: { staleTime: 60000 },_32 })_32_32 if (isLoading) return <Text>Loading NFT metadata...</Text>_32 if (error) return <Text>Error: {error.message}</Text>_32 if (!nft) return <Text>NFT not found</Text>_32_32 return (_32 <View>_32 <Text>{nft.name}</Text>_32 <Image source={{ uri: nft.thumbnailUrl }} style={{ width: 200, height: 200 }} />_32 <Text>{nft.description}</Text>_32 {nft.collectionName && <Text>Collection: {nft.collectionName}</Text>}_32 {nft.rarity && <Text>Rarity: {nft.rarity}</Text>}_32 {nft.traits && (_32 <View>_32 <Text>Traits:</Text>_32 {Object.entries(nft.traits).map(([key, value]) => (_32 <Text key={key}>{key}: {value}</Text>_32 ))}_32 </View>_32 )}_32 </View>_32 )_32}
useFlowAuthz
_10import { useFlowAuthz } from "@onflow/react-native-sdk"
A React hook that returns an authorization function for Flow transactions. If no custom authorization is provided, it returns the current user's wallet authorization.
Parameters:
authz?: AuthorizationFunction– Optional custom authorization functionflowClient?: FlowClient- OptionalFlowClientinstance
Where AuthorizationFunction is defined as:
_10type AuthorizationFunction = (_10 account: Partial<InteractionAccount>_10) => Partial<InteractionAccount> | Promise<Partial<InteractionAccount>>
Returns: AuthorizationFunction
The authorization function is compatible with Flow transactions' authorizations parameter.
_28import { View, Text, TouchableOpacity } from 'react-native';_28import * as fcl from '@onflow/fcl';_28_28// Example 1: Using current user authorization_28function CurrentUserAuthExample() {_28 const authorization = useFlowAuthz()_28_28 const sendTransaction = async () => {_28 const txId = await fcl.mutate({_28 cadence: `_28 transaction {_28 prepare(signer: auth(Storage) &Account) {_28 log(signer.address)_28 }_28 }_28 `,_28 authorizations: [authorization],_28 limit: 100,_28 })_28 console.log("Transaction ID:", txId)_28 }_28_28 return (_28 <TouchableOpacity onPress={sendTransaction}>_28 <Text>Send Transaction</Text>_28 </TouchableOpacity>_28 )_28}
_34// Example 2: Using custom authorization function_34function CustomAuthExample() {_34 const customAuthz = (account) => ({_34 ...account,_34 addr: "0xCUSTOMOADDRESS",_34 keyId: 0,_34 signingFunction: async (signable) => ({_34 signature: "0x...",_34 }),_34 })_34_34 const authorization = useFlowAuthz({ authz: customAuthz })_34_34 const sendTransaction = async () => {_34 const txId = await fcl.mutate({_34 cadence: `_34 transaction {_34 prepare(signer: auth(Storage) &Account) {_34 log(signer.address)_34 }_34 }_34 `,_34 authorizations: [authorization],_34 limit: 100,_34 })_34 console.log("Transaction ID:", txId)_34 }_34_34 return (_34 <TouchableOpacity onPress={sendTransaction}>_34 <Text>Send Custom Auth Transaction</Text>_34 </TouchableOpacity>_34 )_34}
useFlowScheduledTransaction
_10import { useFlowScheduledTransaction } from "@onflow/react-native-sdk"
Fetches a scheduled transaction by ID.
Parameters:
txId?: string– Scheduled transaction IDincludeHandlerData?: boolean– Include handler data (default: false)query?: UseQueryOptions<ScheduledTransaction | null, Error>– Optional TanStack Query optionsflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseQueryResult<ScheduledTransaction | null, Error>
Where ScheduledTransaction is defined as:
_15interface ScheduledTransaction {_15 id: string_15 priority: ScheduledTransactionPriority // 0 = Low, 1 = Medium, 2 = High_15 executionEffort: bigint_15 status: ScheduledTransactionStatus // 0 = Pending, 1 = Processing, 2 = Completed, 3 = Failed, 4 = Cancelled_15 fees: {_15 value: bigint_15 formatted: string_15 }_15 scheduledTimestamp: number_15 handlerTypeIdentifier: string_15 handlerAddress: string_15 handlerUUID?: string // Only included if includeHandlerData is true_15 handlerResolvedViews?: {[viewType: string]: any} // Only included if includeHandlerData is true_15}
_22import { View, Text } from 'react-native';_22_22function ScheduledTransactionDetails({ txId }: { txId: string }) {_22 const { data: transaction, isLoading, error } = useFlowScheduledTransaction({_22 txId,_22 query: { staleTime: 10000 },_22 })_22_22 if (isLoading) return <Text>Loading scheduled transaction...</Text>_22 if (error) return <Text>Error: {error.message}</Text>_22 if (!transaction) return <Text>Transaction not found</Text>_22_22 return (_22 <View>_22 <Text>Scheduled Transaction #{transaction.id}</Text>_22 <Text>Status: {transaction.status}</Text>_22 <Text>Priority: {transaction.priority}</Text>_22 <Text>Fees: {transaction.fees.formatted} FLOW</Text>_22 <Text>Handler: {transaction.handlerTypeIdentifier}</Text>_22 </View>_22 )_22}
useFlowScheduledTransactionList
_10import { useFlowScheduledTransactionList } from "@onflow/react-native-sdk"
Lists all scheduled transactions for an account.
Parameters:
account?: string– Flow address to queryincludeHandlerData?: boolean– Include handler data (default: false)query?: UseQueryOptions<ScheduledTransaction[], Error>– Optional TanStack Query optionsflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseQueryResult<ScheduledTransaction[], Error>
_30import { View, Text, TouchableOpacity, FlatList } from 'react-native';_30_30function ScheduledTransactionsList({ account }: { account: string }) {_30 const { data: transactions, isLoading, error, refetch } = useFlowScheduledTransactionList({_30 account,_30 query: { staleTime: 10000 },_30 })_30_30 if (isLoading) return <Text>Loading scheduled transactions...</Text>_30 if (error) return <Text>Error: {error.message}</Text>_30 if (!transactions || transactions.length === 0) return <Text>No scheduled transactions</Text>_30_30 return (_30 <View>_30 <Text>Scheduled Transactions for {account}</Text>_30 <TouchableOpacity onPress={() => refetch()}>_30 <Text>Refresh</Text>_30 </TouchableOpacity>_30 <FlatList_30 data={transactions}_30 keyExtractor={(tx) => tx.id}_30 renderItem={({ item: tx }) => (_30 <Text>_30 Transaction #{tx.id} - Status: {tx.status} - Fees: {tx.fees.formatted} FLOW_30 </Text>_30 )}_30 />_30 </View>_30 )_30}
useFlowScheduledTransactionCancel
_10import { useFlowScheduledTransactionCancel } from "@onflow/react-native-sdk"
Cancels a scheduled transaction and refunds fees.
Parameters:
mutation?: UseMutationOptions<string, Error, string>– Optional TanStack Query mutation optionsflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseFlowScheduledTransactionCancelResult
Where UseFlowScheduledTransactionCancelResult is defined as:
_10interface UseFlowScheduledTransactionCancelResult extends Omit<_10 UseMutationResult<string, Error>,_10 "mutate" | "mutateAsync"_10> {_10 cancelTransaction: (txId: string) => void_10 cancelTransactionAsync: (txId: string) => Promise<string>_10}
_29import { View, Text, TouchableOpacity } from 'react-native';_29_29function CancelScheduledTransaction() {_29 const { cancelTransactionAsync, isPending, error, data: txId } = useFlowScheduledTransactionCancel({_29 mutation: {_29 onSuccess: (txId) => console.log("Cancel transaction ID:", txId),_29 },_29 })_29_29 const handleCancel = async (scheduledTxId: string) => {_29 try {_29 const resultTxId = await cancelTransactionAsync(scheduledTxId)_29 console.log("Successfully canceled scheduled transaction:", resultTxId)_29 } catch (error) {_29 console.error("Failed to cancel:", error)_29 }_29 }_29_29 return (_29 <View>_29 <TouchableOpacity onPress={() => handleCancel("42")} disabled={isPending}>_29 <Text>Cancel Scheduled Transaction #42</Text>_29 </TouchableOpacity>_29 {isPending && <Text>Canceling transaction...</Text>}_29 {error && <Text>Error: {error.message}</Text>}_29 {txId && <Text>Cancel Transaction ID: {txId}</Text>}_29 </View>_29 )_29}
useFlowScheduledTransactionSetup
_10import { useFlowScheduledTransactionSetup } from "@onflow/react-native-sdk"
Sets up the Transaction Scheduler Manager resource.
Parameters:
mutation?: UseMutationOptions<string, Error, void>– Optional TanStack Query mutation optionsflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseFlowScheduledTransactionSetupResult
Where UseFlowScheduledTransactionSetupResult is defined as:
_10interface UseFlowScheduledTransactionSetupResult extends Omit<_10 UseMutationResult<string, Error>,_10 "mutate" | "mutateAsync"_10> {_10 setup: () => void_10 setupAsync: () => Promise<string>_10}
_29import { View, Text, TouchableOpacity } from 'react-native';_29_29function SchedulerSetup() {_29 const { setupAsync, isPending, error, data: txId } = useFlowScheduledTransactionSetup({_29 mutation: {_29 onSuccess: (txId) => console.log("Setup transaction ID:", txId),_29 },_29 })_29_29 const handleSetup = async () => {_29 try {_29 const resultTxId = await setupAsync()_29 console.log("Scheduler setup successful:", resultTxId)_29 } catch (error) {_29 console.error("Setup failed:", error)_29 }_29 }_29_29 return (_29 <View>_29 <TouchableOpacity onPress={handleSetup} disabled={isPending}>_29 <Text>Setup Transaction Scheduler</Text>_29 </TouchableOpacity>_29 {isPending && <Text>Setting up scheduler...</Text>}_29 {error && <Text>Error: {error.message}</Text>}_29 {txId && <Text>Setup Transaction ID: {txId}</Text>}_29 </View>_29 )_29}
Cross-VM Hooks
useCrossVmBatchTransaction
_10import { useCrossVmBatchTransaction } from "@onflow/react-native-sdk"
This hook allows you to execute multiple EVM transactions in a single atomic Cadence transaction. It is useful for batch processing EVM calls while ensuring they are executed together, either all succeeding or allowing for some to fail without affecting the others.
Parameters:
mutation?: UseMutationOptions<string, Error, UseCrossVmBatchTransactionMutateArgs>– Optional TanStackQuery mutation optionsflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseCrossVmBatchTransactionResult
Where UseCrossVmBatchTransactionResult is defined as:
_10interface UseCrossVmBatchTransactionResult extends Omit<_10 UseMutationResult<string, Error, UseCrossVmBatchTransactionMutateArgs>,_10 "mutate" | "mutateAsync"_10> {_10 mutate: (calls: UseCrossVmBatchTransactionMutateArgs) => void_10 mutateAsync: (calls: UseCrossVmBatchTransactionMutateArgs) => Promise<string>_10}
Where UseCrossVmBatchTransactionMutateArgs is defined as:
_10interface UseCrossVmBatchTransactionMutateArgs {_10 calls: EvmBatchCall[]_10 mustPass?: boolean_10}
Where EvmBatchCall is defined as:
_14interface EvmBatchCall {_14 // The target EVM contract address (as a string)_14 address: string_14 // The contract ABI fragment_14 abi: Abi_14 // The name of the function to call_14 functionName: string_14 // The function arguments_14 args?: readonly unknown[]_14 // The gas limit for the call_14 gasLimit?: bigint_14 // The value to send with the call_14 value?: bigint_14}
_36import { View, Text, TouchableOpacity } from 'react-native';_36_36function CrossVmBatchTransactionExample() {_36 const { sendBatchTransaction, isPending, error, data: txId } = useCrossVmBatchTransaction({_36 mutation: {_36 onSuccess: (txId) => console.log("TX ID:", txId),_36 },_36 })_36_36 const sendTransaction = () => {_36 const calls = [_36 {_36 address: "0x1234567890abcdef",_36 abi: {_36 // ABI definition for the contract_36 },_36 functionName: "transfer",_36 args: ["0xabcdef1234567890", 100n],_36 gasLimit: 21000n,_36 },_36 ]_36_36 sendBatchTransaction({calls})_36 }_36_36 return (_36 <View>_36 <TouchableOpacity onPress={sendTransaction} disabled={isPending}>_36 <Text>Send Cross-VM Transaction</Text>_36 </TouchableOpacity>_36 {isPending && <Text>Sending transaction...</Text>}_36 {error && <Text>Error: {error.message}</Text>}_36 {txId && <Text>Transaction ID: {txId}</Text>}_36 </View>_36 )_36}
useCrossVmTokenBalance
_10import { useCrossVmTokenBalance } from "@onflow/react-native-sdk"
Fetch the balance of a token balance for a given user across both Cadence and EVM environments.
Parameters:
owner: string– Cadence address of the account whose token balances you want.vaultIdentifier?: string– Optional Cadence resource identifier (e.g. "0x1cf0e2f2f715450.FlowToken.Vault") for onchain balanceerc20AddressHexArg?: string– Optional bridged ERC-20 contract address (hex) for EVM/COA balancequery?: Omit<UseQueryOptions<unknown, Error>, "queryKey" | "queryFn">– Optional TanStack Query config (e.g. staleTime, enabled)flowClient?: FlowClient- OptionalFlowClientinstance
Note: You must pass
owner, and one ofvaultIdentifierorerc20AddressHexArg.
Returns: UseQueryResult<UseCrossVmTokenBalanceData | null, Error>
Where UseCrossVmTokenBalanceData is defined as:
_10interface UseCrossVmTokenBalanceData {_10 cadence: TokenBalance // Token balance of Cadence vault_10 evm: TokenBalance // Token balance of EVM (COA stored in /storage/coa)_10 combined: TokenBalance // Combined balance of both Cadence and EVM_10}
Where TokenBalance is defined as:
_10interface TokenBalance {_10 value: bigint // Balance value in smallest unit_10 formatted: string // Formatted balance string (e.g. "123.45")_10 precision: number // Number of decimal places for the token_10}
_24import { View, Text, TouchableOpacity } from 'react-native';_24_24function UseCrossVmTokenBalanceExample() {_24 const { data, isLoading, error, refetch } = useCrossVmTokenBalance({_24 owner: '0x1e4aa0b87d10b141',_24 vaultIdentifier: 'A.1654653399040a61.FlowToken.Vault',_24 query: { staleTime: 10000 },_24 });_24_24 if (isLoading) return <Text>Loading token balance...</Text>_24 if (error) return <Text>Error fetching token balance: {error.message}</Text>_24_24 return (_24 <View>_24 <Text>Token Balances</Text>_24 <Text>Cadence Balance: {data.cadence.formatted} (Value: {data.cadence.value.toString()})</Text>_24 <Text>EVM Balance: {data.evm.formatted} (Value: {data.evm.value.toString()})</Text>_24 <Text>Combined Balance: {data.combined.formatted} (Value: {data.combined.value.toString()})</Text>_24 <TouchableOpacity onPress={() => refetch()}>_24 <Text>Refetch</Text>_24 </TouchableOpacity>_24 </View>_24 )_24}
useCrossVmTransactionStatus
_10import { useCrossVmTransactionStatus } from "@onflow/react-native-sdk"
Subscribes to status updates for a given Cross-VM Flow transaction ID that executes EVM calls. This hook monitors the transaction status and extracts EVM call results if available.
Parameters:
id?: string– Optional Flow transaction ID to monitorflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseCrossVmTransactionStatusResult
Where UseCrossVmTransactionStatusResult is defined as:
_10interface UseCrossVmTransactionStatusResult {_10 transactionStatus: TransactionStatus | null // Latest transaction status, or null before any update_10 evmResults?: CallOutcome[] // EVM transaction results, if available_10 error: Error | null // Any error encountered during status updates_10}
Where CallOutcome is defined as:
_10interface CallOutcome {_10 status: "passed" | "failed" | "skipped" // Status of the EVM call_10 hash?: string // EVM transaction hash if available_10 errorMessage?: string // Error message if the call failed_10}
_30import { View, Text, FlatList } from 'react-native';_30_30function CrossVmTransactionStatusComponent() {_30 const txId = "your-cross-vm-transaction-id-here"_30 const { transactionStatus, evmResults, error } = useCrossVmTransactionStatus({ id: txId })_30_30 if (error) return <Text>Error: {error.message}</Text>_30_30 return (_30 <View>_30 <Text>Flow Status: {transactionStatus?.statusString}</Text>_30 {evmResults && evmResults.length > 0 && (_30 <View>_30 <Text>EVM Call Results:</Text>_30 <FlatList_30 data={evmResults}_30 keyExtractor={(_, idx) => idx.toString()}_30 renderItem={({ item, index }) => (_30 <View>_30 <Text>Call {index}: {item.status}</Text>_30 {item.hash && <Text>Hash: {item.hash}</Text>}_30 {item.errorMessage && <Text>Error: {item.errorMessage}</Text>}_30 </View>_30 )}_30 />_30 </View>_30 )}_30 </View>_30 )_30}
useCrossVmBridgeNftFromEvm
_10import { useCrossVmBridgeNftFromEvm } from "@onflow/react-native-sdk"
This hook bridges NFTs from Flow EVM to Cadence. It withdraws an NFT from the signer's COA (Cadence Owned Account) in EVM and deposits it into their Cadence collection.
Parameters:
mutation?: UseMutationOptions<string, Error, UseCrossVmBridgeNftFromEvmTxMutateArgs>– Optional TanStackQuery mutation optionsflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseCrossVmBridgeNftFromEvmTxResult
Where UseCrossVmBridgeNftFromEvmTxResult is defined as:
_10interface UseCrossVmBridgeNftFromEvmTxResult extends Omit<_10 UseMutationResult<string, Error>,_10 "mutate" | "mutateAsync"_10> {_10 crossVmBridgeNftFromEvm: (args: UseCrossVmBridgeNftFromEvmTxMutateArgs) => void_10 crossVmBridgeNftFromEvmAsync: (args: UseCrossVmBridgeNftFromEvmTxMutateArgs) => Promise<string>_10}
Where UseCrossVmBridgeNftFromEvmTxMutateArgs is defined as:
_10interface UseCrossVmBridgeNftFromEvmTxMutateArgs {_10 nftIdentifier: string // Cadence type identifier (e.g., "A.0x123.MyNFT.NFT")_10 nftId: string // EVM NFT ID as string representation of UInt256_10}
_27import { View, Text, TouchableOpacity } from 'react-native';_27_27function BridgeNftFromEvmExample() {_27 const { crossVmBridgeNftFromEvm, isPending, error, data: txId } = useCrossVmBridgeNftFromEvm({_27 mutation: {_27 onSuccess: (txId) => console.log("Transaction ID:", txId),_27 },_27 })_27_27 const handleBridge = () => {_27 crossVmBridgeNftFromEvm({_27 nftIdentifier: "A.0x1cf0e2f2f715450.ExampleNFT.NFT",_27 nftId: "123",_27 })_27 }_27_27 return (_27 <View>_27 <TouchableOpacity onPress={handleBridge} disabled={isPending}>_27 <Text>Bridge NFT from EVM</Text>_27 </TouchableOpacity>_27 {isPending && <Text>Bridging NFT...</Text>}_27 {error && <Text>Error: {error.message}</Text>}_27 {txId && <Text>Transaction ID: {txId}</Text>}_27 </View>_27 )_27}
useCrossVmBridgeNftToEvm
_10import { useCrossVmBridgeNftToEvm } from "@onflow/react-native-sdk"
This hook bridges NFTs from Cadence to Flow EVM and executes arbitrary EVM transactions atomically. It withdraws NFTs from the signer's Cadence collection and deposits them into their COA in EVM, then executes the provided EVM calls.
Parameters:
mutation?: UseMutationOptions<string, Error, UseCrossVmBridgeNftToEvmTxMutateArgs>– Optional TanStackQuery mutation optionsflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseCrossVmBridgeNftToEvmTxResult
Where UseCrossVmBridgeNftToEvmTxResult is defined as:
_10interface UseCrossVmBridgeNftToEvmTxResult extends Omit<_10 UseMutationResult<string, Error>,_10 "mutate" | "mutateAsync"_10> {_10 crossVmBridgeNftToEvm: (args: UseCrossVmBridgeNftToEvmTxMutateArgs) => void_10 crossVmBridgeNftToEvmAsync: (args: UseCrossVmBridgeNftToEvmTxMutateArgs) => Promise<string>_10}
Where UseCrossVmBridgeNftToEvmTxMutateArgs is defined as:
_10interface UseCrossVmBridgeNftToEvmTxMutateArgs {_10 nftIdentifier: string // Cadence NFT type identifier_10 nftIds: string[] // Array of NFT IDs to bridge_10 calls: EvmBatchCall[] // Array of EVM calls to execute after bridging_10}
_36import { View, Text, TouchableOpacity } from 'react-native';_36_36function BridgeNftToEvmExample() {_36 const { crossVmBridgeNftToEvm, isPending, error, data: txId } = useCrossVmBridgeNftToEvm({_36 mutation: {_36 onSuccess: (txId) => console.log("Transaction ID:", txId),_36 },_36 })_36_36 const handleBridge = () => {_36 crossVmBridgeNftToEvm({_36 nftIdentifier: "A.0x1cf0e2f2f715450.ExampleNFT.NFT",_36 nftIds: ["1", "2", "3"],_36 calls: [_36 {_36 address: "0x1234567890abcdef1234567890abcdef12345678",_36 abi: myContractAbi,_36 functionName: "transferNFT",_36 args: ["0xRecipient", 1n],_36 gasLimit: 100000n,_36 },_36 ],_36 })_36 }_36_36 return (_36 <View>_36 <TouchableOpacity onPress={handleBridge} disabled={isPending}>_36 <Text>Bridge NFTs to EVM</Text>_36 </TouchableOpacity>_36 {isPending && <Text>Bridging NFTs...</Text>}_36 {error && <Text>Error: {error.message}</Text>}_36 {txId && <Text>Transaction ID: {txId}</Text>}_36 </View>_36 )_36}
useCrossVmBridgeTokenFromEvm
_10import { useCrossVmBridgeTokenFromEvm } from "@onflow/react-native-sdk"
This hook bridges fungible tokens from Flow EVM to Cadence. It withdraws tokens from the signer's COA in EVM and deposits them into their Cadence vault.
Parameters:
mutation?: UseMutationOptions<string, Error, UseCrossVmBridgeTokenFromEvmMutateArgs>– Optional TanStackQuery mutation optionsflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseCrossVmBridgeTokenFromEvmResult
Where UseCrossVmBridgeTokenFromEvmResult is defined as:
_10interface UseCrossVmBridgeTokenFromEvmResult extends Omit<_10 UseMutationResult<string, Error>,_10 "mutate" | "mutateAsync"_10> {_10 crossVmBridgeTokenFromEvm: (args: UseCrossVmBridgeTokenFromEvmMutateArgs) => void_10 crossVmBridgeTokenFromEvmAsync: (args: UseCrossVmBridgeTokenFromEvmMutateArgs) => Promise<string>_10}
Where UseCrossVmBridgeTokenFromEvmMutateArgs is defined as:
_10interface UseCrossVmBridgeTokenFromEvmMutateArgs {_10 vaultIdentifier: string // Cadence vault type identifier (e.g., "A.0x123.FlowToken.Vault")_10 amount: string // Amount as UInt256 string representation_10}
_27import { View, Text, TouchableOpacity } from 'react-native';_27_27function BridgeTokenFromEvmExample() {_27 const { crossVmBridgeTokenFromEvm, isPending, error, data: txId } = useCrossVmBridgeTokenFromEvm({_27 mutation: {_27 onSuccess: (txId) => console.log("Transaction ID:", txId),_27 },_27 })_27_27 const handleBridge = () => {_27 crossVmBridgeTokenFromEvm({_27 vaultIdentifier: "A.0x1654653399040a61.FlowToken.Vault",_27 amount: "1000000000", // Amount in smallest unit_27 })_27 }_27_27 return (_27 <View>_27 <TouchableOpacity onPress={handleBridge} disabled={isPending}>_27 <Text>Bridge Tokens from EVM</Text>_27 </TouchableOpacity>_27 {isPending && <Text>Bridging tokens...</Text>}_27 {error && <Text>Error: {error.message}</Text>}_27 {txId && <Text>Transaction ID: {txId}</Text>}_27 </View>_27 )_27}
useCrossVmBridgeTokenToEvm
_10import { useCrossVmBridgeTokenToEvm } from "@onflow/react-native-sdk"
This hook bridges fungible tokens from Cadence to Flow EVM and executes arbitrary EVM transactions atomically. It withdraws tokens from the signer's Cadence vault and deposits them into their COA in EVM, then executes the provided EVM calls.
Parameters:
mutation?: UseMutationOptions<string, Error, UseCrossVmBridgeTokenToEvmMutateArgs>– Optional TanStackQuery mutation optionsflowClient?: FlowClient- OptionalFlowClientinstance
Returns: UseCrossVmBridgeTokenToEvmResult
Where UseCrossVmBridgeTokenToEvmResult is defined as:
_10interface UseCrossVmBridgeTokenToEvmResult extends Omit<_10 UseMutationResult<string, Error>,_10 "mutate" | "mutateAsync"_10> {_10 crossVmBridgeTokenToEvm: (args: UseCrossVmBridgeTokenToEvmMutateArgs) => void_10 crossVmBridgeTokenToEvmAsync: (args: UseCrossVmBridgeTokenToEvmMutateArgs) => Promise<string>_10}
Where UseCrossVmBridgeTokenToEvmMutateArgs is defined as:
_10interface UseCrossVmBridgeTokenToEvmMutateArgs {_10 vaultIdentifier: string // Cadence vault type identifier_10 amount: string // Amount as decimal string (e.g., "1.5")_10 calls: EvmBatchCall[] // Array of EVM calls to execute after bridging_10}
_36import { View, Text, TouchableOpacity } from 'react-native';_36_36function BridgeTokenToEvmExample() {_36 const { crossVmBridgeTokenToEvm, isPending, error, data: txId } = useCrossVmBridgeTokenToEvm({_36 mutation: {_36 onSuccess: (txId) => console.log("Transaction ID:", txId),_36 },_36 })_36_36 const handleBridge = () => {_36 crossVmBridgeTokenToEvm({_36 vaultIdentifier: "A.0x1654653399040a61.FlowToken.Vault",_36 amount: "10.5",_36 calls: [_36 {_36 address: "0x1234567890abcdef1234567890abcdef12345678",_36 abi: erc20Abi,_36 functionName: "transfer",_36 args: ["0xRecipient", 1000000n],_36 gasLimit: 100000n,_36 },_36 ],_36 })_36 }_36_36 return (_36 <View>_36 <TouchableOpacity onPress={handleBridge} disabled={isPending}>_36 <Text>Bridge Tokens to EVM</Text>_36 </TouchableOpacity>_36 {isPending && <Text>Bridging tokens...</Text>}_36 {error && <Text>Error: {error.message}</Text>}_36 {txId && <Text>Transaction ID: {txId}</Text>}_36 </View>_36 )_36}