Skip to main content
The wallet adapter (hip4.wallet) handles fund management around HIP-4 prediction trading: moving USDC between your perp and spot balances, sending USDC, and withdrawing funds to external addresses. HIP-4 outcomes are quoted in USDC, and outcome orders spend the USDC in your spot balance. The adapter relies on two distinct signers - one for user-authorized EIP-712 operations, and one for L1 agent-signed actions - so you need to configure both before using the full method surface.

Two signers

The wallet adapter uses two separate signing keys depending on the operation: User’s wallet - set via setSigner. Required for EIP-712 operations: transfers between spot and perps, withdrawals, and sends. The signer must produce a valid EIP-712 signature on the HyperliquidSignTransaction domain. Agent key - initialized via hip4.auth.initAuth. Required for spot orders (buyUsdh, sellUsdh, buyHype, sellHype) and agentSetAbstraction, which use L1 agent signing (MessagePack serialization + keccak-256 + EIP-712 on the Exchange domain, chain ID 1337). The agent key signs on behalf of the user’s wallet but is a separate keypair.

setSigner interface

setSigner accepts either a HIP4Signer (an object with getAddress() and signTypedData(domain, types, value)) or a viem-style object:
A viem WalletClient’s signTypedData fits the second shape:

Methods

All amounts are decimal strings (e.g. "100", "25.5"). The adapter also exposes lower-level transfer methods (usdClassTransfer, spotSend, sendAsset, sendSpotTokenToEvm, sendToEvmWithData, sendUsdcToEvm) and setReferrer.

WalletActionResult

Every method except setSigner returns a Promise<WalletActionResult>. The methods return failures in the result instead of throwing:

Fund your spot balance

On a standard Hyperliquid account, spot and perps are separate balances, and USDC deposited to Hyperliquid lands in your perp balance. HIP-4 orders spend your spot balance, so move the USDC across first. Accounts in unified or portfolio-margin mode share one balance, and Hyperliquid rejects the transfer, so skip this step for them.

Withdraw flow

Withdrawals leave from your perp balance. On a standard account, move USDC from spot to perps first, then withdraw. Unified and portfolio-margin accounts withdraw directly.

sellHype(amount)

Sells HYPE on the HYPE/USDC spot market. Use this to convert HYPE - for example, balance received on Hypercore - back into USDC. Like buyUsdh and sellUsdh, it is an IOC spot order signed with the L1 agent key. buyHype(amount) is the buying counterpart, with amount also in HYPE. The amount is a HYPE quantity string. HYPE has 2 size decimals on the spot market, so the size is floored (ROUND_DOWN) to 2 decimal places before submission - never rounded up - so a sell can never exceed your HYPE balance.
The correct HYPE/USDC spot index is selected automatically from the adapter’s testnet flag (107 on mainnet, 1035 on testnet).

agentSetAbstraction(mode)

Switches the master account’s abstraction mode using the approved agent key. This is an L1 agent-signed action, so the agent must be initialized first.
buyUsdh, sellUsdh, buyHype, sellHype, and agentSetAbstraction require the agent to be initialized first. Call hip4.auth.initAuth(walletAddress, agentSigner) before invoking any of them, or they will fail with a "Not authenticated" error.
transferToSpot, transferToPerps, withdraw, and usdSend require setSigner to be called first with the user’s actual wallet. These operations use EIP-712 user signing and cannot use the agent key.