Infernet
Node
Offchain

Off-chain requests

Let's start with the off-chain workflow of the Infernet Node. We will:

  1. Run an Infernet Node with the hello-world (opens in a new tab) example container
  2. Use the REST API to create a compute job and collect the results

We will demonstrate two ways to configure, deploy, and query the Infernet Node:

  1. Using the Infernet CLI (opens in a new tab) and Infernet Client (opens in a new tab), tools built by us to simplify the developer experience
  2. From source, using the Infernet Container Starter (opens in a new tab) repository

Infernet CLI + Client

Prerequisites

Configure the Node

Pull the latest Infernet Node configuration:

infernet-cli config other --skip

The output should look something like this:

No version specified. Using latest: v1.3.0
Using configurations:
  Chain = 'other'
  Version = '1.3.0'
  GPU support = disabled
  Output dir = 'deploy'

Stored base configurations to '/root/deploy'.
To configure services:
  - Use `infernet-cli add-service`
  - Or edit config.json directly

Configure hello-world

Add the hello-world container to the node configuration:

infernet-cli add-service hello-world --skip

The output should look something like this:

Version not provided. Using latest version 'latest'.
Successfully added service 'hello-world' to config.json.

Run the node

Start the Infernet Node with the hello-world container:

infernet-cli start

The output should look something like this:

Starting Infernet Node...
Containers started successfully.

You can confirm all necessary containers that are running using docker ps:

docker ps

The output should look something like this:

CONTAINER ID   IMAGE                                        COMMAND                  CREATED         STATUS         PORTS                    NAMES
ed7ec08617aa   ritualnetwork/hello-world-infernet:latest    "gunicorn app:create…"   3 minutes ago   Up 3 minutes   0.0.0.0:3000->3000/tcp   hello-world
22be7ee424f1   ritualnetwork/infernet-node:1.3.1            "/app/entrypoint.sh"     3 minutes ago   Up 3 minutes   0.0.0.0:4000->4000/tcp   infernet-node
f2a0b22a8220   fluent/fluent-bit:3.1.4                      "/fluent-bit/bin/flu…"   3 minutes ago   Up 3 minutes   2020/tcp, 24224/tcp      infernet-fluentbit
b9d42788dd24   redis:7.4.0                                  "docker-entrypoint.s…"   3 minutes ago   Up 3 minutes   0.0.0.0:6379->6379/tcp   infernet-redis

Submit a job request

With the node and container now running, we can submit a job request for the hello-world container using the Infernet Client (opens in a new tab). Notice we pipe (|) the input data to the job command, but you can also use a file.

export SERVER_URL=http://localhost:4000
 
echo '{"some": "input"}' | infernet-client job -c hello-world

The node will return the ID of the compute job that was created, which will look something like this:

e45b5ebc-c71e-4ab8-b10f-d1202e7fb16e

Collect results

Now we can poll the Infernet Node for the job status and results by ID:

infernet-client results --id e45b5ebc-c71e-4ab8-b10f-d1202e7fb16e

The output should look something like this:

[
  {
    "id": "e45b5ebc-c71e-4ab8-b10f-d1202e7fb16e",
    "result": {
      "container": "hello-world",
      "output": {
        "output": "hello, world!, your input was: {'source': 1, 'destination': 1, 'data': {'some': 'input'}, 'requires_proof': False}"
      }
    },
    "status": "success"
  }
]

From Source

Prerequisites

git clone --recurse-submodules https://github.com/ritual-net/infernet-container-starter

Configuration

This step is already complete. The docker-compose.yaml (opens in a new tab) brings up the necessary services for the Infernet Node. while the config.json (opens in a new tab) contains all necessary node configurations and sets up the hello-world container.

Run the node

The Makefile (opens in a new tab) contains a deploy-container command that will bring up the Infernet Node and the hello-world container.

# Navigate to the repository
cd infernet-container-starter
make deploy-container project=hello-world

You can confirm all necessary containers that are running using docker ps:

docker ps

The output should look something like this:

CONTAINER ID   IMAGE                                        COMMAND                  CREATED         STATUS         PORTS                    NAMES
ed7ec08617aa   ritualnetwork/hello-world-infernet:latest    "gunicorn app:create…"   3 minutes ago   Up 3 minutes   0.0.0.0:3000->3000/tcp   hello-world
22be7ee424f1   ritualnetwork/infernet-node:1.3.1            "/app/entrypoint.sh"     3 minutes ago   Up 3 minutes   0.0.0.0:4000->4000/tcp   infernet-node
f2a0b22a8220   fluent/fluent-bit:3.1.4                      "/fluent-bit/bin/flu…"   3 minutes ago   Up 3 minutes   2020/tcp, 24224/tcp      infernet-fluentbit
b9d42788dd24   redis:7.4.0                                  "docker-entrypoint.s…"   3 minutes ago   Up 3 minutes   0.0.0.0:6379->6379/tcp   infernet-redis

Submit a job request

With the node and container now running, we can submit a job request for the hello-world container using the REST API, passing some input data.

curl -X POST "http://127.0.0.1:4000/api/jobs" \
    -H "Content-Type: application/json" \
    -d '{"containers": ["hello-world"], "data": {"some": "input"}}'

The node will return the ID of the compute job that was created, which will look something like this:

{"id": "e45b5ebc-c71e-4ab8-b10f-d1202e7fb16e"}

Collect results

Now we can poll the Infernet Node for the job status and results by ID:

curl -X GET "http://127.0.0.1:4000/api/jobs?id=e45b5ebc-c71e-4ab8-b10f-d1202e7fb16e"

Here is the result you can expect:

[
    {
        "id": "e45b5ebc-c71e-4ab8-b10f-d1202e7fb16e",
        "result": {
            "container": "hello-world",
            "output": {
                "output": "hello, world!, your input was: {'source': 1, 'data': {'some': 'input'}}"
            }
        },
        "status": "success"
    }
]

Additional Resources

From here, you can:

  1. Continue to the on-chain quickstart.
  2. Check out the starter configurations, code, and other resources for the hello-world container in the Infernet Container Starter (opens in a new tab) repository.
  3. Explore different deployment options for the Infernet Node.
  4. Check out the REST API and Client documentation.
  5. Build an Infernet-compatible container.