To begin, clone the task template:
git clone https://github.com/koii-network/task-template.git hello-world
What's in the template?
index.js— is the hub of your app, and ties the other pieces together. This will be the entry point when your task runs on task nodes.
_koiiNode— is a directory that contains
koiiNode.jswhich has the interfaces to make API calls to the core of the task-node. It contains all the necessary functions required to submit and audit the work, as well as the distribution lists. Check here to learn more namespace functions.
It houses three key files:
distribution.js. These files are where you define your task, audit, and distribution logic, enabling you to control the core functionality of the task.
This structure allows a modular approach to task development. By only utilizing these three files, you can easily modify and test your task logic without having to worry about the other aspects. In order to understand the theory behind, please refer to the
And finally, in the
index.js file, all these functions are combined as a task, which is then imported and used in
corelogic.js. It is advisable to organize separate features into sub-files and import them into the relevant files before web-packing for better code management and maintainability. This modular approach allows for a more organized and efficient development process.
submission.js file, there are 3 methods that allow you to define the actions your task will perform and what it will submit. Here are the descriptions of these methods, which you can modify as per your specific requirements:
|The logic for what your task should do goes here.|
|After completing the task, the results/work will be stored either on IPFS or NeDB. This method fetches the results/work from where it was stored.|
|This method calls a |
audit.js file, there are a total of 2 methods that deal with verifying the submissions made. You can modify these methods to suit your needs:
|This method contains logic to verify a node's submission value.|
|Makes a call to the |
In the distribution.js file, there are a total of 4 methods that handle the flow of distributing rewards. You have the flexibility to modify any of these methods to meet your specific requirements:
|This method contains the logic to generate a distribution list. We have provided a sample code that rewards 1 KOII to all the nodes with valid submissions for that round.|
|Makes a call to a |
|The logic to validate the distribution list goes here.|
|Makes a call to the |
When creating a task using the Task Template, there's usually no need to edit the following methods:
By implementing and modifying these methods, we will create a comprehensive and fully functional task. Let's proceed with writing the logic and submission process for our task.
If you encounter any difficulties, feel free to contact us on Discord.