From 6a4b11572c3dc3aaa4cb4f175220b543ccfb4731 Mon Sep 17 00:00:00 2001 From: blockend Date: Tue, 14 Jan 2025 23:19:49 +0100 Subject: [PATCH 1/3] feat[DOCS] : add useDataTransaction documentation --- docs/hooks/useDataTransaction.md | 99 ++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 docs/hooks/useDataTransaction.md diff --git a/docs/hooks/useDataTransaction.md b/docs/hooks/useDataTransaction.md new file mode 100644 index 0000000..43a89d8 --- /dev/null +++ b/docs/hooks/useDataTransaction.md @@ -0,0 +1,99 @@ +--- +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. + +--- + +## Usage + +```tsx +import { useDataTransaction } from "~~/hooks/scaffold-stark/useDataTransaction"; + +const DataTransaction = ({ blockNumber }: { blockNumber: number }) => { + const { blockData, error, refetch, isEnabled, toggleFetching } = + useDataTransaction(blockNumber); + + return ( +
+ {error ? ( +

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...

+ )} + + +
+ ); +}; +``` + +--- + +## Parameters + +- **`blockNumber`**: `number` + The block number for which data should be fetched. + +--- + +## Return Value + +The hook returns an object with the following properties: + +### 1. `blockData: BlockData | null` +The processed data for the specified block, including: + +- **`transaction`**: Total number of transactions in the block. +- **`blockStatus`**: Status of the block. +- **`blockNumber`**: Block number. +- **`blockHash`**: Block hash. +- **`blockVersion`**: Starknet version of the block. +- **`blockTimestamp`**: Timestamp of the block. +- **`blockTransactions`**: List of transactions in the block. +- **`parentBlockHash`**: Hash of the parent block. +- **`totalTransactions`**: Total number of transactions in the block. +- **`tps`**: Transactions per second (calculated if the previous block exists). +- **`gasprice`**: Gas price in Wei for L1 transactions. +- **`gaspricefri`**: Gas price in FRI for L1 transactions. +- **`timeDiff`**: Time difference (in seconds) between the current block and the previous block. +- **`averageFeeUSD`**: Average transaction fee in USD. + +### 2. `error: string | null` +An error message if the data fetching fails. + +### 3. `refetch: () => void` +A function to refetch the data. + +### 4. `isEnabled: boolean` +Indicates whether the automatic fetching is enabled. + +### 5. `toggleFetching: () => void` +A function to toggle the automatic fetching of data. + +--- + +## 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. + +--- \ No newline at end of file From abadef34a11031d6e7024a7bca4ff11c0ed06368 Mon Sep 17 00:00:00 2001 From: blockend Date: Wed, 15 Jan 2025 15:17:05 +0100 Subject: [PATCH 2/3] docs : add usage example description for useDataTransaction hook --- docs/hooks/useDataTransaction.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/hooks/useDataTransaction.md b/docs/hooks/useDataTransaction.md index 43a89d8..02a57b5 100644 --- a/docs/hooks/useDataTransaction.md +++ b/docs/hooks/useDataTransaction.md @@ -11,6 +11,9 @@ Use this hook to fetch, process, and monitor blockchain transaction data from St ## 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"; From f053d00effef00ce919cf4e20e903a2f3dcb8dce Mon Sep 17 00:00:00 2001 From: blockend Date: Wed, 15 Jan 2025 15:25:39 +0100 Subject: [PATCH 3/3] docs : move features section to the top --- docs/hooks/useDataTransaction.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/hooks/useDataTransaction.md b/docs/hooks/useDataTransaction.md index 02a57b5..424767b 100644 --- a/docs/hooks/useDataTransaction.md +++ b/docs/hooks/useDataTransaction.md @@ -9,6 +9,16 @@ Use this hook to fetch, process, and monitor blockchain transaction data from St --- +## 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, @@ -91,12 +101,3 @@ A function to toggle the automatic fetching of data. --- -## 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. - ---- \ No newline at end of file