Skip to content

Delegator workflow

As a delegator, you define the task, fund its maximum reward, and choose the signed bid that becomes the on-chain agreement.

The transaction fragments below use ethers v6 contract instances connected to the delegator’s signer. Values such as specHash, inputHash, amounts, deadlines, and specURI come from the task prepared in step 1.

Prepare the complete TaskSpec and task input off-chain. For STATS_V1:

  • canonicalize the TaskSpec with RFC 8785 JCS, then compute specHash = keccak256(JCS(taskSpec));
  • encode the uint64[] input with abi.encode, then compute inputHash = keccak256(abi.encode(values));
  • express every USDC amount as an integer with 6 decimals; and
  • choose acceptDeadline, maxComputeWindowSec, and a minBondUSDC at or above the hub’s current minimum.

See TaskSpec commitments and STATS_V1 for the exact encodings.

Approve the hub to transfer maxRewardUSDC, then create the task:

await (await usdc.approve(hubAddress, maxRewardUSDC)).wait();
const receipt = await (
await hub.createTask(
specHash,
statsV1VerifierId,
inputHash,
maxRewardUSDC,
minBondUSDC,
acceptDeadline,
maxComputeWindowSec,
specURI
)
).wait();

Read TaskCreated from the receipt to obtain the taskId. The hub holds the maximum reward in USDC and snapshots the active verifier for that task.

Receive bids off-chain and confirm each bid matches the created task:

  • taskId, specHash, and verifierId match the on-chain task;
  • rewardUSDC, bondUSDC, and computeWindowSec match the terms you want;
  • validUntil is current; and
  • nonce matches bidNonce[delegatee].

The delegatee signs the exact EIP-712 bid. Review signed bids for the domain and field order.

Encrypt the task key for the chosen delegatee and call:

await (
await hub.selectBid(taskId, bid, delegateeSignature, encryptedKey)
).wait();

Selection records the reward, bond, compute window, and fee snapshot. The hub immediately returns maxRewardUSDC - rewardUSDC to you and keeps the selected reward in escrow. TaskSelected carries the encrypted key for the delegatee, which retains control of activation.

Watch the task and its lifecycle events:

  • TaskActivated starts the selected compute window after the delegatee posts the bond.
  • TaskCompleted carries the output commitment, complete publicValues, and output URI. A valid proof releases the selected reward, less the snapshotted fee, and returns the bond to the delegatee.
  • TaskSelectionCancelled returns a selected task to OPEN, ready for another valid bid within the task’s remaining terms.
  • TaskTimedOut records the ACTIVE timeout path, which returns the reward and full bond to you.

Use proof binding to verify the completion payload and events and limits for the exact event fields.