hip4.wallet) handles all fund management for HIP-4 prediction trading: moving USDC between your perp and spot accounts, buying and selling USDC on the spot market, and withdrawing funds to external addresses. It relies on two distinct signers - one for user-authorized EIP-712 operations, and one for L1 agent-signed spot orders - 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 viasetSigner. Required for EIP-712 operations: transfers between spot and perps, withdrawals, and USD sends. The signer must produce a valid EIP-712 signature on the HyperliquidSignTransaction domain.
Agent key - initialized via hip4.auth.initAuth. Required for USDC spot buy/sell, 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
walletClient.signTypedData and any other EIP-712-capable signer.
Methods
All amounts are strings representing USDC quantities with up to 6 decimal places (e.g.
"100", "25.50").
WalletActionResult
Every method returns a Promise<WalletActionResult>:
Deposit flow
To fund a prediction account, transfer USDC from your perp balance to spot, then buy USDH on the spot market.Withdraw flow
To exit a prediction position and withdraw funds, sell USDC back to USDC, move it to your perp account, then withdraw.sellHype(amount)
Sells HYPE on the HYPE/USDC spot market (not USDC). Use this to convert HYPE - for example, balance received on Hypercore - back into USDC. Like buyUsdc/sellUsdc, it is an IOC spot order signed with the L1 agent key.
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.
testnet flag (107 on mainnet, 1035 on testnet).