Off-chain requests
Let's start with the off-chain workflow of the Infernet Node. We will:
- Run an Infernet Node with the
hello-world
(opens in a new tab) example container - 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:
- 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
- From source, using the Infernet Container Starter (opens in a new tab) repository
Infernet CLI + Client
Prerequisites
-
Docker
(opens in a new tab): Infernet Nodes execute containerized workflows. As such, installing and running (opens in a new tab) a modern version of Docker is a prerequisite, regardless of your choice of how to run the node. -
Python
(opens in a new tab): Required for running the Infernet CLI. Must be Python 3.9 or higher, and includepip
package manager. -
Infernet CLI
(opens in a new tab): The CLI is a tool for configuring and managing Infernet Nodes. Install withpip
:pip install infernet-cli
-
Infernet Client
(opens in a new tab): The client is a tool for interacting with Infernet Nodes. Install withpip
:pip install infernet-client
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
Docker
(opens in a new tab): Infernet Nodes execute containerized workflows. As such, installing and running (opens in a new tab) a modern version of Docker is a prerequisite, regardless of your choice of how to run the node.Git
(opens in a new tab): Required for cloning the repository.infernet-container-starter
(opens in a new tab): The starter repository contains a simplehello-world
container and a Makefile to help you deploy it. Clone the repository locally:
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:
- Continue to the on-chain quickstart.
- 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. - Explore different deployment options for the Infernet Node.
- Check out the REST API and Client documentation.
- Build an Infernet-compatible container.