# Local Hyperliquid signatures and execution

BLOCK CLI signs supported Hyperliquid L1 actions and direct spot/perp USDC transfers with the agent's encrypted local EVM wallet. The hosted API prepares unsigned actions and reads exchange state. Private keys never go to the hosted API.

Supported execution is mainnet, direct master account: one default-perpetual limit order (`Alo`, `Ioc`, or `Gtc`), one cancellation, a cross/isolated leverage update, an isolated-margin change, or a direct USDC transfer between the account's HyperCore spot and default-perpetual balances. This is Hyperliquid exchange signing, not a HyperEVM transaction. Generic messages, arbitrary typed data, external transfers/bridge withdrawals, API-wallet delegation, vaults, subaccounts, builder fees, trigger orders, batch orders, spot trading, and HIP-3 execution are unsupported.

## Prepare, inspect, sign, submit

Prepare an order with `block-cli call hyperliquid prepare_order --params '<JSON>'`. Required parameters are `user`, `nonce`, `expiresAfter`, `coin`, `side`, `limitPrice`, `size`, `timeInForce`, `reduceOnly`, and `maxNotionalUsd`. Optional `clientOrderId` is a unique 128-bit hexadecimal ID. `user` must equal the EVM address in the local wallet.

Allocate signer nonces atomically in your runtime. Use Unix milliseconds between five minutes ago and one minute ahead; `expiresAfter` must be after both nonce and now and within five minutes. The hosted API and local inspector do not reserve nonces. Saving an action does not extend its validity.

```sh
# Save the preparation response as prepared-order.json, then inspect it.
block-cli hyperliquid inspect --file prepared-order.json --out order-review.json

# Review action, numeric asset index, side, exact size/price, time-in-force,
# reduceOnly, nonce, expiry, signer and approvalDigest in order-review.json.
# Read the digest from that file and pass its exact value as APPROVAL_DIGEST.
block-cli hyperliquid sign \
  --file agent-wallet.json \
  --review order-review.json \
  --approve "$APPROVAL_DIGEST" \
  --max-notional-usd 100 \
  --out signed-order.json

# This command submits the signed action to the exchange.
block-cli hyperliquid submit --file signed-order.json
```

Unlocking uses `AGENT_CRYPTO_WALLET_PASSWORD`, as for other local wallet commands. `hyperliquid sign` only signs and saves; `hyperliquid submit` performs the exchange POST. Signed artifacts use dedicated Hyperliquid formats and cannot be passed as Solana or EVM transactions.

For cancellations and leverage updates, prepare with `prepare_cancel` or `prepare_leverage`, then use the same inspect/sign/submit sequence. `--max-notional-usd` is required for orders; exact digest approval is required for every action. The local notional ceiling compares limit price times size with exact decimal arithmetic. It excludes trading fees and funding and does not cap realized sell proceeds, which can exceed the limit-price notional.

The API checks market precision and limits against fetched metadata. The local inspector validates the supplied preparation and describes the numeric asset index actually signed; it does not independently fetch market metadata or establish account eligibility, margin, positions, or ownership. Hyperliquid enforces execution constraints.

## Signature and submission behavior

The action must retain canonical field order and decimal strings. Local signing follows the official Python SDK: MessagePack action bytes, eight-byte big-endian nonce, null-vault marker, and expiry marker plus eight-byte expiry are hashed with Keccak-256. The fixed EIP-712 `Exchange` domain uses version `1`, chain ID `1337`, zero verifying contract, and mainnet phantom-agent source `a`. Chain ID `1337` is the signature domain, not a selectable EVM RPC chain.

The approval digest commits to the direct signer, network, exact action, nonce, vault, and expiry. Changing any of them invalidates the review. Signatures are recovered locally after signing and again before submission, with nonzero `r`, canonical low-`s`, and recovery value checks. Freshness is checked before and after asynchronous signing and immediately before submission.

Submission posts once to `https://api.hyperliquid.xyz/exchange`, with a bounded response, a 15-second timeout, redirects disabled, and no automatic retry. Results distinguish `resting`, `filled`, `partially-filled`, `canceled`, `accepted`, `rejected`, and `unknown`. `accepted` for leverage is an exchange acknowledgment; these results do not assert an independently verified onchain confirmation. A top-level `ok` containing an item error is `rejected`.

A timeout or missing/malformed response is `unknown`: the exchange may already have accepted the action. Do not automatically submit a newly signed replacement. Reconcile orders, fills and account state first. Submission expiry does not cancel an already resting order.

## Reconcile an order

```sh
block-cli call hyperliquid order_status \
  --params '{"user":"0xYOUR_ACCOUNT","orderId":12345}'
```

`orderId` accepts a safe JSON integer exchange order ID or a `0x` plus 32 hexadecimal character client order ID. Supplying a client order ID during preparation lets an agent reconcile an uncertain submission even when no exchange order ID was received. The response verifies the returned ID, limits known orders to default perpetual markets, and reports the exchange's status. `unknownOid` yields `state: "unknown"` and `submissionFailureProven: false`; it does not prove the action failed.

Use `user_fills` for fill records and `account` after leverage changes. An open order can be partially filled; an exchange `resting` acknowledgment alone does not prove there were no fills.

## Isolated margin and spot/perp USDC transfers

`prepare_isolated_margin` requires `user`, `coin`, `nonce`, `expiresAfter`, signed decimal `amountUsd`, and positive `maxAbsoluteAmountUsd`. A positive amount adds isolated margin; a negative amount removes it. Values must represent exact USD6 amounts, without rounding, and the raw signed integer must fit JavaScript's safe integer range. The current wire action pins `isBuy: true` according to the official API; it is currently ignored until hedge mode. Strict-isolated markets reject removal during preparation.

`prepare_usd_class_transfer` requires `user`, positive decimal `amountUsd`, `maxAbsoluteAmountUsd`, `toPerp`, `nonce`, and `acknowledgeNoExchangeExpiry: true`. `toPerp: true` moves the account's USDC from spot to perpetual balance; `false` moves it back. Amounts are exact USD6 strings bounded to u64. There is no recipient, vault, subaccount, bridge, or arbitrary asset option.

Both actions use the same CLI workflow:

```sh
block-cli hyperliquid inspect --file prepared-collateral.json --out collateral-review.json
block-cli hyperliquid sign \
  --file agent-wallet.json \
  --review collateral-review.json \
  --approve "$APPROVAL_DIGEST" \
  --max-collateral-change-usd "$INDEPENDENT_USD_CEILING" \
  --out signed-collateral.json
block-cli hyperliquid submit --file signed-collateral.json
```

The independent local ceiling is required and compares the absolute margin change or transfer amount using exact integer arithmetic. It must be a positive canonical decimal (for example `10`, not `10.0`). Preparing an action does not prove that the wallet owns the account, has sufficient balances or isolated margin, or is eligible for that action in its current account mode.

Isolated margin uses the existing expiry-bound L1 phantom-agent signature. USDC transfers instead use the official SDK's **user-signed** EIP-712 type `HyperliquidTransaction:UsdClassTransfer`, domain `HyperliquidSignTransaction`, version `1`, signing chain ID `421614` (`0x66eee`), and zero verifying contract. `hyperliquidChain: "Mainnet"` is included in the signed data. This domain chain ID does not route an EVM transaction. Dedicated transfer artifacts prevent confusing the two signature schemes.

**The transfer protocol does not support `expiresAfter`.** The local inspector/signer/submitter checks a nonce within five minutes past to one minute ahead, including after asynchronous signing. This local policy cannot make the signature expire at the exchange. Anyone holding a signed artifact may be able to submit it later until its nonce is consumed or rejected by the protocol. The required acknowledgment and review state this explicitly.

After an isolated margin update, use `account`. After a USDC class transfer, compare `spot_balances` and `account`, along with relevant account history. `spot_balances` uses the official `spotClearinghouseState` read, including unified/portfolio account balances, and does not compute transferable funds or prove an individual transfer. An `accepted` result is only exchange acknowledgment; an uncertain response remains `unknown` and never triggers automatic retry.

## Verification

Four deterministic mainnet signature/action-hash vectors were independently generated with official `hyperliquid-python-sdk` version `0.24.0`, using its public test key. They cover orders with and without client IDs, cancellation with an order ID at JavaScript's safe integer limit, and leverage. All include expiry. Tests also cover tampering, wrong keys, low-`s`, action scope, nonce/expiry windows, timeouts, item errors, partial fills, and exact status reconciliation. No funded trading or live financial action was executed during implementation.

Eight additional SDK vectors cover isolated-margin additions/removals up to the supported integer bound and separate user-signed USDC transfers in both directions, including one micro-USDC and the u64 amount boundary. Collateral tests cover independent budgets, exact decimal conversion, signature-domain separation, changing nonces/amounts/signers, stale asynchronous signing, and exact injected submission bodies. Exchange submissions in these tests are mocked.

Read-only live verification on October 20, 2026 fetched current ETH metadata, inspected an unsigned prepared order, and queried a nonexistent client order ID. The status normalized to `unknown`, with no signature or exchange request. Evidence is in `hyperliquid-local-live-v0.10.0.json`.

`hyperliquid-collateral-live-v0.12.0.json` (evidence record in the source checkout) records current ETH metadata preparation/inspection, an actual spot-balance read, and user-transfer preparation/inspection. Exactly two read-only `/info` requests were made; no `/exchange` request or live signature was used.

Official references: [signing](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/signing), [exchange endpoint](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint), [order status](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#query-order-status-by-oid-or-cloid), [Python signing implementation](https://github.com/hyperliquid-dex/hyperliquid-python-sdk/blob/master/hyperliquid/utils/signing.py).
