Skip to main content

Hooks

React hooks for authentication, wallet, and payment functionality.

useAuth

Authentication state and actions.

import { useAuth } from '@agentfish/react';

function MyComponent() {
const {
isAuthenticated, // boolean - is user logged in
isLoading, // boolean - auth state loading
user, // User | null
signOut, // () => Promise<void>
} = useAuth();

if (isLoading) return <div>Loading...</div>;

return (
<div>
{isAuthenticated ? (
<>
<p>Welcome, {user?.email}</p>
<button onClick={signOut}>Sign Out</button>
</>
) : (
<p>Please sign in</p>
)}
</div>
);
}

Return Values

ValueTypeDescription
isAuthenticatedbooleanWhether user is logged in
isLoadingbooleanAuth state is loading
userUser | nullCurrent user object
signOut() => Promise<void>Sign out function

useWallet

Wallet information and actions.

import { useWallet } from '@agentfish/react';

function WalletInfo() {
const {
wallet, // Wallet | null
balance, // number (USDC)
address, // string | null
refreshWallet, // () => Promise<void>
} = useWallet();

return (
<div>
<p>Address: {address}</p>
<p>Balance: ${balance?.toFixed(2)} USDC</p>
<button onClick={refreshWallet}>Refresh</button>
</div>
);
}

Return Values

ValueTypeDescription
walletWallet | nullFull wallet object
balancenumberBalance in USDC
addressstring | nullWallet address
refreshWallet() => Promise<void>Refresh wallet data

useAgentFish

Full context access including x402 payment functions.

import { useAgentFish } from '@agentfish/react';

function PaymentExample() {
const {
// Auth
isAuthenticated,
user,
wallet,

// Payments
fetch, // x402-aware fetch wrapper
pay, // Manual payment function

// Wallet
balance,
refreshWallet,
getPayments,
} = useAgentFish();

const handleRequest = async () => {
// x402-aware fetch - automatically handles 402 Payment Required
const response = await fetch('https://ai-api.com/chat', {
method: 'POST',
body: JSON.stringify({ message: 'Hello' }),
maxPayment: 1.00, // Max $1 USDC
});

const data = await response.json();
console.log(data);
};

const handleManualPayment = async () => {
// Manual payment
const { signature } = await pay(
0.50, // Amount
'https://merchant.com', // Merchant
'merchant-address' // Address
);
console.log('Payment signature:', signature);
};

return (
<div>
<p>Balance: ${balance} USDC</p>
<button onClick={handleRequest}>Make API Request</button>
<button onClick={handleManualPayment}>Send Payment</button>
</div>
);
}

Return Values

ValueTypeDescription
isAuthenticatedbooleanWhether user is logged in
userUser | nullCurrent user object
walletWallet | nullFull wallet object
balancenumberBalance in USDC
fetchfunctionx402-aware fetch wrapper
payfunctionManual payment function
refreshWalletfunctionRefresh wallet data
getPaymentsfunctionGet payment history

TypeScript Types

import type {
User,
Wallet,
Payment,
} from '@agentfish/react';