diff --git a/docs/hooks/useDataTransaction.md b/docs/hooks/useDataTransaction.md new file mode 100644 index 0000000..424767b --- /dev/null +++ b/docs/hooks/useDataTransaction.md @@ -0,0 +1,103 @@ +--- +sidebar_position: 11 +--- + + +# `useDataTransaction` + +Use this hook to fetch, process, and monitor blockchain transaction data from Starknet for a specific block number. It calculates various statistics such as transactions per second (TPS), gas prices, average transaction fees in USD, and many more. + +--- + +## Features + +- **Automatic Data Fetching**: Automatically fetches data when the hook is used. +- **TPS Calculation**: Estimates transactions per second based on block timestamps. +- **Average Fee in USD**: Converts transaction fees from Wei to USD using live ETH price data from CoinGecko. +- **Gas Price Metrics**: Retrieves L1 gas price information in both Wei and FRI. +- **Error Handling**: Captures and provides error details if fetching fails. + +--- + +## Usage + +This example fetches and monitors data for the specified block, +allowing you to display metrics or manage the data fetching state dynamically. + +```tsx +import { useDataTransaction } from "~~/hooks/scaffold-stark/useDataTransaction"; + +const DataTransaction = ({ blockNumber }: { blockNumber: number }) => { + const { blockData, error, refetch, isEnabled, toggleFetching } = + useDataTransaction(blockNumber); + + return ( +
Error: {error}
+ ) : blockData ? ( + <> +Block Number: {blockData.blockNumber}
+Transactions: {blockData.transaction}
+TPS: {blockData.tps}
+Gas Price (ETH): {blockData.gasprice}
+Average Fee (USD): {blockData.averageFeeUSD}
+ + > + ) : ( +Loading block data...
+ )} + + +