Self-Hosting Your Blockchain Indexer
This documentation page is actively being improved. Check back regularly for updates and additional information.
While Envio offers a fully managed cloud hosting solution via Envio Cloud, you may prefer to run your blockchain indexer on your own infrastructure. This guide covers everything you need to know about self-hosting Envio indexers.
We deeply appreciate users who choose Envio Cloud, as it directly supports our team and helps us continue developing and improving Envio's technology. If your use case allows for it, please consider the hosted option.
Why Self-Host?
Self-hosting gives you:
- Complete Control: Manage your own infrastructure and configurations
- Data Sovereignty: Keep all indexed data within your own systems
Self Hosting can be done with a variety of different infrastructure, tools and methods. The outline below is merely a starting point and does not offer a full production level solution. In some cases advanced knowledge of infrastructure, database management and networking may be required for a full production level solution.
Prerequisites
Before self-hosting, ensure you have:
- Docker installed on your host machine, or Node.js 22.15.0 or newer to run the indexer directly
- A PostgreSQL database the indexer can reach
- Sufficient storage for blockchain data and the indexer database
- Adequate CPU and memory resources (requirements vary based on chains and indexing complexity)
- Required HyperSync and/or RPC endpoints
- Envio API token for HyperSync access (
ENVIO_API_TOKEN) - required for continued access. See API Tokens.
Getting Started
In general, if you want to self-host, you will likely use a Docker setup. Add the three files below to the root of the project envio init created. They use pnpm; change the install step if you use npm or Yarn.
Dockerfile:
FROM node:24-slim
# Use the pnpm major version you use locally, so --frozen-lockfile accepts your lockfile
RUN npm install -g pnpm@9
WORKDIR /envio-indexer
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY . .
# `envio start` runs codegen before it starts indexing, so there is no build step.
CMD ["pnpm", "envio", "start"]
.dockerignore:
node_modules
.git
logs
.env
.env.*
Keep .env in .dockerignore. The indexer loads .env from its working directory at startup, so COPY . . without it bakes your ENVIO_API_TOKEN (and any other secret) into the image. Pass secrets as runtime environment variables instead, as the compose file below does. node_modules is excluded so the image installs the envio binary for Linux, not for your machine.
docker-compose.yaml:
services:
envio-postgres:
image: postgres:18.3
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ${ENVIO_PG_PASSWORD:?set ENVIO_PG_PASSWORD}
POSTGRES_DB: envio
volumes:
# postgres:18+ stores data under /var/lib/postgresql/18/docker.
# Mount /var/lib/postgresql, not /var/lib/postgresql/data.
- envio-pg-data:/var/lib/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d envio"]
interval: 5s
timeout: 2s
retries: 20
graphql-engine:
image: hasura/graphql-engine:v2.43.0
restart: always
depends_on:
envio-postgres:
condition: service_healthy
ports:
- "127.0.0.1:${HASURA_EXTERNAL_PORT:-8080}:8080"
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:${ENVIO_PG_PASSWORD}@envio-postgres:5432/envio
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET:?set HASURA_GRAPHQL_ADMIN_SECRET}
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: public
HASURA_GRAPHQL_STRINGIFY_NUMERIC_TYPES: "true"
HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
healthcheck:
test: ["CMD-SHELL", "timeout 1s bash -c ':> /dev/tcp/127.0.0.1/8080' || exit 1"]
interval: 5s
timeout: 2s
retries: 50
envio-indexer:
build: .
# Restarts after a crash, but not after a clean exit (an indexer with `end_block` exits 0 when done)
restart: on-failure
# Passes project variables used in config.yaml, such as ENVIO_RPC_URL
env_file: .env
depends_on:
graphql-engine:
condition: service_healthy
ports:
- "127.0.0.1:9898:9898"
environment:
NODE_ENV: production
# Passed at runtime, never baked into the image. Remove for RPC-only indexers.
ENVIO_API_TOKEN: ${ENVIO_API_TOKEN:?set ENVIO_API_TOKEN}
ENVIO_PG_HOST: envio-postgres
ENVIO_PG_PORT: 5432
ENVIO_PG_USER: postgres
ENVIO_PG_PASSWORD: ${ENVIO_PG_PASSWORD}
ENVIO_PG_DATABASE: envio
ENVIO_PG_SSL_MODE: "false"
HASURA_GRAPHQL_ENDPOINT: http://graphql-engine:8080/v1/metadata
HASURA_GRAPHQL_ROLE: admin
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET}
ENVIO_THROTTLE_CHAIN_METADATA_INTERVAL_MILLIS: 500
ENVIO_THROTTLE_PRUNE_STALE_DATA_INTERVAL_MILLIS: 30000
healthcheck:
# node:*-slim has no curl or wget, so probe /healthz with Node's fetch
test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:9898/healthz').then(r => process.exit(r.ok ? 0 : 1), () => process.exit(1))"]
interval: 10s
timeout: 3s
retries: 5
start_period: 30s
volumes:
envio-pg-data:
Put the values in a .env next to docker-compose.yaml. Docker Compose reads it to fill in the ${...} variables, and env_file passes it to the indexer at runtime, so add any variable your config.yaml uses, such as ENVIO_RPC_URL. The image never sees it. Use a password without URL-special characters, since it is embedded in HASURA_GRAPHQL_DATABASE_URL.
# .env
ENVIO_API_TOKEN=<your-api-token>
ENVIO_PG_PASSWORD=<a-strong-password>
HASURA_GRAPHQL_ADMIN_SECRET=<a-strong-secret>
envio dev uses ports 8080 and 9898 on the host too. Stop it first (pnpm envio stop also deletes the local dev data), or change both HASURA_EXTERNAL_PORT and the indexer's 9898 mapping. Then build and start everything:
docker compose up -d --build
docker compose logs -f envio-indexer
Check that data lands in Postgres and is served by Hasura:
docker compose exec envio-postgres psql -U postgres -d envio -c '\dt public.*'
curl -s "http://$(docker compose port graphql-engine 8080)/v1/graphql" -H 'Content-Type: application/json' \
-d '{"query":"{ _meta { chainId progressBlock isReady } }"}'
Both ports listen on 127.0.0.1 only. Hasura's public role reads every indexed table without the admin secret, so serve the GraphQL API to other machines only on purpose: drop the 127.0.0.1: prefix or put a reverse proxy in front, and set HASURA_GRAPHQL_ENABLE_CONSOLE: "false" in production.
The older local-docker-example repository uses variable names from earlier versions. If you start from it, replace TUI_OFF with ENVIO_TUI=false, CONFIG_FILE with ENVIO_CONFIG and ENVIO_PG_PUBLIC_SCHEMA with ENVIO_PG_SCHEMA. ENVIO_PG_PUBLIC_SCHEMA is still read, so its value envio puts the tables in that schema instead of public.
Configuration Explained
The compose file sets up three services:
- PostgreSQL Database (
envio-postgres): Stores your indexed data - Hasura GraphQL Engine (
graphql-engine): Provides the GraphQL API for querying your data - Envio Indexer (
envio-indexer): The core indexing service that processes blockchain data.envio devis not used: the container runsenvio startwithNODE_ENV=production, so every variable from Production mode is set explicitly. The image doesn't need thepsqlclient: the indexer restores the effect cache from.envio/cacheover its own Postgres connection, andCOPY . .includes that folder.
Environment Variables
The configuration uses environment variables with sensible defaults. For production, you should customize:
- Envio API token (
ENVIO_API_TOKEN), passed at runtime and never copied into the image (see the warning above) - Database connection (
ENVIO_PG_HOST,ENVIO_PG_PORT,ENVIO_PG_USER,ENVIO_PG_PASSWORD,ENVIO_PG_DATABASE, andENVIO_PG_SSL_MODEfor a managed database) - Hasura connection (
HASURA_GRAPHQL_ENDPOINT, for examplehttp://graphql-engine:8080/v1/metadata, andHASURA_GRAPHQL_ADMIN_SECRET), orENVIO_HASURA=falseto run without Hasura. WithNODE_ENV=production, set theHASURA_GRAPHQL_*variables even when Hasura is off (see Production mode) - Resource limits based on your workload requirements
If you set NODE_ENV=production, the Postgres connection variables (including ENVIO_PG_SSL_MODE, false for a database without TLS), the Hasura variables (including HASURA_GRAPHQL_ROLE, usually admin) and the two throttle intervals (ENVIO_THROTTLE_CHAIN_METADATA_INTERVAL_MILLIS, ENVIO_THROTTLE_PRUNE_STALE_DATA_INTERVAL_MILLIS; the dev values 500 and 30000 are fine) lose their dev defaults, and the indexer won't start until they are set. ENVIO_PG_PASSWORD (testing) and ENVIO_PG_SCHEMA (public) keep their defaults, so set the password yourself. See Production mode for the full list.
Running the Indexer
The indexer container runs envio start (the start script in package.json). It:
- Runs codegen, so the image only needs your project files and dependencies.
- On the first run, creates the tables in
ENVIO_PG_SCHEMA(defaultpublic) and, when Hasura is enabled, tracks them in Hasura. - On later runs, resumes from the last checkpoint.
- Serves
/metricsand/healthzonENVIO_INDEXER_PORT(default9898). Point your container health check at/healthzon that port.node:*-slimimages have nocurl, so the compose file above probes it with Node'sfetch. See Observability.
envio start -r deletes the indexed data and starts over. A restart after changing the config, the schema or the envio version stops with The following config changes are incompatible with the existing indexer data:. Re-index with -r, or run the new version against a fresh ENVIO_PG_SCHEMA and switch over once it has synced. See Common Issues.
To match the versions envio dev uses locally, run postgres:18.3 and hasura/graphql-engine:v2.43.0. From postgres:18 on, mount the data volume at /var/lib/postgresql, not /var/lib/postgresql/data, or the container refuses to start. An existing Postgres 17 volume needs a dump and restore (or pg_upgrade) before Postgres 18 can use it.
Getting Help
If you encounter issues with self-hosting:
- Check the Envio GitHub repository for known issues
- Join the Envio Discord community for community support
For most production use cases, we recommend using Envio Cloud to benefit from automatic scaling, monitoring, and maintenance.