Addition
Addition example
This is a simple addition example. It takes two numbers as inputs and returns their sum. For this example we can use the standard proplet deployment without any additional configuration.
Source Code
The source code is available in the examples/addition directory.
Loading...
Create Task
To create a task for this example, we need to build the example to wasm and then create a task with the wasm file.
cd propeller
make additionYour output should look like this:
GOOS=js GOARCH=wasm tinygo build -buildmode=c-shared -o build/addition.wasm -target wasip1 examples/addition/addition.goNow we can create a task with the wasm file:
curl -X POST "http://localhost:7070/tasks" \
-H "Content-Type: application/json" \
-d '{"name": "add", "inputs": [10, 20]}'Your output should look like this:
{
"id": "53db63cb-885c-4364-849c-f69640aaa601",
"name": "add",
"kind": "standard",
"state": 0,
"cli_args": null,
"inputs": [10, 20],
"daemon": false,
"encrypted": false,
"start_time": "0001-01-01T00:00:00Z",
"finish_time": "0001-01-01T00:00:00Z",
"created_at": "2026-02-13T10:53:49.157542442Z",
"updated_at": "0001-01-01T00:00:00Z",
"next_run": "0001-01-01T00:00:00Z",
"priority": 50
}Upload Wasm
Now we need to upload the wasm file:
curl -X PUT "http://localhost:7070/tasks/53db63cb-885c-4364-849c-f69640aaa601/upload" \
-F "file=@$(pwd)/build/addition.wasm"Your output should look like this:
{
"id": "53db63cb-885c-4364-849c-f69640aaa601",
"name": "add",
"kind": "standard",
"state": 0,
"file": "...<redacted>...",
"cli_args": null,
"inputs": [10, 20],
"daemon": false,
"encrypted": false,
"start_time": "0001-01-01T00:00:00Z",
"finish_time": "0001-01-01T00:00:00Z",
"created_at": "2026-02-13T10:53:49.157542442Z",
"updated_at": "2026-02-13T10:55:38.798892865Z",
"next_run": "0001-01-01T00:00:00Z",
"priority": 50
}Start Task
Now we can start the task:
curl -X POST "http://localhost:7070/tasks/53db63cb-885c-4364-849c-f69640aaa601/start"Your output should look like this:
{ "started": true }The results of the task will be something like this.
curl -X GET "http://localhost:7070/tasks/53db63cb-885c-4364-849c-f69640aaa601"Your output should look like this:
{
"id": "53db63cb-885c-4364-849c-f69640aaa601",
"name": "add",
"kind": "standard",
"state": 3,
"file": "...<redacted>...",
"cli_args": null,
"inputs": [10, 20],
"daemon": false,
"encrypted": false,
"proplet_id": "a95517f9-5655-4cf5-a7c8-aa00290b3895",
"results": "30\n",
"start_time": "2026-02-13T11:00:43.010348944Z",
"finish_time": "2026-02-13T11:00:43.202889598Z",
"created_at": "2026-02-13T10:53:49.157542442Z",
"updated_at": "2026-02-13T11:00:43.202889537Z",
"next_run": "0001-01-01T00:00:00Z",
"priority": 50
}Invoking Using WasmTime
wasmtime --invoke add ./build/addition.wasm 10 20The results of the task will be something like this.
warning: using `--invoke` with a function that takes arguments is experimental and may break in the future
warning: using `--invoke` with a function that returns values is experimental and may break in the future
30