# How to Create Function Tasks

{% hint style="info" %}
Check the [Supported Languages](/developing-truebit-tasks/how-to-create-function-tasks/supported-languages.md) section to see the specific task preparation steps required for your development language.
{% endhint %}

## Prerequisites

There are several important considerations when writing Function Task code:&#x20;

* **Execution environment**: The task must run the same on any computer architecture and operating system. Therefore, Function Tasks execute in an isolated WebAssembly sandbox using our deterministic WASI implementation. Please, check the [WebAssembly ](/developing-truebit-tasks/how-to-create-function-tasks/key-concepts/webassembly.md)section for more information.
* **No network calls:** To provide maximum security, the execution environment does not provide network access. If you need to access data from an external source, consider using an [API Task](/developing-truebit-tasks/how-to-create-api-tasks.md).
* **Determinism**: The execution environment guarantees [determini](/developing-truebit-tasks/how-to-create-function-tasks/key-concepts/determinism.md)[sm](/developing-truebit-tasks/how-to-create-function-tasks/key-concepts/determinism.md) - All Function Tasks will produce the same outputs for given inputs when executed by any Truebit Verify node.

## Building A Function Task&#x20;

### 1. Write Your Function Task Code

The task developer will create the code, following the best practices described below:

#### **Replace network operation with filesystem reads and writes**

If your program would normally read and write to network endpoints, you'll need to replace this with filesystem operations.

For example, instead of making an HTTP request to `example.com`,  read from the input.txt file. Click [here](/developing-truebit-tasks/how-to-create-function-tasks/function-task-examples/fibonacci.md#in-out-parameters) to see an example.&#x20;

You can write results to the filesystem into an output file. Click [here](/developing-truebit-tasks/how-to-create-function-tasks/function-task-examples/fibonacci.md#in-out-parameters) to see an example.

#### Random Numbers

If your program normally uses random numbers, in Truebit you will always get the same sequence. This is done to ensure a deterministic execution.

#### Dates and Times&#x20;

If your program would normally get date-time values, in Truebit you will always get the same value, which is "`1970.1.1 0:1:40`". This is done to ensure a deterministic execution.

**Output value**

The task must return a value. If the result is empty, the task will be marked as failed.

### 2. Test Your Function Task

Once your code is ready for testing, the **development workflow involves two primary steps** using the Truebit CLI:

* **Build and Prepare**: Execute the [`build`](/developing-truebit-tasks/truebit-cli-reference.md) command to generate a WebAssembly [(WASM) file](/developing-truebit-tasks/how-to-create-function-tasks/key-concepts/webassembly.md). Truebit utilizes WebAssembly to ensure cross-platform consistency across any hardware or operating system. During this stage, the file is automatically instrumented to guarantee deterministic execution.
* **Execute and Test**: Run the [`start`](/developing-truebit-tasks/truebit-cli-reference.md#start) command to deploy and verify your compiled code within the Truebit environment.

{% hint style="success" %}
Repeat this process every time your source code has been changed.
{% endhint %}

### 3. Deploy The Function Task

Once the task is ready for being used by others, the [Task Developer](/overview/how-do-you-intend-to-use-truebit.md#task-developers) will deploy it to make it available for being called by the [Task Requester](/overview/how-do-you-intend-to-use-truebit.md#task-requesters).

#### Authorize The Task execution

The Task Authorization process is an optional step. This step allows the [Task Developer](/overview/how-do-you-intend-to-use-truebit.md#task-developers) to define who has permission to execute the deployed task.

{% hint style="info" %}
Click Here to see more information about the [**Task Authorization**](/developing-truebit-tasks/task-authorization.md) process.&#x20;
{% endhint %}

### 4. Execute The Function Task

The [Task Requester](/overview/how-do-you-intend-to-use-truebit.md#task-requesters) executes the task using the [Task Execution Endpoint](/integrating-truebit-tasks/api-task-execution.md) from the Truebit API.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://devs.truebit.io/developing-truebit-tasks/how-to-create-function-tasks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
