Skip to content
Mainnet Live. All executions, addresses and hashes are live.
WORMHOOK
skeletonv0.1 · skeleton docs

Calling IMD Research from Solana

The reference integration. How IMDHOOKS starts an IMD research job and gets the result hash back on Solana.

The flow

  1. A user in IMDHOOKS asks for a research job and approves a budget.
  2. IMDHOOKS sends a HookCall: imd.research.v1 → START_RESEARCH, maxSpend = budget.
  3. On Ethereum, the gateway verifies the call and dispatches to the IMD Adapter, which queues the job.
  4. The receipt returns to Solana with the job ID's output hash and the amount reserved.
  5. IMDHOOKS shows the job as accepted and links to the execution.

Walk through the HookCall #18291 demo execution to see every stage.

Code

imdhooks/start-research.ts
import { WormHookClient } from "@wormhook/sdk";

const client = new WormHookClient({ network: "mainnet-beta", appId: IMDHOOKS_PROGRAM_ID });

export async function startResearch(query: string, budget: string) {
  const call = await client.prepareCall({
    hookId: "imd.research.v1",
    action: "START_RESEARCH",
    payload: { query, depth: "standard", budget, tag: `imdhooks:${sessionId()}` },
    maxSpend: budget,          // ≤ 250 IMD per-call cap on this hook
    ttl: 900,
  });

  const execution = await client.simulate(call);    // send() in phase 2
  const receipt = await execution.waitForReceipt();

  switch (receipt.status) {
    case "success": return { ok: true, callId: call.callId, outputHash: receipt.outputHash, spent: receipt.amountSpent };
    case "failed":  return { ok: false, callId: call.callId, reason: receipt.revertReason };
    case "partial": throw new Error("unreachable: research jobs are atomic");
  }
}

Budgets

  • budget in the payload and maxSpend on the call must agree. The adapter reverts if the payload asks for more than the call allows.
  • The hook's per-call cap is 250 IMD; IMDHOOKS' daily cap is 50,000 IMD (demo values).
  • The receipt reports the amount reserved at execution. Final settlement happens when the job completes, outside the receipt.

What can go wrong

SituationYou'll seeDemo
Budget above what the app has availablefailed receipt, WH-401, revert BudgetExceededdemo-reverted
Executor slow, call outlives TTLfailed receipt, WH-201demo-expired
Executor slow, still within TTLrelaying · delayed, WH-202demo-relay-pending