import {createTakerClient, type TakerClient} from "@parlays-live/taker";
createTakerClient
function createTakerClient(config: TakerConfig): TakerClient
Creates a taker client bound to one deployment (relayer + escrow + chain). Pure and stateless; safe as a module-level singleton. See TakerConfig for the config fields and Configuration for network presets.
The returned object exposes config (the exact config passed in) plus the methods below, in two groups: relayer transport (HTTP) and signing + on-chain call parameters (pure builders for wagmi/viem).
All relayer methods throw an Error whose message is the relayer’s error string (or request failed (<status>)) on any non-2xx response.
Relayer transport
quote
quote(legs: PickLeg[], stake: bigint, taker: Address): Promise<QuoteResponse>
Prices a leg set from live Hyperliquid mids and returns the maker-signed order. The client never supplies odds.
The legs to combine: {marketId: number, outcome: number} with outcome 0 NO / 1 YES. Max 10 legs by default (relayer-enforced).
Taker gross stake, raw USDC 6 decimals. Relayer defaults: min 1 USDC, max 5,000 USDC.
The taker’s wallet address; baked into the order and verified on-chain.
Returns QuoteResponse: the serialized order, the maker signature, the quote economics, the correlation transparency block, and the margin block (or null). Throws on refusals (mutually exclusive legs), risk-limit rejections, and pricing failures; see relayer errors.
submit
submit(order: Record<string, unknown>, makerSig: Hex, takerSig: Hex): Promise<SubmitResponse>
Relays a fully signed order on-chain. Gasless for the taker: the relayer simulates then sends ParlayEscrow.submitParlay.
order
Record<string, unknown>
required
The serialized order exactly as returned by quote (do not modify it; both signatures cover it byte-for-byte).
The taker’s EIP-712 signature over takerSigningPayload(order).
Returns SubmitResponse: {txHash: Hex, parlayId: string}.
cashoutQuote
cashoutQuote(parlayId: number, taker: Address): Promise<CashoutQuote>
Fetches a quoter-signed buy-back price to close a live parlay early. Only the parlay’s taker can request it. Returns CashoutQuote; the signature expires 120 seconds after issuance.
margin
margin(detail?: boolean): Promise<MarginState>
Public margin-engine state: isolated vs cross accounting side by side, vault capacity, and quoting headroom under both modes. Pass detail: true to include the per-position book and netting clusters. Returns MarginState. See Margin concepts.
health
health(): Promise<RelayerHealth>
Relayer readiness: configuration, RPC, Hyperliquid, vault, and quoter authorization checks, plus the pause flag. Returns RelayerHealth. Useful as a preflight before showing trade UI (ok: false means quotes will fail).
Signing + on-chain call parameters
These are pure builders; nothing is sent anywhere.
takerSigningPayload
takerSigningPayload(order: Record<string, unknown>): {
domain: TypedDataDomain; // {name: "Sparrow", version: "1", chainId, verifyingContract: escrow}
types: typeof PARLAY_TYPES;
primaryType: "ParlayOrder";
message: Record<string, unknown>;
}
The EIP-712 payload the taker signs, deserialized back to bigints from the quote’s serialized order. Feed it straight to wagmi’s signTypedData / viem’s signTypedData. It signs the exact order the maker signed.
const takerSig = await signTypedDataAsync(client.takerSigningPayload(q.order) as never);
allowanceCall
allowanceCall(owner: Address): {address; abi; functionName: "allowance"; args: [owner, escrow]}
readContract parameters for the current USDC allowance the escrow can pull from owner. Compare against the stake before submitting.
approveCall
approveCall(amount: bigint): {chainId; address; abi; functionName: "approve"; args: [escrow, amount]}
writeContract parameters approving the escrow to pull stakes. The React hook approves maxUint256 once so the approve transaction never recurs; pass an exact amount if your host prefers per-trade approvals.
cashOutCall
cashOutCall(parlayId: number, q: CashoutQuote): {chainId; address; abi; functionName: "cashOut"; args}
writeContract parameters executing a quoted cash-out on the escrow: cashOut(parlayId, cashValue, quoterNonce, deadline, sig), with the string fields of the quote converted to bigint for you.
Non-React usage
The client plus the pure position reads cover scripts, servers, and bots without wagmi:
import {createPublicClient, http} from "viem";
import {privateKeyToAccount} from "viem/accounts";
import {createTakerClient, fetchParlays, parseUsdc} from "@parlays-live/taker";
const taker = createTakerClient({
relayerUrl: "https://sparrow-relayer.dennis-furrer.workers.dev",
escrow: "0x77DeFc3E3B66bE01B8468Eb696Ec9F330D24332a",
collateralToken: "0x75b69d0E8fA3CdB644b0f069E4e876B85A76E137",
chainId: 998,
});
const account = privateKeyToAccount(process.env.PK as `0x${string}`);
// quote -> sign -> submit, no browser anywhere
const q = await taker.quote([{marketId: 101, outcome: 1}], parseUsdc("10"), account.address);
const takerSig = await account.signTypedData(taker.takerSigningPayload(q.order) as never);
const res = await taker.submit(q.order, q.makerSig, takerSig);
// read positions with a plain viem client
const publicClient = createPublicClient({transport: http("https://rpc.hyperliquid-testnet.xyz/evm")});
const rows = await fetchParlays(publicClient, {escrow: taker.config.escrow});
The snippet assumes the account already approved the escrow for USDC; call approveCall through a viem WalletClient first if not.