@agg-market/hooks
v13.0.0
Published
React hooks for the [AGG](https://agg.market) prediction market aggregator. Wraps [`@agg-market/sdk`](https://www.npmjs.com/package/@agg-market/sdk) with React context, shared auth/session state, and data fetching.
Downloads
1,644
Readme
@agg-market/hooks
React hooks for the AGG prediction market aggregator. Wraps
@agg-market/sdk with React context, shared
auth/session state, and data fetching.
For pre-built trading components, see @agg-market/ui.
For the connect/sign-in UX and auth method adapters, see
@agg-market/auth.
Install
npm install @agg-market/sdk @agg-market/hooksQuick start
Wrap your app in <AggProvider>:
import { AggProvider } from "@agg-market/hooks";
import { createAggClient } from "@agg-market/sdk";
const client = createAggClient({
baseUrl: "https://api.agg.market",
appId: "your-app-id",
});
function App() {
return (
<AggProvider client={client}>
<YourApp />
</AggProvider>
);
}Auth Session State
AggProvider owns the shared AGG auth session. It keeps client.isAuthenticated, the current
user profile, and token-backed session refresh/sign-out behavior in sync for the rest of the hooks
layer.
For most apps, use @agg-market/auth on top of AggProvider:
import { AggProvider } from "@agg-market/hooks";
import { createAggClient } from "@agg-market/sdk";
import { AggAuthProvider, ConnectButton, createEmailAuthMethod } from "@agg-market/auth";
import { useSiweAuthMethod } from "@agg-market/auth/siwe";
import { WagmiProvider } from "wagmi";
import { wagmiConfig } from "./wagmi-config";
const client = createAggClient({
baseUrl: "https://api.agg.market",
appId: "your-app-id",
});
function AuthButton() {
const siwe = useSiweAuthMethod();
return (
<AggAuthProvider methods={[siwe, createEmailAuthMethod()]}>
<ConnectButton />
</AggAuthProvider>
);
}
function App() {
return (
<WagmiProvider config={wagmiConfig}>
<AggProvider client={client}>
<AuthButton />
</AggProvider>
</WagmiProvider>
);
}useAggAuth Compatibility Hook
useAggAuth remains available as a lower-level helper for apps that want to wire their own wallet
UI and directly trigger SIWE or SIWS message signing:
import { useAggAuth } from "@agg-market/hooks";
import { useAccount, useSignMessage } from "wagmi";
function SignIn() {
const { address, chainId } = useAccount();
const { signMessageAsync } = useSignMessage();
const { signIn, signOut, isAuthenticated, user } = useAggAuth({
signMessage: async (message) => signMessageAsync({ message }),
address,
chainId,
});
if (isAuthenticated) {
return (
<div>
<p>Signed in as {user?.id}</p>
<button onClick={signOut}>Sign out</button>
</div>
);
}
return <button onClick={() => signIn("Sign in to AGG")}>Sign in with Ethereum</button>;
}For Solana, pass a signMessage function that signs the raw UTF-8 message bytes and returns a
base58-encoded Ed25519 signature:
import bs58 from "bs58";
import { useWallet } from "@solana/wallet-adapter-react";
import { useAggAuth } from "@agg-market/hooks";
function SolanaSignIn() {
const { publicKey, signMessage } = useWallet();
const { signIn, isLoading } = useAggAuth({
address: publicKey?.toBase58(),
chain: "solana",
chainId: "mainnet",
signMessage: async (message) => {
const signedBytes = await signMessage!(new TextEncoder().encode(message));
return bs58.encode(signedBytes);
},
});
return (
<button onClick={() => signIn("Sign in to AGG")} disabled={isLoading}>
Sign in with Solana
</button>
);
}This stays Ledger-compatible because the dapp builds the SIWS message and the wallet only needs to
support signMessage().
Hooks
| Hook | Description |
| -------------------------- | -------------------------------------------- |
| useAggClient() | Access the AggClient instance from context |
| useAggAuth(options) | Wallet-signature helper for SIWE/SIWS |
| useHello() | Health check — { data, error, isLoading } |
| useVenueEvents(options) | Fetch prediction market events |
| useCategories(options) | Fetch market categories |
| useOrderBook(options) | Fetch orderbook data |
| useVenueBalances(venues) | Fetch balances across venues |
Peer dependencies
@agg-market/sdkreact^18.0.0 or ^19.0.0
Related packages
| Package | Description |
| -------------------------------------------------------------------- | ------------------------------------ |
| @agg-market/sdk | Vanilla TypeScript client |
| @agg-market/ui | Pre-built React trading components |
| @agg-market/auth | Auth adapters and connect/sign-in UI |
License
MIT
