Prepare the desk computer to work with Hyperliquid - install the SDKs, pick testnet or mainnet, verify connectivity, and (only when the user asks) provision a trade-only API wallet through the secure secret store and verify it is approved. Use during desk setup, when moving between research, testnet and mainnet levels, when a key is rotated, or when any Hyperliquid call fails with an environment problem.
---
name: hyperliquid-setup
description: Prepare the desk computer to work with Hyperliquid - install the SDKs, pick testnet or mainnet, verify connectivity, and (only when the user asks) provision a trade-only API wallet through the secure secret store and verify it is approved. Use during desk setup, when moving between research, testnet and mainnet levels, when a key is rotated, or when any Hyperliquid call fails with an environment problem.
license: MIT
metadata:
version: "1.0.3"
author: Galleon Labs
category: hyperliquid
network-default: testnet
---
# Hyperliquid setup
Sections 1-3 are read-only and safe to run at any time. Section 4 provisions a key and is done only when the user asks to move to a testnet or mainnet desk. Section 5 is the readiness check the Execution Trader runs before its first send.
## 1. Networks
| | Mainnet | Testnet |
| --- | --- | --- |
| REST | `https://api.hyperliquid.xyz` | `https://api.hyperliquid-testnet.xyz` |
| WebSocket | `wss://api.hyperliquid.xyz/ws` | `wss://api.hyperliquid-testnet.xyz/ws` |
| App | `https://app.hyperliquid.xyz` | `https://app.hyperliquid-testnet.xyz` |
| Faucet | - | `https://app.hyperliquid-testnet.xyz/drip` |
Reads (`/info`) need no key. Writes (`/exchange`) need a signing key and are signed differently per network, so a key and its network go together. The desk records the network in `/workspace/trading-desk/desk.md` and in the environment.
Testnet is the default. Nothing on the desk selects mainnet unless `HYPERLIQUID_NETWORK=mainnet` is set on purpose.
## 2. Install
Python (used by most snippets on the desk):
```bash
python3 --version # 3.9+ required, 3.11+ preferred
python3 -m venv ~/.hypergrok/venv
source ~/.hypergrok/venv/bin/activate
python3 -m pip install "hyperliquid-python-sdk==0.24.0"
python3 -c "import hyperliquid, eth_account; print('ok', hyperliquid.__name__)"
```
Activate it with `source ~/.hypergrok/venv/bin/activate` in each new shell before SDK snippets. The public Python tools shipped here need no SDK or activation. These are the versions reviewed on 2026-10-25; review API and snippet compatibility before upgrading them.
Optional TypeScript (if the user prefers TS or wants the WebSocket client from `@nktkas/hyperliquid`):
```bash
node --version # 22.12+ required by @nktkas/hyperliquid (ESM-only)
mkdir -p /workspace/trading-desk/ts && cd /workspace/trading-desk/ts
[ -f package.json ] || npm init -y >/dev/null
npm pkg set type=module >/dev/null # so .js files can use import and top-level await
npm i @nktkas/hyperliquid@0.33.3 viem@2.57.11 decimal.js@10.6.0
node -e "import('@nktkas/hyperliquid').then(m=>console.log('ok', Object.keys(m).length))"
```
`curl` and `jq` are enough for every read in `hyperliquid-market-data` and `hyperliquid-account`; install `jq` if missing.
## 3. Connectivity check (no key)
```bash
for base in https://api.hyperliquid.xyz https://api.hyperliquid-testnet.xyz; do
printf '%s -> ' "$base"
curl -sS -m 10 -X POST "$base/info" -H 'Content-Type: application/json' \
-d '{"type":"allMids"}' | jq -r 'if type=="object" then "ok, \(length) mids, BTC \(.BTC)" else "unexpected: \(.)" end'
done
```
Both lines should read `ok`. Record the time and result in the desk record. If one network fails, the desk is not blind on the other; say which.
## 4. API wallet (only when the user asks to trade)
Before creating or provisioning any key, verify and record native out-of-band approval coverage for the actual SDK, script and HTTP send paths, per `desk-operating-model` and `SETUP.md` section 7. If it cannot be verified, continue research without a key. An existing key or chat approval does not remove this prerequisite.
An **API wallet** (Hyperliquid also calls it an agent wallet) is a separate key the user authorises to sign trading actions for their account. It can place, modify and cancel orders and change leverage and margin; it cannot withdraw to Arbitrum, cannot send USDC or tokens to another wallet, and cannot approve other agents or builders (those need the main wallet's signature). It *can* still move funds inside the user's own account (perp to spot and across dexs via `agentSendAsset`, into sub-accounts and vaults, into staking via `cDeposit2`, and it can spend USDC on `reserveRequestWeight`) and change the account's abstraction mode via `agentSetAbstraction`, all of which the desk forbids by rule. That is the only kind of key that ever reaches the desk computer.
Why: all of the user's Bots share one computer, so anything on it is readable by every Bot. A trade-only key bounds the damage; a seed phrase or main-wallet key would not.
### 4.1 The user creates it in the Hyperliquid app
Guide the user; do not do it for them (it involves their wallet):
1. Open the app for the chosen network (`https://app.hyperliquid.xyz` or `https://app.hyperliquid-testnet.xyz`), connect the main wallet, open the **API** page (`/API`, under **More** in the app's navigation).
2. Generate a new API wallet, give it a name such as `hypergrok-desk`, choose a validity period (a few months is sensible; it can be revoked at any time), and **Authorize**. The app shows the API wallet's private key once. The API wallet's address is shown next to it.
3. On testnet, fund the account from the faucet (`/drip`): it gives 1,000 mock USDC, but only to an address that has deposited on mainnet at some point (email/Privy logins get different addresses per network; export the mainnet wallet into a wallet extension and connect that to testnet). Testnet USDC is not real.
Never ask for the seed phrase or the main wallet's key. If the user offers it, decline and point back to this step.
### 4.2 The user provides the key through the secure secret store
Grok Bot has a secure secret card for exactly this. Ask the user to add a secret named `HYPERLIQUID_PRIVATE_KEY` with the API wallet's private key. Never ask them to paste it in chat and never write it to a file under `/workspace`.
If the desk's Grok Bot setup exposes secrets to the computer as environment variables, scripts read `HYPERLIQUID_PRIVATE_KEY` from the environment. If it does not, the fallback is a file the **user** creates while in control of the computer:
```bash
mkdir -p ~/.hyperliquid && chmod 700 ~/.hyperliquid
# the user pastes the key into this file themselves, then:
chmod 600 ~/.hyperliquid/api-wallet.key
```
Every signing snippet on the desk uses the same loader, which reads the environment first, then that file, and never prints the key:
```python
import os
def load_key():
k = os.environ.get("HYPERLIQUID_PRIVATE_KEY")
if not k:
p = os.path.expanduser("~/.hyperliquid/api-wallet.key")
if os.path.exists(p):
k = open(p).read().strip()
if not k:
raise SystemExit("no API wallet key available - see hyperliquid-setup section 4")
return k
```
### 4.3 Non-secret configuration
Set these for the desk computer's shell (for example in `~/.bashrc`, and mirror them in `desk.md`):
```bash
export HYPERLIQUID_NETWORK=testnet # or mainnet, deliberately
export HYPERLIQUID_ACCOUNT_ADDRESS=0xYourMainAccount # the account the API wallet acts for, NOT the API wallet's address
```
The account address is public. Reads use it; the Execution Trader passes it as `account_address` when signing with the API wallet.
## 5. Readiness check (before the first send)
Run by the Execution Trader; read-only; proves the key belongs to the account on this network without sending anything.
```python
import os, time
import eth_account
from hyperliquid.info import Info
from hyperliquid.utils import constants
def load_key():
k = os.environ.get("HYPERLIQUID_PRIVATE_KEY")
if not k:
p = os.path.expanduser("~/.hyperliquid/api-wallet.key")
if os.path.exists(p):
k = open(p).read().strip()
if not k:
raise SystemExit("no API wallet key available - see hyperliquid-setup section 4")
return k
network = os.environ.get("HYPERLIQUID_NETWORK", "testnet")
base = constants.MAINNET_API_URL if network == "mainnet" else constants.TESTNET_API_URL
account = os.environ["HYPERLIQUID_ACCOUNT_ADDRESS"]
agent_addr = eth_account.Account.from_key(load_key()).address # derived locally, key never printed
info = Info(base, skip_ws=True)
role = info.user_role(agent_addr) # {"role": "agent", "data": {"user": "0x..."}} when approved
agents = info.extra_agents(account) # named agents: [{"address","name","validUntil"}, ...]
named = next((a for a in agents if a["address"].lower() == agent_addr.lower()), None)
acts_for_account = role.get("role") == "agent" and role.get("data", {}).get("user", "").lower() == account.lower()
unexpired = named is None or named["validUntil"] > time.time() * 1000
approved = acts_for_account and unexpired # an unnamed agent is proved by userRole alone
state = info.user_state(account)
print(f"network={network} account={account}")
print(f"api_wallet={agent_addr} role={role.get('role')} approved_for_account={approved}")
for a in agents:
if a["address"].lower() == agent_addr.lower():
print(f"valid_until_ms={a.get('validUntil')} name={a.get('name')}")
print(f"account_value={state['marginSummary']['accountValue']} positions={len(state['assetPositions'])}")
```
Ready means: `role=agent`, `approved_for_account=True`, `validUntil` in the future (when the agent is named and listed), and `account_value` is what the user expects on this network. Anything else: stop and report which line disagrees.
## 6. Rotation and revocation
- Revoke: the user removes the API wallet on the app's `/API` page. Sends from the desk fail immediately afterwards.
- Rotate: revoke, create a new API wallet (4.1), replace the secret (4.2), rerun the readiness check. Journal the time.
- Suspected misuse: revoke first, investigate second (`desk-incident-response` playbook G).
## Pitfalls
- Using the API wallet's address as `HYPERLIQUID_ACCOUNT_ADDRESS`. Reads on the agent's address show an empty account; the account is the main wallet's address.
- Signing for mainnet with a testnet key or vice versa. The signature encodes the network; the exchange rejects the mismatch, but the desk should never get that far.
- Installing the SDK into a temporary environment or forgetting to activate it in a new shell. Keep `~/.hypergrok/venv`; re-run section 2 if that directory is lost after a computer refresh.
- `Info(...)` performs network calls on construction; pass `skip_ws=True` unless you want the WebSocket thread.
- Printing environment variables while debugging. Redact anything that could be the key.
don't have the plugin yet? install it then click "run inline in claude" again.
set up the desk computer to trade on Hyperliquid testnet or mainnet. installs SDKs, picks a network, verifies you can reach the Hyperliquid API without credentials, then (only if you ask) provisions a trade-only API wallet via the secret store and confirms it's approved for your account. run this at initial desk setup, when switching networks or research levels, after key rotation, or when a Hyperliquid call fails with an env problem.
HYPERLIQUID_NETWORK env var.https://api.hyperliquid.xyz (mainnet) or https://api.hyperliquid-testnet.xyz (testnet). read-only calls (e.g. /info) work without auth. write calls (e.g. /exchange) require a signed request with an api wallet key.https://app.hyperliquid.xyz (mainnet) or https://app.hyperliquid-testnet.xyz (testnet). used only to create the api wallet (you do this, not the script).HYPERLIQUID_PRIVATE_KEY. if grok bot's setup exposes secrets as env vars, it reads from there. if not, fallback is ~/.hyperliquid/api-wallet.key.https://app.hyperliquid-testnet.xyz/drip. dispenses 1000 mock usdc per drip, once per address.Info, Exchange, and signing utils./info are generous; writes are tighter. if you hit limits, back off and retry with exponential delay.validUntil timestamp. after that time, the key no longer works. check it in the readiness check; if expired, rotate the key.-m 10 (10 second timeout). if you see timeouts, the desk is not blind; you can still use the other network.input: your choice of testnet or mainnet.
output: HYPERLIQUID_NETWORK env var is set (or already set if unchanged).
set this in your shell (e.g., ~/.bashrc) and in /workspace/trading-desk/desk.md:
export HYPERLIQUID_NETWORK=testnet # or mainnet, deliberately
testnet is the default. mainnet is never selected unless you explicitly set this var. once set, every script on the desk uses this value.
input: python 3.9+.
output: hyperliquid-python-sdk >=0.24 is installed and importable.
python3 --version # confirm 3.9+, prefer 3.11+
python3 -m pip install --user --upgrade "hyperliquid-python-sdk>=0.24,<1" \
|| python3 -m pip install --break-system-packages --upgrade "hyperliquid-python-sdk>=0.24,<1"
python3 -c "import hyperliquid, eth_account; print('ok', hyperliquid.__name__)"
if the first pip call fails (e.g., due to system-wide pip lock), the second invocation forces install anyway. if imports print "ok hyperliquid", you are done.
input: node 22.12+, npm (optional).
output: @nktkas/hyperliquid and viem are installed (optional; skip if you prefer python).
only run this if you plan to use TypeScript or need the nktkas WebSocket client.
node --version # confirm 22.12+
mkdir -p /workspace/trading-desk/ts && cd /workspace/trading-desk/ts
[ -f package.json ] || npm init -y >/dev/null
npm pkg set type=module >/dev/null # enables import in .js files
npm i @nktkas/hyperliquid viem
node -e "import('@nktkas/hyperliquid').then(m=>console.log('ok', Object.keys(m).length))"
if the last command prints "ok" and a count, you are ready for TypeScript.
input: curl, jq, internet connectivity.
output: at least one of mainnet or testnet responds with market data (confirms both are reachable).
for base in https://api.hyperliquid.xyz https://api.hyperliquid-testnet.xyz; do
printf '%s -> ' "$base"
curl -sS -m 10 -X POST "$base/info" -H 'Content-Type: application/json' \
-d '{"type":"allMids"}' | jq -r 'if type=="object" then "ok, \(length) mids, BTC \(.BTC)" else "unexpected: \(.)" end'
done
each line should print ok, <N> mids, BTC <price>. record the time and result in desk.md. if one network times out or returns an error, note which one is down; the desk is not blind on the other.
input: your desk's operating model and section 7 of SETUP.md.
output: written confirmation that the SDK, script, and HTTP send paths are approved by your oversight.
before creating or storing any API key, verify with your desk operating model (or chat with your ops contact) that:
if you cannot confirm this, do not proceed. continue research and reading without a key. an existing key or a chat message does not substitute for this check.
input: main wallet connected to the hyperliquid app.
output: api wallet address and private key (shown once in the app).
do this yourself in the app. the script never touches your wallet. follow these steps:
https://app.hyperliquid.xyz (mainnet) or https://app.hyperliquid-testnet.xyz (testnet).hypergrok-desk. choose a validity period (a few months is standard; can be revoked anytime). click Authorize.if testnet: after creating the wallet, go to /drip and claim 1000 mock USDC. if the faucet says "not eligible", it means your mainnet address has never deposited; export your mainnet wallet to a browser extension, connect it to testnet, and try again.
never share your seed phrase or main wallet key. if you accidentally offer it, the script will refuse it.
input: api wallet private key from step 6.
output: HYPERLIQUID_PRIVATE_KEY is stored securely and readable by the desk.
use the grok bot secure secret card to add a new secret named HYPERLIQUID_PRIVATE_KEY with the value you copied in step 6. never paste it into chat and never write it to a file under /workspace.
if grok bot setup exposes secrets as environment variables, the loader reads from the env. if not, the fallback is a file you create manually:
mkdir -p ~/.hyperliquid && chmod 700 ~/.hyperliquid
# paste the private key into the file yourself:
echo "0xyourprivatekey" > ~/.hyperliquid/api-wallet.key
chmod 600 ~/.hyperliquid/api-wallet.key
every signing snippet on the desk uses this loader:
import os
def load_key():
k = os.environ.get("HYPERLIQUID_PRIVATE_KEY")
if not k:
p = os.path.expanduser("~/.hyperliquid/api-wallet.key")
if os.path.exists(p):
k = open(p).read().strip()
if not k:
raise SystemExit("no API wallet key available - see hyperliquid-setup section 4")
return k
input: your main wallet address (public).
output: HYPERLIQUID_ACCOUNT_ADDRESS is set in the shell and in desk.md.
add this to your shell config (e.g., ~/.bashrc) and mirror it in desk.md:
export HYPERLIQUID_ACCOUNT_ADDRESS=0xYourMainAccountAddress # NOT the api wallet address
the account address is public. every read and write uses it to identify which account to query or trade for. the api wallet signs on behalf of this account; the two addresses are different.
input: HYPERLIQUID_PRIVATE_KEY, HYPERLIQUID_NETWORK, HYPERLIQUID_ACCOUNT_ADDRESS all set.
output: confirmation that the api wallet is approved, valid, and acts for your account.
save this script and run it:
import os
import eth_account
from hyperliquid.info import Info
from hyperliquid.utils import constants
def load_key():
k = os.environ.get("HYPERLIQUID_PRIVATE_KEY")
if not k:
p = os.path.expanduser("~/.hyperliquid/api-wallet.key")
if os.path.exists(p):
k = open(p).read().strip()
if not k:
raise SystemExit("no API wallet key available - see hyperliquid-setup section 4")
return k
network = os.environ.get("HYPERLIQUID_NETWORK", "testnet")
base = constants.MAINNET_API_URL if network == "mainnet" else constants.TESTNET_API_URL
account = os.environ["HYPERLIQUID_ACCOUNT_ADDRESS"]
agent_addr = eth_account.Account.from_key(load_key()).address
info = Info(base, skip_ws=True)
role = info.user_role(agent_addr)
agents = info.extra_agents(account)
listed = any(a["address"].lower() == agent_addr.lower() for a in agents)
acts_for_account = role.get("role") == "agent" and role.get("data", {}).get("user", "").lower() == account.lower()
approved = acts_for_account or listed
state = info.user_state(account)
print(f"network={network} account={account}")
print(f"api_wallet={agent_addr} role={role.get('role')} approved_for_account={approved}")
for a in agents:
if a["address"].lower() == agent_addr.lower():
print(f"valid_until_ms={a.get('validUntil')} name={a.get('name')}")
print(f"account_value={state['marginSummary']['accountValue']} positions={len(state['assetPositions'])}")
check that:
role=agent.approved_for_account=True.valid_until_ms is in the future (if the agent is named and listed).account_value matches what you expect on this network.if any line disagrees, stop and report which one before sending anything.
if you have not yet decided to trade: run steps 1-4 only. these are read-only, safe, and always allowed. you can come back to step 5 later.
if you decide to trade (step 5 onwards):
/workspace.HYPERLIQUID_NETWORK is already set and locked to mainnet, you are trading real money. if testnet, you are trading mock funds only.if the readiness check fails:
role != agent: the key is not approved as an agent for your account. go back to the app and check that the api wallet is authorized. then rerun step 9.approved_for_account=False: the key's address does not match your account's agents. regenerate or check that the secret store has the correct private key.valid_until_ms in the past: the key has expired. rotate (see rotation below).account_value is 0 or wrong: on testnet, fund from the faucet. on mainnet, check that you have deposited and your main wallet is connected correctly.if a hyperliquid call fails with an env error (e.g., "no agent found", "signature invalid", "network error"):
HYPERLIQUID_NETWORK matches the network the key was created on (testnet key cannot sign for mainnet and vice versa).HYPERLIQUID_ACCOUNT_ADDRESS is the main account, not the api wallet address.HYPERLIQUID_PRIVATE_KEY is set and readable.if you suspect the key has been compromised: revoke it immediately in the app, then investigate per the desk incident response playbook.
HYPERLIQUID_NETWORK env var is set to testnet or mainnet and persisted in ~/.bashrc or equivalent.import hyperliquid, eth_account returns no error./workspace/trading-desk/desk.md.HYPERLIQUID_PRIVATE_KEY is stored in the secret store (env var or ~/.hyperliquid/api-wallet.key).HYPERLIQUID_ACCOUNT_ADDRESS env var is set to the main account address and persisted in ~/.bashrc.role=agent, approved_for_account=True, valid_until_ms in the future (if listed), and account_value as expected./workspace or printed to stdout.readiness check passes: the readiness check prints all expected values with no errors. role=agent and approved_for_account=True both appear. you can proceed to send.
connectivity is confirmed: both networks (or at least the target network) respond to the connectivity check with market data and a recent BTC price. no timeout or connection error.
trade-only key is secured: the private key is stored in the secret store and is not readable as plain text from disk or env (unless the secret store explicitly exposes it, which is by design).
no key is leaked: grep the entire /workspace dir for the api wallet address or any part of the private key. you find nothing.
next send will work: the readiness check