bigblocks
Version:
Complete Bitcoin UI component library - authentication, social, wallet, market, inscriptions, and blockchain interactions for React
31 lines (30 loc) • 1.05 kB
JavaScript
// useBlockchainService Hook
// Provides access to the blockchain service for making API calls
import { useMemo } from "react";
import { useBitcoinAuthContext } from "../components/providers/BitcoinAuthProvider.js";
import { createBlockchainService, } from "../lib/blockchain-service.js";
/**
* Hook to access the blockchain service for making blockchain API calls
*
* @example
* ```tsx
* const blockchainService = useBlockchainService();
*
* // Broadcast a transaction
* const result = await blockchainService.broadcastTransaction(tx);
*
* // Get UTXOs
* const utxos = await blockchainService.getUTXOs(address);
*
* // Get balance
* const balance = await blockchainService.getBalance(address);
* ```
*/
export function useBlockchainService() {
const { config } = useBitcoinAuthContext();
// Create blockchain service instance based on config
const blockchainService = useMemo(() => {
return createBlockchainService(config.blockchainService);
}, [config.blockchainService]);
return blockchainService;
}