import { GetBlockResponse } from 'starknet';
import { BlockNumber } from 'starknet';
/** Value returned from `useStarknetBlock`. */
export interface StarkNetBlockResult {
/** Block data. */
data?: GetBlockResponse;
/** True if loading block. */
loading?: boolean;
/** Error loading block. */
error?: string;
}
/**
* Hook for fetching a block.
*
* @remarks
*
* This hook fetches the `latest` block using the default provider.
* Block data is continuously refreshed in the background.
*
* @deprecated Use {@link useBlock}.
*
* @example
* This example shows how to fetch the latest block.
* ```tsx
* function Component() {
* const { data, loading, error } = useStarknetBlock()
*
* if (loading) return Loading...
* if (error) return Error...
* return Hash: {data.block_hash}
* }
* ```
*/
export declare function useStarknetBlock(): StarkNetBlockResult;
export interface FetchBlockArgs {
/** Identifier for the block to fetch. */
blockIdentifier: BlockNumber;
}
/** Arguments for `useBlock`. */
export declare type UseBlockProps = Partial & {
/** How often to refresh the data. */
refetchInterval?: number | false;
/** Callback fired every time a new block is fetched. */
onSuccess?: (block: GetBlockResponse) => void;
};
/** Value returned from `useBlock`. */
export interface UseBlockResult {
/** Block data. */
data?: GetBlockResponse;
/** True if loading block data. */
isLoading: boolean;
/** True if error while loading data. */
isError: boolean;
/** Error fetching block. */
error?: unknown;
}
/**
* Hook for fetching a block.
*
* @remarks
*
* Specify which block to fetch with the `blockIdentifier` argument.
* Control if and how often data is refreshed with `refetchInterval`.
*
* @example
* This example shows how to fetch the latest block only once.
* ```tsx
* function Component() {
* const { data, isLoading, isError } = useBlock({
* refetchInterval: false,
* blockIdentifier: 'latest'
* })
*
* if (isLoading) return Loading...
* if (isError) return Error...
* return Hash: {data.block_hash}
* }
* ```
*
* @example
* This example shows how to fetch the pending block every 3 seconds.
* Use your browser network monitor to verify that the hook is refetching the
* data.
* ```tsx
* function Component() {
* const { data, isLoading, isError } = useBlock({
* refetchInterval: 3000,
* blockIdentifier: 'pending'
* })
*
* if (isLoading) return Loading...
* if (isError) return Error...
* return Hash: {data.block_hash}
* }
* ```
*/
export declare function useBlock({ refetchInterval, onSuccess, blockIdentifier, }?: UseBlockProps): UseBlockResult;