Skip to content
Version 0.0.1 (Testnet)

Deploy and test your projection

This guide will walk you through deploying your first projection on Datai Network, or for testing purposes on your local machine. Before you start, please make sure you have followed the steps from the previous guide.

Deploying a projection is simple, and Datai CLI will handle most of the heavy lifting.

Let’s start by running the following command

Deploying a projection locally

Before you begin, make sure you have the following prerequisites:

  1. Create .env file and make sure you have an archive node for a network of your choice. Please note that you need all of the following environment variables present, even if you don’t have access to particular networks.

    .env
    ETH_PROVIDER="[archive node url]"
    LOG_LEVEL=debug
  2. Make sure you are inside of the dev container. CTRL + Shift + P - Dev Containers: Rebuild and Reopen in Container. Every command you will ever need to run will be from within the container.

terminal
deploy TEMPLATE PROTOCOL MODULE NETWORK

This command will deploy both the subgraph and the watcher build into a Docker volume, allowing it to be utilized by the host application.

Deploying watcher and subgraph separately

You can also deploy the watcher and subgraph separately by running the following commands. This is useful in cases where you find errors in one of the components and after fixing them, you’d like to deploy only the fixed part.

Deploying subgraph

terminal
build TEMPLATE PROTOCOL MODULE NETWORK
deploy TEMPLATE PROTOCOL MODULE NETWORK graph

Deploying watcher

terminal
build TEMPLATE PROTOCOL MODULE NETWORK
deploy TEMPLATE PROTOCOL MODULE NETWORK watcher

Run the host application

To ensure the accuracy of positions within your deployment, you can utilize the public host image. Since this image is part of the internal Datai application and provided for testing purposes only, we strongly recommend running it within a Docker Compose environment. This setup will include all necessary environment variables and facilitate communication between internal services.

The host image is already included in the project’s Docker Compose configuration. To start the service, navigate to the root directory of the project and run:

terminal
docker compose up -d host

Run the projection indexation

To add a projection for indexation, you can use the following API call to our host application:

terminal
curl -X POST 'http://localhost:9000/deploy?projection=PROTOCOL__MODULE___NETWORK&plane=activePositions'

In our previous guide, we used Uniswap V2 Liquidity Pool module on Ethereum Mainnet as an example. Here’s how our command would look like:

terminal
curl -X POST 'http://localhost:9000/deploy?projection=PROTOCOL__MODULE___NETWORK&plane=activePositions'

This will trigger the indexation process for the projection, and you can monitor the progress in the host application logs.

Check status

The indexation process can take some time to complete, depending on the size of the network and the number of positions to be indexed. You can monitor the progress in the host application logs. Here’s how to check the status.

terminal
docker logs host

Fetch the data

Once the indexation process is complete, you can fetch the data from the host application. Here’s how to do it.

terminal
curl 'http://localhost:9000/activePositions?projection=PROTOCOL__MODULE___NETWORK&user=0x123456789'

Replace PROTOCOL, MODULE, NETWORK, and 0x123456789 with the appropriate projection details and user address.

Deploying a projection on Datai Network

Having deployed and tested your projection locally, it is now time to deploy it to Datai Network.

Steps for submission

  1. Access the projection dev container: Ensure you are within the projection development environment (the dev container) where the projection has been developed and tested.

  2. Submit the Projection: Execute the following command within the dev container to submit the projection data to IPFS:

    terminal(dev-container)
    yarn submit TEMPLATE PROTOCOL MODULE NETWORK
    • TEMPLATE: Replace this with the specific template name used in your projection.
    • PROTOCOL: The protocol identifier associated with the projection.
    • MODULE: The module name that the projection is part of.
    • NETWORK: The network (e.g., mainnet, polygon, arbitrum) where the projection will be deployed.
  3. Verify the Submission: After the submission, you should receive a hash that represents the IPFS CID of the projection data.

    terminal (output)
    Deployment Submitted: Please proceed with staking MDN tokens using
    the hash [deploymentResultsIpfsHash] to initiate the indexation process.

    [deploymentResultsIpfsHash]: The is placeholder will be the actual IPFS CID hash generated upon successful submission to the network.

Stake and Activate the Projection

Using Datai Network Console, you can stake and activate your projection. The process is simple and can be done in a few steps.

  1. Open the Datai Network Console.
  2. Navigate to your projections and select the one you’ve just finished developing.
  3. Using the hash you received after the submission input it in the IPFS hash field. Datai Network Console - IPFS hash
  4. Next, stake and confirm your projection registration. Datai Network Console - Register Projection
  5. Confirm the transaction in your wallet and wait for the network confirmation.