Tasks
Tasks represent requests for jobs to be performed. Think of them like a transaction mixed with a block, a fee is proposed along with the data required to "mine" it, and miners receive the fees and potentially the task reward which is how the Arbius token comes into existence.
The Task model
The Task model contains all the information about the Task, such as its fees, information on how to run it, and whether or not it grants tasks rewards.
Properties
- Name
model
- Type
- bytes32
- required
- Defaults to
- Description
Model id
- Name
fee
- Type
- uint256
- required
- Defaults to
- Description
Amount of fee offered for completion
- Name
owner
- Type
- address
- required
- Defaults to
- Description
Which address is allowed to rescind the task (after delay)
- Name
blocktime
- Type
- uint64
- required
- Defaults to
- Description
Unix timestamp of task registration.
- Name
version
- Type
- uint8
- required
- Defaults to
- Description
Version, currently unused and always 0.
- Name
cid
- Type
- string
- required
- Defaults to
- Description
IPFS CID for input request.
Retrieve task
Look up a task based on its ID.
Request
import { ethers } from 'ethers'
import Config from './config.json'
import EngineArtifact from './artifacts/EngineV1.sol/EngineV1.json';
const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
const engine = new ethers.Contract(
Config.engineAddress,
EngineArtifact.abi,
provider,
)
const task = await engine.tasks(taskId);
const { model, fee, owner, blocktime, version, cid } = task;
Submit task
Submit a new task to be completed by others. Watch for SolutionSubmitted
events to see when someone has provided a solution. Wait for longer to see for any ContestationSubmitted
events to ensure it is valid. Once the MIN_CLAIM_SOLUTION_TIME
has passed, you can be relatively certain the tasks solution is valid. For integration into smart contracts, consider a two part process to initiate the task then to later confirm the task has no (or failed) contestation. If a task has a valid contestation you will receive your fees back, so you can try again.
Request
import { ethers } from 'ethers'
import Config from './config.json'
import EngineArtifact from './artifacts/EngineV1.sol/EngineV1.json';
const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
const wallet = new ethers.Wallet(
process.env.PRIVATE_KEY,
provider,
);
const engine = new ethers.Contract(
Config.engineAddress,
EngineArtifact.abi,
wallet,
)
const model = 'model id we are using';
// ensure this follows model template
const input = {
prompt: "cat rocket ship"
};
const params = {
version: 0,
owner: wallet.address,
model,
fee: ethers.utils.parseEther('0.1'),
input: ethers.utils.hexlify(ethers.utils.toUtf8Bytes(JSON.stringify(input))),
}
const tx = await engine.submitTask(
params.version,
params.owner,
params.model,
params.fee,
params.input,
)
const receipt = await tx.wait();