Sell a watch
Sell a watch that runs for days, posts the matches it finds, and lets the buyer pay one day at a time or stop early.
A watch is a job you can sell on dvmkit that runs for days and posts the matches it finds. The buyer pays for the first day up front. The watch asks for payment before each later day. The buyer chooses when the standing limit ends, how much it can spend in total, and how much any one charge can be. The buyer’s agent signs that limit. Declining charges only finished days, while cancelling also charges the day in progress.
The buyer is what the rest of these docs call the caller. The standing limit is what the dvm CLI calls a standing mandate, and the caller’s agent uses these flags to set it.
| Part of the limit | Flag | In the example below |
|---|---|---|
| When it ends | --mandate-until | 15d, a day past the 14-day watch |
| Requested budget | --budget | $0.75 |
| Most any one charge can be | --auto-pay-below | $0.05, one day |
The signed total in this example is $0.70 for 14 payments capped at $0.05 each.
The buyer can choose how long the limit lasts. The example DVM advertises no ceiling on it (credit.mandate_max_duration is null on its /v1/info). A limit is never renewed: once it ends, the next day's ask waits for the caller to pay by hand.
The example: earthquake alerts
quake-watch checks the public USGS earthquake catalog for events at or above the magnitude the caller picks. It posts matches found by successful polls. It runs at https://dvmkit--quake-watch.dvmkit.ai with one capability, watch. It is hidden from the directory, so you reach it by its address.
It charges $0.05 a day. The default watch is 14 days, which costs $0.70 in total. It checks the catalog four times a day by default. A failed or late poll can delay a match, and a watch can miss matches if its final poll and retries fail. The buyer retrieves posted messages separately.
| Input field | Range | Default |
|---|---|---|
min_magnitude | 2.5 to 9 | 4.5 |
periods | 1 to 30 whole periods | 14 |
period_seconds | 600 to 86400 whole seconds (10 minutes to one day) | 86400 (one day) |
polls_per_period | 1 to 24 whole polls | 4 |
This DVM takes ecash only. The rules for what each day costs and when it is charged are the SDK's, and they are the same on every rail it supports (charging by the piece). The runs on this page all paid with ecash.
The handler
This is the whole handler, copied from the deployed DVM:
import { configureDVM, type DVMDescriptor } from "@dvmkit/sdk";
import { secp256k1Auth } from "@dvmkit/sdk/server";
import { z } from "zod";
const input = z
.object({
pubkey: z
.string()
.regex(/^[0-9a-f]{64}$/)
.optional(),
signature: z
.string()
.regex(/^[0-9a-f]{128}$/)
.optional(),
timestamp: z.number().int().optional(),
nonce: z
.string()
.regex(/^[a-zA-Z0-9_-]{8,64}$/)
.optional(),
min_magnitude: z.number().min(2.5).max(9).default(4.5),
periods: z.number().int().min(1).max(30).default(14),
period_seconds: z.number().int().min(600).max(86400).default(86400),
polls_per_period: z.number().int().min(1).max(24).default(4),
})
.strict();
const lookbackMs = 2 * 60 * 60 * 1000;
const feed = z.object({
features: z.array(
z.object({
id: z.string(),
properties: z.object({
ids: z.string().default(""),
mag: z.number(),
place: z.string().nullable(),
time: z.number(),
url: z.string(),
}),
})
),
});
export function createQuakeWatchDVM(): DVMDescriptor<Record<string, unknown>, typeof input> {
const usd = process.env.DVMKIT_QUAKE_WATCH_PERIOD_PRICE_USD ?? "0.05";
return configureDVM<Record<string, unknown>, typeof input>({
name: "quake-watch",
description: "Get earthquake alerts at or above a magnitude you choose.",
capability: "watch",
auth: secp256k1Auth(),
idleTimeout: 172800,
credit: { min: `$${usd}`, max: `$${(Number(usd) * 30).toFixed(4)}` },
price: `$${usd}`,
input,
async onJob(ctx) {
const { min_magnitude, periods, period_seconds, polls_per_period } = ctx.input;
const price = await ctx.step("price", () => Promise.resolve(Number(usd)));
const t0 = await ctx.step("t0", () => Promise.resolve(Date.now()));
const periodMs = period_seconds * 1000;
const seen = new Set<string>();
let previousSuccessfulPoll = t0;
let matches = 0;
for (let p = 1; p <= periods; p++) {
for (let i = 1; i <= polls_per_period; i++) {
const pollTime = t0 + (p - 1) * periodMs + Math.floor((i * periodMs) / polls_per_period);
await ctx.sleepUntil(`p${p}-i${i}`, pollTime);
const fetchWindow = () =>
fetchUsgs(
ctx.fetch,
Math.max(t0, previousSuccessfulPoll - lookbackMs),
pollTime,
min_magnitude
);
let result = await ctx.step(`poll:${p}:${i}`, fetchWindow);
if (result.failed) {
const percent = (100 * ((p - 1) * polls_per_period + i)) / (periods * polls_per_period);
ctx.progress(percent, "poll", `USGS poll ${i} of period ${p} failed.`);
if (i === polls_per_period) {
for (let k = 1; k <= 3 && result.failed; k++) {
await ctx.sleep(`p${p}-r${k}`, 60_000);
result = await ctx.step(`poll:${p}:r${k}`, fetchWindow);
}
if (result.failed)
ctx.progress(percent, "poll", `Could not fetch the end of period ${p}.`);
}
if (result.failed) continue;
}
previousSuccessfulPoll = pollTime;
for (const { ids, ...hit } of result.hits) {
const aliases = [hit.id, ...ids.split(",").filter(Boolean)];
const duplicate = aliases.some((id) => seen.has(id));
for (const id of aliases) seen.add(id);
if (duplicate) continue;
matches++;
ctx.artifact({ data: JSON.stringify(hit), mime_type: "application/json" });
ctx.text(`M${hit.mag} earthquake — ${hit.place ?? "location unavailable"}`);
}
}
if (p < periods) {
await ctx.requestPayment(
{ amount: price, currency: "usd" },
`Period ${p + 1} of ${periods}`
);
}
}
ctx.complete(`Watched ${periods} periods and found ${matches} matching earthquakes.`);
},
});
}
async function fetchUsgs(
fetch: typeof globalThis.fetch,
start: number,
end: number,
magnitude: number
) {
const url = new URL("https://earthquake.usgs.gov/fdsnws/event/1/query");
url.search = new URLSearchParams({
format: "geojson",
starttime: new Date(start).toISOString(),
endtime: new Date(end).toISOString(),
minmagnitude: String(magnitude),
}).toString();
try {
const response = await fetch(url, {
redirect: "error",
signal: AbortSignal.timeout(20_000),
});
if (!response.ok) return { hits: [], failed: true };
const { features } = feed.parse(await response.json());
return { hits: features.map(({ id, properties }) => ({ id, ...properties })), failed: false };
} catch {
return { hits: [], failed: true };
}
}The rest of this section explains the SDK calls a seller has to understand. The SDK reference has the exact semantics of each.
Paying one day at a time
The upfront price buys day 1. At the end of each day except the last, the handler calls ctx.requestPayment for the next day. That ask marks the current day finished. The SDK settles the charges when the job ends. The next day’s work starts only once the ask is paid. An ask can be paid automatically if there’s enough prepaid balance, the standing limit is still valid, and the payment fits within its caps.
Each ask is a separate payment from the upfront one. See how mid-job payments work.
idleTimeout: 172800 gives the caller two days to pay an ask by hand. If nobody pays by then, the job is cancelled and only the finished days are charged.
Paying from a balance needs signed callers and prepaid credit, which is why the handler sets auth: secp256k1Auth() and a credit block. Its credit block sets one day's price as the smallest amount a caller can fund and 30 days' worth, the longest watch it sells, as the most a balance can hold.
Sleeping between checks
ctx.sleepUntil(id, at) parks the job until a set time, and ctx.sleep(id, ms) parks it for a set length. After a failed poll, the next attempt starts from the last successful poll with up to two extra hours of overlap, bounded by the watch’s start time. At the end of a period, the handler uses ctx.sleep to wait 60 seconds before each of up to three retries. If those retries fail, it reports the gap. A later period can still recover it.
These waits are durable: the first run records the deadline, and the job stays working while it sleeps. Nothing holds a connection open for days. See durable waits for what the host needs.
Surviving a restart
The handler uses ctx.step for the price, the start time, and each USGS poll. On replay, the SDK reuses saved step results. If a result failed to save, the step can run again. See durable steps.
Once the processing watchdog adopts a sleeping job, the SDK runs onJob again from the top. It skips finished waits and reuses paid asks. The handler rebuilds the seen set from poll results and emits messages in the same order on replay so the SDK can skip messages it already posted.
This is why the step and sleep IDs (poll:3:2, p3-i2) must stay the same while a job is running. A new version that renamed them would not find a sleeping job's saved results.
Recording the price as a step lets the SDK reuse the job’s saved price after a change to the DVM’s price.
Posting each match
For each match the watch finds for the first time, ctx.artifact posts the match as JSON (id, mag, place, time, and url) and ctx.text posts a one-line alert. Each is a job message with its own sequence number, which is how the caller reads only what is new. ctx.progress reports a failed check without ending the job, and ctx.complete ends it after the last day.
ctx.fetch is aborted when the job is cancelled, so a cancel stops any USGS call in flight.
What the buyer runs
The buyer's agent uses the dvm CLI. These are the commands we ran against the deployed DVM.
Fund a balance
For this DVM, the buyer needs ecash in their wallet before funding. The agent loads $0.70 into prepaid credit to cover all 14 days. Day 1 costs $0.05.
dvm credit fund dvmkit--quake-watch --amount '$0.70' --over-trustBy default, the CLI caps credit at $0.50 until the buyer has three verifiably completed jobs at this DVM. Buyers still subject to that cap need --over-trust to load $0.70. Without it, the CLI refuses the funding request with amount_exceeds_trust_tier. See the trust ladder.
Preview the limit, then submit
Add --dry-run to preview the limit. The CLI reads provider information without signing the limit or submitting the job.
dvm request -d dvmkit--quake-watch/watch --data '{"min_magnitude":4.5,"periods":14}' --budget '$0.75' --auto-pay-below '$0.05' --max-payments 14 --mandate-until 15d --no-stream --dry-runSubmit without --dry-run to compute and sign a fresh limit, with a new expiry 15 days from submission.
dvm request -d dvmkit--quake-watch/watch --data '{"min_magnitude":4.5,"periods":14}' --budget '$0.75' --auto-pay-below '$0.05' --max-payments 14 --mandate-until 15d --no-streamTo carry the previewed limit into the live submit, replace --mandate-until 15d with --mandate-preview <approval>. Pass the dry run’s mandate.approval as the value. Live limits can lower the signed amounts. See preview a standing credit mandate.
--max-payments 14 allows day 1 plus 13 asks. --no-stream returns the job ID without waiting for the watch to finish.
Read the matches
dvm messages <job> --no-stream --after <seq>Every message has a sequence number. Pass the last one the agent has seen as --after, and only newer messages come back. Without --after, --no-stream replays the job's messages from the start.
Stop early
dvm decline <job>A decline sent between payment asks under a standing limit takes effect at the next ask; a decline of an ask that is already open takes effect at once. The handler makes no further ask on the final day, so the watch finishes normally if you decline then.
| What the buyer does | When the job ends | Charged |
|---|---|---|
| Declines an open payment ask | Immediately | Finished days |
| Declines under a standing limit while the watch sleeps | At the next ask, before payment for a new day. On the last day, at normal completion | Finished days, including the day that just finished |
Runs dvm cancel | Immediately | Finished days and the day in progress |
Limits
- Each day is paid in advance. Day 1 is paid when the job starts. Each later day is asked for at the boundary before it begins.
- A restart in the short awake interval between sleeps can fail the job. A failed job keeps the finished days charged and releases the day in progress (charging by the piece).
What we have run
2026-11-24, a shortened rehearsal on dvmkit hosting. The price was $0.01 a period. The 14-period job used 15-minute periods, and the two early-stop jobs used 10-minute periods. The jobs used their own inputs, not the sample command above.
- A 14-period watch completed and charged exactly 14 periods. It posted three USGS matches during the run (M3.8 near the US Virgin Islands, M4.7 in Turkey, and M4.2 in Alaska).
- We restarted the machine mid-period while the job was asleep. The job resumed on the new process and was not charged twice.
- Declining an open payment ask stopped a job after 1 period, charging 1.
- Stopping under a standing limit ended a job at the next boundary, charging only the 2 periods it had used.
- Reading with
--after 7returned exactly the messages after sequence number 7.
2026-11-25. A 14-day run at the real price, $0.05 a day, started on the hosted DVM. We will update this page at day 7 and at day 14.
The 14-period job’s signed receipt bundle contains the CLI’s verification output. The receipt signature and builder attestation verify. The signed settlement lists all 14 charges at $0.01 each, totaling $0.14. The bundle reports result_hash: unchecked. Verifying the match artifacts would require a separate check.
Sell your own
Start from this handler. Replace fetchUsgs with your own source and the alert text with yours. Keep the polls inside ctx.step, make their requests through ctx.fetch, and set the price for one day.
For durable waits, run SDK 0.46.0 or later on a container host backed by Postgres. Keep the processing watchdog enabled and a worker running so it can pick up sleeping jobs.
To try it locally, run dvmctl dev handler.ts with dvmctl 0.20.2 or later, which serves SDK 0.46.0. Under dev a sleep is an in-process timer, so it does not survive a restart. To exercise a restart mid-sleep, point DATABASE_URL at local Postgres and run dvmctl serve, or start the server from your own createDVMHost entry point.