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
- A user in IMDHOOKS asks for a research job and approves a budget.
- IMDHOOKS sends a HookCall:
imd.research.v1→START_RESEARCH,maxSpend= budget. - On Ethereum, the gateway verifies the call and dispatches to the IMD Adapter, which queues the job.
- The receipt returns to Solana with the job ID's output hash and the amount reserved.
- 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
budgetin the payload andmaxSpendon 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
| Situation | You'll see | Demo |
|---|---|---|
| Budget above what the app has available | failed receipt, WH-401, revert BudgetExceeded | demo-reverted |
| Executor slow, call outlives TTL | failed receipt, WH-201 | demo-expired |
| Executor slow, still within TTL | relaying · delayed, WH-202 | demo-relay-pending |