Search…
Quote Of The Day - Example Task

Goal of the task

A common task is recording data from various centralized sources and post it on IPFS or other decentralized locations. This example records a β€œQuote of the day” from an API endpoint and uploads it to IPFS.

Nodes?

When deployed to the network task will be run by several nodes at the same time. When creating the task you will need to provide a bounty that will be used to reward these nodes at the end node census when they have completed the task correctly. The nodes themselves will also have to provide a stake that will force them to complete the task correctly or have their tasks slashed.
There are primarily three types of nodes: Service, Worker and Witness. Service nodes are fully fledged nodes that aggregate data, and can provide API endpoints as they are accessible to external networks. Worker nodes collect data and write that data to K2, IPFS or Service nodes. Witness nodes verify and audit service and worker nodes. You can potentially have infinitely more layers/types of nodes.

Interacting with K2

We use a system called K2 as our settlement layer. The data submitted to K2 should be a CID that references results of a task uploaded to IPFS. Votes are also submitted to K2 during the voting process. During the audit the data submitted to K2 is reviewed for its accuracy.
Task Design
Every task is written as a single executable file containing all the functions need to complete your task. We go into detail throughout the tutorial. Three functions are required to be defined:
  • Setup
  • Executable
  • Validate Node

Handling off-chain data

In many cases tasks will need to retrieve data from other places on the internet such as the example task we are working on. This can be done through calls to API endpoints or web scraping. For getting data from IPFS we use Web3.Storage in this example task. Each node will provide their own API keys for running a given task.

Local Testing

Tasks can use defined environment variables in their task. This example task requires you to define a Web3.Storage API in your environment variable. You can get a free Web3.Storage API key here.
For details on locally testing your executable please view how to setup the docker container provided​

Deploying Task

In order to get your task running on the network of nodes you will need to first register your task on the main K2 network contract using the create-task-cli. After that you will need to provide your task enough bounty to fund the task nodes who run your task. Finally you will need to get our dev team to whitelist your task.
Copy link
On this page