import { ClarityValue } from "@stacks/transactions"; import { type Network } from "../config/networks.js"; /** * Custom error for Hiro API rate limit responses (429) */ export declare class HiroApiRateLimitError extends Error { readonly retryAfterSeconds: number; constructor(message: string, retryAfterSeconds: number); } export interface AccountInfo { balance: string; locked: string; nonce: number; balanceProof: string; nonceProof: string; } export interface StxBalance { balance: string; total_sent: string; total_received: string; locked: string; lock_height: number; lock_tx_id: string; burnchain_lock_height: number; burnchain_unlock_height: number; } export interface TokenBalance { balance: string; total_sent: string; total_received: string; } export interface FungibleTokenHolding { asset_identifier: string; balance: string; } export interface NonFungibleTokenHolding { asset_identifier: string; value: { hex: string; repr: string; }; } export interface AccountBalances { stx: StxBalance; fungible_tokens: Record; non_fungible_tokens: Record; } export interface Transaction { tx_id: string; nonce: number; fee_rate: string; sender_address: string; sponsored: boolean; post_condition_mode: string; post_conditions: unknown[]; anchor_mode: string; tx_status: string; receipt_time: number; receipt_time_iso: string; tx_type: string; block_hash?: string; block_height?: number; burn_block_time?: number; canonical?: boolean; tx_result?: { hex: string; repr: string; }; } export interface ContractInfo { tx_id: string; contract_id: string; block_height: number; source_code: string; abi: string; } export interface ContractInterface { functions: Array<{ name: string; access: string; args: Array<{ name: string; type: string; }>; outputs: { type: string; }; }>; variables: Array<{ name: string; access: string; type: string; }>; maps: Array<{ name: string; key: string; value: string; }>; fungible_tokens: Array<{ name: string; }>; non_fungible_tokens: Array<{ name: string; type: string; }>; } export interface BlockInfo { hash: string; height: number; canonical: boolean; burn_block_hash: string; burn_block_height: number; burn_block_time: number; parent_block_hash: string; parent_microblock_hash: string; parent_microblock_sequence: number; txs: string[]; microblocks_accepted: string[]; microblocks_streamed: string[]; execution_cost_read_count: number; execution_cost_read_length: number; execution_cost_runtime: number; execution_cost_write_count: number; execution_cost_write_length: number; } export interface MempoolTransaction { tx_id: string; tx_status: string; tx_type: string; receipt_time: number; receipt_time_iso: string; fee_rate: string; sender_address: string; nonce: number; sponsored?: boolean; sponsor_address?: string; sponsor_nonce?: number; } export interface PoxInfo { contract_id: string; pox_activation_threshold_ustx: number; first_burnchain_block_height: number; current_burnchain_block_height: number; prepare_phase_block_length: number; reward_phase_block_length: number; reward_slots: number; rejection_fraction: number; total_liquid_supply_ustx: number; current_cycle: { id: number; min_threshold_ustx: number; stacked_ustx: number; is_pox_active: boolean; }; next_cycle: { id: number; min_threshold_ustx: number; min_increment_ustx: number; stacked_ustx: number; prepare_phase_start_block_height: number; blocks_until_prepare_phase: number; reward_phase_start_block_height: number; blocks_until_reward_phase: number; ustx_until_pox_rejection: number; }; min_amount_ustx: number; prepare_cycle_length: number; reward_cycle_id: number; reward_cycle_length: number; rejection_votes_left_required: number; next_reward_cycle_in: number; } export interface NftHolding { asset_identifier: string; value: { hex: string; repr: string; }; block_height: number; tx_id: string; } export interface NftEvent { sender: string; recipient: string; asset_identifier: string; value: { hex: string; repr: string; }; tx_id: string; block_height: number; } export interface BnsName { name: string; address: string; blockchain: string; expire_block: number; grace_period: number; last_txid: string; resolver: string; status: string; zonefile: string; zonefile_hash: string; } export interface BnsV2NameData { name_string: string; namespace_string: string; full_name: string; owner: string; registered_at: string; renewal_height: string; stx_burn: string; revoked: boolean; imported_at: string; preordered_by: string; is_valid: boolean; } export interface BnsV2NameResponse { current_burn_block: number; status: string; is_managed: boolean; data: BnsV2NameData; } export interface BnsV2NamesOwnedResponse { total: number; current_burn_block: number; names: Array<{ full_name: string; name_string: string; namespace_string: string; owner: string; registered_at: number; renewal_height: number; stx_burn: string; }>; } export interface FeeEstimation { estimated_cost: { read_count: number; read_length: number; runtime: number; write_count: number; write_length: number; }; estimated_cost_scalar: number; estimations: Array<{ fee: number; fee_rate: number; }>; cost_scalar_change_by_byte: number; } /** * Nonce information for a Stacks address. * Used to detect nonce gaps in the sponsor relay. */ export interface NonceInfo { last_mempool_tx_nonce: number | null; last_executed_tx_nonce: number; possible_next_nonce: number; detected_missing_nonces: number[]; detected_mempool_nonces: number[]; } /** * Fee priorities from the mempool. * Values are in micro-STX. */ export interface MempoolFeePriorities { no_priority: number; low_priority: number; medium_priority: number; high_priority: number; } /** * Response from /extended/v2/mempool/fees endpoint. * Contains fee priorities for different transaction types. */ export interface MempoolFeeResponse { all: MempoolFeePriorities; token_transfer: MempoolFeePriorities; contract_call: MempoolFeePriorities; smart_contract: MempoolFeePriorities; } export interface TokenMetadata { name: string; symbol: string; decimals: number; total_supply: string; token_uri?: string; description?: string; image_uri?: string; image_thumbnail_uri?: string; image_canonical_uri?: string; tx_id: string; sender_address: string; contract_principal: string; } export declare class HiroApiService { private network; private defaultBaseUrl; private mempoolFeesCache; constructor(network: Network); /** * Helper function to attempt a single fetch request. * Extracted to enable retry logic in the main fetch() method. */ private attemptFetch; /** * Fetch data from the Hiro API with automatic retry on rate limits. * Retries up to 3 times with exponential backoff (1s, 2s, 4s). * Respects Retry-After header if present. */ private fetch; getAccountInfo(address: string): Promise; getStxBalance(address: string): Promise; getAccountBalances(address: string): Promise; getAccountTransactions(address: string, options?: { limit?: number; offset?: number; type?: string[]; }): Promise<{ limit: number; offset: number; total: number; results: Transaction[]; }>; getAccountNonce(address: string): Promise; getNonceInfo(address: string): Promise; getTokenBalance(address: string, contractId: string): Promise; getTokenMetadata(contractId: string): Promise; getTokenHolders(contractId: string, options?: { limit?: number; offset?: number; }): Promise<{ limit: number; offset: number; total: number; results: Array<{ address: string; balance: string; }>; }>; getUserTokens(address: string): Promise; getNftHoldings(address: string, options?: { limit?: number; offset?: number; asset_identifiers?: string[]; }): Promise<{ limit: number; offset: number; total: number; results: NftHolding[]; }>; getNftEvents(contractId: string, options?: { limit?: number; offset?: number; }): Promise<{ limit: number; offset: number; total: number; results: NftEvent[]; }>; getNftMetadata(contractId: string, tokenId: number): Promise; getContractInfo(contractId: string): Promise; getContractInterface(contractId: string): Promise; getContractSource(contractId: string): Promise<{ source: string; publish_height: number; }>; callReadOnlyFunction(contractId: string, functionName: string, functionArgs: ClarityValue[], senderAddress: string): Promise<{ okay: boolean; result?: string; cause?: string; }>; getContractEvents(contractId: string, options?: { limit?: number; offset?: number; }): Promise<{ limit: number; offset: number; results: unknown[]; }>; getTransaction(txid: string): Promise; getTransactionStatus(txid: string): Promise<{ status: string; block_height?: number; tx_result?: unknown; }>; searchTransactions(query: string, options?: { limit?: number; offset?: number; }): Promise<{ results: Transaction[]; }>; getMempoolTransactions(options?: { sender_address?: string; recipient_address?: string; limit?: number; offset?: number; }): Promise<{ limit: number; offset: number; total: number; results: MempoolTransaction[]; }>; estimateFee(txPayload: string): Promise; /** * Get fee priorities from the mempool. * Returns estimated fees (in micro-STX) for different priority levels * and transaction types. * * Cached for 60 seconds to reduce API load. */ getMempoolFees(): Promise; getBlockByHeight(height: number): Promise; getBlockByHash(hash: string): Promise; getLatestBlock(): Promise; getBlocks(options?: { limit?: number; offset?: number; }): Promise<{ limit: number; offset: number; total: number; results: BlockInfo[]; }>; getPoxInfo(): Promise; getStackerInfo(address: string): Promise; getBnsNameInfo(name: string): Promise; getBnsNamesOwnedByAddress(address: string): Promise<{ names: string[]; }>; getBnsNamePrice(name: string): Promise<{ units: string; amount: string; }>; resolveBnsName(name: string): Promise; getNetworkStatus(): Promise<{ server_version: string; status: string; chain_tip: { block_height: number; block_hash: string; index_block_hash: string; microblock_hash: string; microblock_sequence: number; }; }>; getCoreApiInfo(): Promise<{ peer_version: number; pox_consensus: string; burn_block_height: number; stable_pox_consensus: string; stable_burn_block_height: number; server_version: string; network_id: number; parent_network_id: number; stacks_tip_height: number; stacks_tip: string; stacks_tip_consensus_hash: string; genesis_chainstate_hash: string; }>; } export declare function getHiroApi(network: Network): HiroApiService; export declare function getStxBalance(address: string, network: Network): Promise<{ stx: string; stxLocked: string; }>; export declare function getTransactionStatus(txid: string, network: Network): Promise<{ status: string; block_height?: number; tx_result?: unknown; }>; export declare class BnsV2ApiService { private baseUrl; constructor(); private fetch; /** * Get BNS V2 name info */ getNameInfo(name: string): Promise; /** * Get names owned by an address */ getNamesOwnedByAddress(address: string): Promise; /** * Check if a name exists (is registered) */ nameExists(name: string): Promise; /** * Resolve a name to an address */ resolveName(name: string): Promise; } export declare function getBnsV2Api(): BnsV2ApiService; //# sourceMappingURL=hiro-api.d.ts.map