Skip to main content

tx

Creates a transaction monitor that provides methods for tracking and subscribing to transaction status updates on the Flow blockchain. This function returns an object with methods to get snapshots, subscribe to status changes, and wait for specific transaction states.

Import

You can import the entire package and access the function:


_10
import * as fcl from "@onflow/fcl-react-native"
_10
_10
fcl.tx(transactionId, opts)

Or import directly the specific function:


_10
import { tx } from "@onflow/fcl-react-native"
_10
_10
tx(transactionId, opts)

Usage


_54
// Basic transaction monitoring
_54
import * as fcl from "@onflow/fcl"
_54
_54
const txId = await fcl.mutate({
_54
cadence: `
_54
transaction {
_54
execute { log("Hello, World!") }
_54
}
_54
`
_54
})
_54
_54
// Get current status
_54
const status = await fcl.tx(txId).snapshot()
_54
console.log("Current status:", status.status)
_54
_54
// Subscribe to all status changes
_54
const unsubscribe = fcl.tx(txId).subscribe((status) => {
_54
console.log("Status update:", status.status)
_54
if (status.status === fcl.transaction.isSealed) {
_54
console.log("Transaction sealed!")
_54
console.log("Events:", status.events)
_54
}
_54
})
_54
// Clean up subscription when done
_54
setTimeout(() => unsubscribe(), 60000)
_54
_54
// Wait for specific transaction states
_54
try {
_54
// Wait for finalization (consensus reached)
_54
const finalizedStatus = await fcl.tx(txId).onceFinalized()
_54
console.log("Transaction finalized")
_54
_54
// Wait for execution (transaction executed)
_54
const executedStatus = await fcl.tx(txId).onceExecuted()
_54
console.log("Transaction executed")
_54
_54
// Wait for sealing (transaction sealed in block)
_54
const sealedStatus = await fcl.tx(txId).onceSealed()
_54
console.log("Transaction sealed:", sealedStatus.events)
_54
} catch (error) {
_54
console.error("Transaction failed:", error.message)
_54
}
_54
_54
// Handle transaction errors
_54
fcl.tx(txId).subscribe(
_54
(status) => {
_54
if (status.statusCode === 1) {
_54
console.error("Transaction error:", status.errorMessage)
_54
}
_54
},
_54
(error) => {
_54
console.error("Subscription error:", error)
_54
}
_54
)

Parameters

transactionId

  • Type: string
  • Description: The 64-character hex transaction ID to monitor. Must be a valid Flow transaction hash (64 bytes represented as hex string).

opts (optional)

  • Type:

_10
{ pollRate?: number; txNotFoundTimeout?: number; }

  • Description: Optional configuration parameters

Returns


_10
{ snapshot: () => Promise<TransactionStatus>; subscribe: (onData: (txStatus: TransactionStatus) => void, onError?: (err: Error) => void) => () => void; onceFinalized: () => Promise<TransactionStatus>; onceExecuted: () => Promise<TransactionStatus>; onceSealed: () => Promise<TransactionStatus>; }

Transaction monitor object with methods for tracking transaction status


Rate this page