hip4.auth) manages the agent key lifecycle for HIP-4 prediction trading. Rather than prompting the user to sign every individual order, HIP-4 uses an ephemeral agent keypair that you approve once via the user’s wallet. After approval, the agent key signs all orders and USDH spot trades silently on the user’s behalf. The adapter tracks the current auth state and exposes it synchronously so your UI can react to changes without awaiting async calls.
HIP4Signer interface
The signer argument you pass to initAuth must implement HIP4Signer:
initAuth accepts:
- viem
PrivateKeyAccount(fromprivateKeyToAccount), which the SDK wraps to matchHIP4Signer - ethers v6
WalletorSigner, which hasgetAddress()andsignTypedData() - Any other object with
getAddress()andsignTypedData()that returns a hex string or{ r, s, v }object
signer here is the agent key, not the user’s wallet. The agent has a different address from the user’s wallet by design.
Methods on adapter.auth
initAuth(walletAddress, signer)
Stores the agent signer for use by the trading and wallet adapters and sets the state to "ready". It doesn’t check that Hyperliquid has approved the agent; an unapproved agent’s orders are rejected by the exchange. Throws if signer isn’t an object with a signTypedData() method.
Returns
Promise<PredictionAuthState>.
getAuthStatus()
Returns the current auth state synchronously. Use this to gate UI elements or order flows.
clearAuth()
Resets the auth adapter to "disconnected" state. Call this on user logout or when the agent key is rotated.
Standalone functions
These functions are exported from@outcome.xyz/hip4 and are used to create and submit the one-time agent approval before calling initAuth.
getAgentApprovalTypedData(agentAddress, agentName, nonce, isMainnet?)
Builds the EIP-712 typed data object for the user to sign when approving an agent.
Returns an object with
domain, types, primaryType, and message, ready for walletClient.signTypedData.
submitAgentApproval(signature, agentAddress, agentName, nonce, isMainnet?, exchangeUrl?)
Submits the signed agent approval to Hyperliquid. After this call succeeds, the agent can sign orders on the user’s behalf.
Returns
Promise<{ success: boolean; error?: string }>. It doesn’t throw: network errors come back as success: false. Check success before proceeding to initAuth.
Builder fee approval
Before orders can carry your builder fee, the user must approve a maximum fee rate for your builder address. The flow mirrors agent approval: build the typed data, have the user’s wallet sign it, then submit it. Hyperliquid lets one address approve up to 10 builders.getBuilderFeeApprovalTypedData(builderAddress, maxFeeRate, nonce, isMainnet?) and submitBuilderFeeApproval(signature, builderAddress, maxFeeRate, nonce, isMainnet?, exchangeUrl?) take the same isMainnet flag (default true) as the agent functions. submitBuilderFeeApproval returns Promise<{ success: boolean; error?: string }>. To check an existing approval, call hip4.client.fetchMaxBuilderFee(user, builder), which returns the approved fee in tenths of a basis point (0 if none).
Full agent approval flow
The following example shows the complete setup using viem. You run this flow once for each new agent key.The agent’s address differs from the user’s wallet address. The SDK does not
validate that they match - this is intentional, since the agent signs on
behalf of the user.