This repository was archived by the owner on Apr 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
feat[DOCS] : add useDataTransaction documentation #90
Merged
metalboyrick
merged 3 commits into
Scaffold-Stark:main
from
Oladayo-Ahmod:useDataTransaction-docs
Feb 5, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 ( | ||
| <div> | ||
| {error ? ( | ||
| <p>Error: {error}</p> | ||
| ) : blockData ? ( | ||
| <> | ||
| <p>Block Number: {blockData.blockNumber}</p> | ||
| <p>Transactions: {blockData.transaction}</p> | ||
| <p>TPS: {blockData.tps}</p> | ||
| <p>Gas Price (ETH): {blockData.gasprice}</p> | ||
| <p>Average Fee (USD): {blockData.averageFeeUSD}</p> | ||
|
|
||
| </> | ||
| ) : ( | ||
| <p>Loading block data...</p> | ||
| )} | ||
| <button onClick={toggleFetching}> | ||
| {isEnabled ? "Pause Fetching" : "Resume Fetching"} | ||
| </button> | ||
| <button onClick={refetch}>Refetch Data</button> | ||
| </div> | ||
| ); | ||
| }; | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 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. | ||
|
|
||
| --- | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe can briefly state what the example does, like in your other PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done