Builder hub

Trade on Hyperliquid
from Solidity

Three steps, one contract, one API. Your contract sends an order to the lane, Onbook signs it as the account's trade-only agent, and Hyperliquid's answer comes back to your contract.

Quick start

Three steps

1 · Import
// 1. Get the two files (or copy them from /sol/)
// CoreActions.sol · encodes orders exactly like CoreWriter
// IKeeperLane.sol · the lane's interface
import {CoreActions} from "./CoreActions.sol";
import {IKeeperLane} from "./IKeeperLane.sol";
2 · Send an order
// 2. Point it at your account, once
// (your account must have granted this contract):
lane.setDefaultAccount(yourAddress);
// Build the order. Or let the API do it:
// GET /api/v1/encode?coin=HYPE&side=buy&price=66.2&size=1&tif=ioc
bytes memory order = CoreActions.limitOrder(
159, // HYPE perp (asset ids: /api/v1/markets)
true, // buy
66_20000000, // price, 1e8-scaled
1_00000000, // size, 1e8-scaled
false, // reduceOnly
CoreActions.TIF_IOC,
0 // cloid: 0 lets the keeper derive one
);
uint64 nonce = lane.sendRawAction(order);
3 · Hear back
// 3. Hear back. Once, from your contract:
lane.setCallbackGas(60_000);
// then anyone prepays the callbacks:
lane.deposit{value: 0.002 ether}(address(this));
function onCoreResult(uint64 nonce, uint8 status, uint64 oid,
uint64 filledSz, uint64 avgPx) external {
require(msg.sender == address(lane));
// 2 resting · 3 filled · 4 partly filled · 5 refused · 6 cancelled
}

Public API

Ask for the exact bytes,
read every result

No key, CORS open, JSON. Markets and their rules, ready-to-send CoreWriter bytes, the lane's live state, and the keeper's numbers. Pick an endpoint and press Send.

One market: its CoreWriter asset id, size decimals, max price decimals and live prices.

GET /api/v1/markets/HYPE
Press Send: this calls the live API and shows its real answer.

Starter contract

A vault that buys HYPE
and hears back

Deploy it on Elysium, grant it from your account with a $10 limit, call useAccount with your address, then buy, and watch Filled come back.

MyVault.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {CoreActions} from "./CoreActions.sol";
interface IKeeperLane {
function sendRawAction(bytes calldata data) external returns (uint64 nonce);
function setCallbackGas(uint32 gas) external;
function setDefaultAccount(address account) external;
}
/// Buys HYPE on Hyperliquid from Elysium, and hears back when it fills.
/// 1. Deploy it. 2. From your wallet, grant it on the lane with a $10 limit.
/// 3. Call useAccount(yourAddress). 4. Call buy. 5. Watch Filled.
contract MyVault {
IKeeperLane constant LANE = IKeeperLane(0xfaF3501406e6694e929e3B8c46695DDD56904E9D);
uint32 constant HYPE = 159; // perp asset id, see /api/v1/markets
address public immutable owner = msg.sender;
event Filled(uint64 nonce, uint64 size, uint64 avgPx);
constructor() {
LANE.setCallbackGas(60_000); // so the lane calls onCoreResult
}
/// Trade this HyperCore account (it must have granted this contract first).
function useAccount(address account) external {
require(msg.sender == owner, "owner only");
LANE.setDefaultAccount(account);
}
function buy(uint64 pxE8, uint64 szE8) external returns (uint64) {
require(msg.sender == owner, "owner only");
// 1e8-scaled: 66.20 USD = 66_20000000, 1 HYPE = 1_00000000
bytes memory order = CoreActions.limitOrder(HYPE, true, pxE8, szE8, false, CoreActions.TIF_IOC, 0);
return LANE.sendRawAction(order);
}
function onCoreResult(uint64 nonce, uint8 status, uint64, uint64 filledSz, uint64 avgPx) external {
require(msg.sender == address(LANE), "only the lane");
if (status == 3) emit Filled(nonce, filledSz, avgPx); // 3 = filled
}
}

Addresses

Point your contract here

The lane's live state, owner, keeper and fee are at /api/v1/lane. Kinetiq's native lane will sit at the last address once their upgrade ships.

ChainElysium mainnet · 99901
RPChttps://rpc.elysium.kinetiq.xyz
KeeperLane0xfaF3501406e6694e929e3B8c46695DDD56904E9D
Playground0x6F43BF56c6ef654631e8839846115549Dbe7c272
Kinetiq's native lane0x3333333333333333333333333333333333333333
Rules the lane enforces, so your contract should too: limit orders and cancels only; price at most 5 significant figures and 6 minus the market's size decimals; size at most the market's size decimals; within the account's limits. The API refuses anything else rather than rounding it.