Infernet
Node
Quickstart

Quickstart

Once comfortable with the Infernet SDK and the overview of various job types independently, it's useful to put the individual components together with an Infernet Node to test the full end-to-end lifecycle.

The following examples quickly introduce a node operator to two common applications of the Infernet Node:

  1. Web2 off-chain compute processing
  2. Web3 on-chain subscription processing
ℹ️

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.

Web2 off-chain compute

The easiest way to test the Web2 workflow of the Infernet Node is to run the hello-world example container from our Infernet Container Starter (opens in a new tab) repository.

Clone the starter repository

# Clone locally
git clone --recurse-submodules https://github.com/ritual-net/infernet-container-starter
# Navigate to the repository
cd infernet-container-starter

Run the hello-world container

Once inside the repository directory, you can run a simple command to deploy the hello-world container along with bootstrapping the rest of the Infernet node stack in one go:

make deploy-container project=hello-world

You can quickly observe the containers that are now active by running docker ps in a new Terminal session:

# > docker ps
 
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.0.0            "/app/entrypoint.sh"     3 minutes ago   Up 3 minutes   0.0.0.0:4000->4000/tcp                      infernet-node
f2a0b22a8220   fluent/fluent-bit:latest                     "/fluent-bit/bin/flu…"   3 minutes ago   Up 3 minutes   2020/tcp, 24224/tcp                         deploy-fluentbit-1
d802f062ab93   ritualnetwork/infernet-anvil:1.0.0           "anvil --host 0.0.0.…"   3 minutes ago   Up 3 minutes   0.0.0.0:8545->3000/tcp, :::8545->3000/tcp   infernet-anvil
b9d42788dd24   redis:latest                                 "docker-entrypoint.s…"   3 minutes ago   Up 3 minutes   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp   deploy-redis-1

Create an off-chain compute job

With the relevant containers now running, we can go ahead and create an off-chain compute request using the REST API, calling our hello-world container with 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"}}'

Immediately, our Infernet Node should response with an ID of the compute job that was created:

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

Collect job status

To check for the current status of the job (including any results or errors), we can poll the /api/jobs endpoint with the ID of our job from above:

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

  1. To look at the node configuration, code, and other resources for the hello-world container, reference the Infernet Container Starter (opens in a new tab) repository.
  2. To build an Infernet-compatible container image, reference the Containers section.

Web3 on-chain subscriptions

To test the Web3 workflow of the Infernet Node, we will need to scaffold some additional components. Below, we:

  1. Deploy an Anvil (opens in a new tab) local testnet node with the Infernet SDK contracts already setup (via our infernet-anvil (opens in a new tab) image).
  2. Deploy an simple Infernet Consumer contract for our Web3 demo application.
  3. Deploy an Infernet Node ready to service our requests.

Then, once this preliminary infrastructure is setup, we:

  1. Make a subscription request to our newly-deployed consumer contract, creating an on-chain subscription.
  2. Monitor the full lifecycle of the subscription, from the:
    • node listening to the subscription event,
    • to the node processing the subscription,
    • to the node sending the result back to the our consumer contract on-chain.

Clone the starter repository

# Clone locally
git clone --recurse-submodules https://github.com/ritual-net/infernet-container-starter
# Navigate to the repository
cd infernet-container-starter

Run the hello-world container

Akin to the Web2 demo above, we will bootstrap all relevant services and infrastructure in one go:

make deploy-container project=hello-world

In another terminal, you can run docker container ls to see a list of the now running containers:

# > docker container ls
 
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.0.0            "/app/entrypoint.sh"     3 minutes ago   Up 3 minutes   0.0.0.0:4000->4000/tcp                      infernet-node
f2a0b22a8220   fluent/fluent-bit:latest                     "/fluent-bit/bin/flu…"   3 minutes ago   Up 3 minutes   2020/tcp, 24224/tcp                         deploy-fluentbit-1
d802f062ab93   ritualnetwork/infernet-anvil:1.0.0           "anvil --host 0.0.0.…"   3 minutes ago   Up 3 minutes   0.0.0.0:8545->3000/tcp, :::8545->3000/tcp   infernet-anvil
b9d42788dd24   redis:latest                                 "docker-entrypoint.s…"   3 minutes ago   Up 3 minutes   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp   deploy-redis-1

Notice that you now have an Anvil node running on port 8545 and an Infernet Node on port 4000.

By default, the infernet-anvil (opens in a new tab) has the Infernet SDK contracts pre-deployed for you:

  • Coordinator: 0x2E983A1Ba5e8b38AAAeC4B440B9dDcFBf72E15d1
  • Primary node: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
  • Registry: 0x663F3ad617193148711d28f5334eE4Ed07016602
  • Inbox: 0x8438Ad1C834623CfF278AB6829a248E37C2D7E3f
  • Reader: 0xBC9129Dc0487fc2E169941C75aABC539f208fb01
  • Fee: 0x6e989C01a3e3A94C973A62280a72EC335598490e
  • Wallet Factory: 0xF6168876932289D073567f347121A267095f3DD6
  • Wallet (owned by the primary node): 0x60985ee8192B322c3CAbA97A9A9f7298bdc4335C

Note, that the primary node address assigned is the default second account in Anvil. This account is prefunded with 10,000 ETH with private key: 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d.

Deploy a consumer

Next, we must deploy a consumer contract that implements the simple Infernet SDK interface.

Our SaysGM (opens in a new tab) contract is a simple, example consumer. All this contract does is request a compute output from an Infernet Node, and upon receiving the result, use the forge console to print the result. We can deploy this contract via the associated forge project (opens in a new tab).

Anvil logs

During this process, it is useful to look at the logs of the Anvil node to see what's going on. To follow the logs, in a new terminal, run:

docker logs -f infernet-anvil

Installing dependencies

Before we can deploy the contract, it is important to install relevant dependencies:

# cd in, install, and cd out
cd projects/hello-world/contracts && forge install --no-commit foundry-rs/forge-std && forge install --no-commit ritual-net/infernet-sdk && cd ../../../

Deploying the contract

Once ready, to deploy the SaysGM consumer contract, in another terminal, run:

project=hello-world make deploy-contracts

You should expect to see similar Anvil logs:

# > project=hello-world make deploy-contracts
 
eth_sendRawTransaction
eth_getTransactionReceipt
 
Transaction: 0x23ca6b1d1823ad5af175c207c2505112f60038fc000e1e22509816fa29a3afd6
Contract created: 0x13D69Cf7d6CE4218F646B759Dcf334D82c023d8e
Gas used: 476669
 
Block Number: 1
Block Hash: 0x6b026b70fbe97b4a733d4812ccd6e8e25899a1f6c622430c3fb07a2e5c5c96b7
Block Time: "Wed, 17 Jan 2024 22:17:31 +0000"
 
eth_getTransactionByHash
eth_getTransactionReceipt
eth_blockNumber

From our logs, we can see that the SaysGM contract has been deployed to address 0x13D69Cf7d6CE4218F646B759Dcf334D82c023d8e.

Call the contract

Now, let's call the contract initiating a request to the Infernet Node. In the same terminal, run:

make call-contract project=hello-world

You should first expect to see an initiation transaction sent to the SaysGm contract:

eth_getTransactionReceipt
 
Transaction: 0xe56b5b6ac713a978a1631a44d6a0c9eb6941dce929e1b66b4a2f7a61b0349d65
Gas used: 123323
 
Block Number: 2
Block Hash: 0x3d6678424adcdecfa0a8edd51e014290e5f54ee4707d4779e710a2a4d9867c08
Block Time: "Wed, 17 Jan 2024 22:18:39 +0000"
eth_getTransactionByHash

Shortly after that you should see another transaction submitted from the Infernet Node which is the result of your on-chain subscription and its associated job request:

eth_chainId
eth_sendRawTransaction
 
 
_____  _____ _______ _    _         _
|  __ \|_   _|__   __| |  | |  /\   | |
| |__) | | |    | |  | |  | | /  \  | |
|  _  /  | |    | |  | |  | |/ /\ \ | |
| | \ \ _| |_   | |  | |__| / ____ \| |____
|_|  \_\_____|  |_|   \____/_/    \_\______|
 
 
subscription Id 1
interval 1
redundancy 1
node 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
input:
0x
output:
0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000607b276f7574707574273a202268656c6c6f2c20776f726c64212c20796f757220696e707574207761733a207b27736f75726365273a20302c202764617461273a20273437366636663634323036643666373236653639366536373231277d227d
proof:
0x
 
Transaction: 0x949351d02e2c7f50ced2be06d14ca4311bd470ec80b135a2ce78a43f43e60d3d
Gas used: 94275
 
Block Number: 3
Block Hash: 0x57ed0cf39e3fb3a91a0d8baa5f9cb5d2bdc1875f2ad5d6baf4a9466f522df354
Block Time: "Wed, 17 Jan 2024 22:18:40 +0000"
 
 
eth_blockNumber
eth_newFilter

We can now confirm that the address of the Infernet Node (see the logged node parameter in the Anvil logs above) matches the address of the node we setup by default for our Infernet Node.

Congratulations! 🎉 You have successfully created an on-chain subscription request!

Additional Resources

  1. See the source code (opens in a new tab) for our SaysGM consumer contract
  2. Read more about the Infernet SDK architecture
  3. Find out more about the Infernet Node architecture