import type { Address } from "@starknet-start/chains"; import type { Abi, ExtractAbiFunction, ExtractAbiFunctionNames, ExtractArgs, FunctionRet } from "abi-wan-kanabi/kanabi"; import type { BlockNumber } from "starknet"; import type { UseQueryProps, UseQueryResult } from "../query"; import { type CallQueryKey, type UseCallProps, useCall } from "./use-call"; type Result> = FunctionRet; /** Options for `useReadContract`. */ export type UseReadContractProps> = UseQueryProps< Result, Error, Result, ReturnType > & { /** The target contract's ABI. * * @remarks * * You must pass ABI as const * */ abi?: TAbi; /** The target contract's address. */ address?: Address; /** Refresh data at every block. */ watch?: boolean; /** The contract's function name. */ functionName: TFunctionName; /** Read arguments. */ args?: ExtractArgs>; /** Block identifier used when performing call. */ blockIdentifier?: BlockNumber; }; /** Value returned from `useReadContract`. */ export type UseReadContractResult< TAbi extends Abi, TFunctionName extends ExtractAbiFunctionNames, > = UseQueryResult, Error>; /** * Perform a read-only contract call. If the specified block identifier is pending, * the hook will periodically refetch data automatically. * * @remarks * * - The hook only performs a call if the target `abi`, `address`, * `functionName`, and `args` are not undefined. * * - You must pass `abi` as `const` for autocomplete to work. */ export function useReadContract>( props: UseReadContractProps, ) { return useCall(props as UseCallProps) as UseReadContractResult; }