v4.0Launch App
Developers

SDK Reference

The @hookos/sdk package provides a TypeScript client for interacting with all HookOS contracts. It wraps ethers.js and handles encoding, gas estimation, and event parsing.

Installation

bash
npm install @hookos/sdk ethers

Initialization

typescript
import { HookOS } from "@hookos/sdk";
import { ethers } from "ethers";

const hookos = new HookOS({
  signer: yourSigner,
  network: "ethereum", // or "sepolia", "base", "arbitrum"
});
i
All write methods require a signer. Read-only methods work with just a provider.

hookos.tokens

Methods for creating and querying tokens.

MethodReturnsDescription
create(opts)TokenResultDeploy a new HookToken via TokenFactory
get(address)TokenInfoGet token details including attached hooks
byCreator(address)TokenInfo[]List all tokens created by an address
search(query)TokenInfo[]Search tokens by name, symbol, or attributes
tokens.create()
interface CreateTokenOptions {
  name: string;
  symbol: string;
  initialSupply: bigint;
  metadataURI?: string;
}

interface TokenResult {
  address: string;
  txHash: string;
  blockNumber: number;
}

hookos.hooks

Methods for registering, attaching, and querying hooks.

MethodReturnsDescription
register(opts)stringRegister a hook on-chain, returns hook ID
attach(opts)TxResultAttach a hook to a token at a specific hook point
detach(opts)TxResultRemove a hook from a token
list(token)HookBinding[]List all hooks attached to a token
get(hookId)HookInfoGet hook metadata and stats
browse(filters)HookInfo[]Browse the hook marketplace
hooks.register()
interface RegisterHookOptions {
  name: string;
  category: string;
  implementation: string; // deployed contract address
  metadataURI: string;
}

interface HookBinding {
  hookId: string;
  hookPoint: HookPoint;
  gasLimit: number;
  active: boolean;
}

type HookPoint =
  | "beforeSwap"
  | "afterSwap"
  | "beforeAddLiquidity"
  | "afterAddLiquidity"
  | "beforeRemoveLiquidity"
  | "afterRemoveLiquidity";

hookos.arena

Methods for PvP battles and wagering.

MethodReturnsDescription
create(opts)BattleResultCreate a new battle between two tokens
wager(opts)TxResultPlace a wager on a battle side
settle(id)TxResultSettle a completed battle
claim(id)bigintClaim winnings from a settled battle
cancel(id)TxResultCancel a battle before it starts

hookos.fees

Methods for querying fee distributions.

MethodReturnsDescription
getShares()FeeSharesGet current fee split configuration
pending(address)bigintCheck unclaimed fees for an address
claim()TxResultClaim pending fee rewards

Error handling

The SDK throws typed errors for common failure modes.

typescript
import { HookOSError, InsufficientGasError } from "@hookos/sdk";

try {
  await hookos.tokens.create({ ... });
} catch (err) {
  if (err instanceof InsufficientGasError) {
    console.error("Not enough gas:", err.required);
  } else if (err instanceof HookOSError) {
    console.error("HookOS error:", err.code, err.message);
  }
}

Events

Subscribe to on-chain events using the SDK event listener.

typescript
hookos.on("TokenCreated", (event) => {
  console.log("New token:", event.tokenAddress);
});

hookos.on("HookExecuted", (event) => {
  console.log("Hook fired:", event.hookId, event.success);
});

hookos.on("BattleSettled", (event) => {
  console.log("Winner:", event.winner);
});