Submitting Jobs

How to submit compute jobs to the network

Experimental Feature

This feature is experimental and may change significantly in future versions.

Job Submission

A compute job consists of a program specification and input data. When submitted, the job is distributed to validators who execute it and generate a verifiable receipt.

Job Structure

interface ComputeJob {
  // Program to execute (hash or identifier)
  program: string;
  
  // Input data for the program
  input: Buffer | string | object;
  
  // Optional configuration
  options?: {
    // Maximum execution time in ms
    timeout?: number;
    
    // Number of validators required
    redundancy?: number;
    
    // Priority level
    priority?: 'low' | 'normal' | 'high';
    
    // Callback URL for async notification
    webhook?: string;
  };
}

Submitting a Job

import { ComputeNet } from '@computenet/sdk';

const client = new ComputeNet({ network: 'testnet' });

// Simple job submission
const receipt = await client.compute({
  program: 'sha256',
  input: 'data to hash'
});

// Advanced job with options
const receipt = await client.compute({
  program: 'ml-inference-v1',
  input: { 
    model: 'sentiment-analysis',
    text: 'ComputeNet is amazing!'
  },
  options: {
    timeout: 30000,
    redundancy: 3,
    priority: 'high'
  }
});

console.log('Job ID:', receipt.jobId);
console.log('Status:', receipt.status);
console.log('Output:', receipt.output);

Async Jobs

For long-running computations, use async submission with webhooks:

// Submit async job
const { jobId } = await client.submitAsync({
  program: 'complex-computation',
  input: largeDataset,
  options: {
    webhook: 'https://myapp.com/webhooks/computenet'
  }
});

// Check status later
const status = await client.getJobStatus(jobId);

// Retrieve receipt when complete
if (status.complete) {
  const receipt = await client.getReceipt(jobId);
}