# Create Tasks

## Overview

The Othentic CLI allows you to define different [Tasks](https://docs.othentic.xyz/main/learn/core-concepts/tasks) to be performed by Operators. This guide covers the commands needed to define these tasks via [Task Definitions](https://docs.othentic.xyz/main/learn/core-concepts/tasks/task-definitions).

#### Read More

* [Tasks](https://docs.othentic.xyz/main/learn/core-concepts/tasks)
* [Task Definitions](https://docs.othentic.xyz/main/learn/core-concepts/tasks/task-definitions)
* [CLI Command Reference](https://docs.othentic.xyz/main/reference/othentic-cli/network/tasks/create-task-definition)

## Prerequisites

* [Othentic CLI installed](https://docs.othentic.xyz/main/welcome/getting-started/install-othentic-cli)
* Access to AVS Governance multisig owner account
* Attestation Center contract address of the AVS

{% stepper %}
{% step %}

### Create Tasks&#x20;

Run the following command:

```bash
otcli network create-task-definition
```

{% hint style="success" %}
Pass `--browser-sign`  flag to connect your wallet and sign using a web browser UI.
{% endhint %}

Follow these steps when prompted:

* Provide the private key of the multi-sig address.
* Enter the Attestation Center contract address.
* Enter all the Task details
  * Task Name&#x20;
  * Base Rewards  (e.g. 0.001 ether; default: 0)
    * Attester rewards
    * Performer rewards&#x20;
    * Aggregator rewards&#x20;
  * Minimum voting power&#x20;
  * Restricted attester IDs
  * Max number of Attesters
  * Expiry block – When the task expires (leave blank for never)
    {% endstep %}

{% step %}

### Implement Task [Execution Service](https://docs.othentic.xyz/main/learn/core-concepts/execution-service) Logic

Write the logic that the **Performer** will execute.

In your implementation, make sure to execute the task based on the appropriate **Task Definition ID**.

```xojo
curl -X POST http://localhost:4003/task/execute \
  -H "Content-Type: application/json" \
  -d '{
        "taskDefinitionId": 123
      }'
```

{% endstep %}

{% step %}

### Implement Task [Validation Service](https://docs.othentic.xyz/main/learn/core-concepts/validation-service) Logic

Write the logic that the **Attester** will execute.

In your implementation, make sure to validate the task based on the appropriate [**Task Definition ID received as part of the \`sendTask\` RPC request.**](https://docs.othentic.xyz/main/learn/core-concepts/execution-service#task-submission)

```
{
  "taskDefinitionId": 123,
  "proofOfTask": "abcs",
  "data": "0x1232",
  "performer": "0x1234567890abcdef1234567890abcdef12345678"
}
```

{% endstep %}

{% step %}

### Verify Tasks creation

Refer to the following [Task specific methods](https://docs.othentic.xyz/main/reference/contracts/attestation-center#tasks) in the Attestation center to get details about the tasks created. These methods allow you to query Task specific data like [Minimum Voting Power](https://docs.othentic.xyz/main/learn/core-concepts/tasks/task-definitions#minimum-voting-power-for-a-task),  [Restricted Operator Set](https://docs.othentic.xyz/main/learn/core-concepts/tasks/task-definitions#restricted-operator-set-for-a-task) etc.
{% endstep %}
{% endstepper %}

***

## Using scripts

New Task Definitions are created on-chain via the [`AttestationCenter`](https://docs.othentic.xyz/main/reference/contracts/attestation-center) smart contract. To create a task definition, call [`createNewTaskDefinition`](https://github.com/Othentic-Labs/core-contracts/blob/main/src/NetworkManagement/L2/AttestationCenter.sol#L247) as shown in the example below:

{% tabs %}
{% tab title="Ethers" %}

<pre class="language-javascript"><code class="lang-javascript"><strong>const attestationCenter = new ethers.Contract(
</strong>  ATTESTATION_CENTER_ADDRESS,
  ['function createNewTaskDefinition(string,(uint256,uint256,uint256,uint256,uint256,uint256,uint256[])) external']
);

const tx = await attestationCenter.createNewTaskDefinition(
  "Example Task",             // Human-readable name
  {             
  ethers.MaxUint256,          // Never expires
  ethers.parseEther('0.01'),  // Reward for attestation
  ethers.parseEther('0.1'),   // Reward for performer
  ethers.parseEther('0.005'), // Reward for aggregation
  0,                          // Disable disputes
  0,                          // Minimum Voting Power
  []                          // Restricted Operator Set 
  }                          
);

await tx.wait();
</code></pre>

{% endtab %}

{% tab title="Foundry" %}

<pre class="language-solidity"><code class="lang-solidity"><strong>import { Script, console } from 'forge-std/Script.sol';
</strong>
interface IAttestationCenter {
    struct TaskDefinitionParams {
        uint256 blockExpiry;
        uint256 baseRewardFeeForAttesters;
        uint256 baseRewardFeeForPerformer;
        uint256 baseRewardFeeForAggregator;
        uint256 disputePeriodBlocks;
        uint256 minimumVotingPower;
        uint256[] restrictedOperatorIndexes;
    }
    function createNewTaskDefinition(
        string memory _name,
        uint256 _blockExpiry,
        uint256 _baseRewardFeeForAttesters,
        uint256 _baseRewardFeeForPerformer,
        uint256 _baseRewardFeeForAggregator,
        uint256 _disputePeriodBlocks,
        uint256 _minimumVotingPower,
        uint256[] _restrictedOperatorIndexes
    ) external returns (uint16 _id);
}

contract CreateNewTask is Script {
    function run () external {
        IAttestationCenter attestationCenter = IAttestationCenter(ATTESTATION_CENTER_ADDRESS);

        uint16 taskId = attestationCenter.createNewTaskDefinition({
            _name: "Example Task",                           // Human-readable name
            _params: TaskDefinitionParams(
               blockExpiry: type(uint256).max,               // Never expires
               baseRewardFeeForAttesters: 0.01 ether,        // Reward for attestation
               baseRewardFeeForPerformer: 0.1 ether,         // Reward for task
               baseRewardFeeForAggregator: 0.005 ether,      // Reward for aggregation
               disputePeriodBlocks: 0                        // Disable disputes
               minimumVotingPower: 0                         // Minimum Voting Power
               restrictedOperatorIndexes: new uint256[](0)   // Restricted Operator Set
            )
        });

        console.log('New task ID: %s', taskId);
    }
}
</code></pre>

{% endtab %}
{% endtabs %}
