> For the complete documentation index, see [llms.txt](https://docs.envio.dev/llms.txt).

## Introduction

This tutorial provides a step-by-step guide to indexing a simple Greeter smart contract deployed on multiple blockchains. You'll learn how to set up and run a multichain indexer using Envio's template system.

### What is the Greeter Contract?

The [Greeter contract](https://github.com/Float-Capital/hardhat-template) is a straightforward smart contract that allows users to store greeting messages on the blockchain. For this tutorial, we'll be indexing instances of this contract deployed on both **Polygon** and **Linea**.

### What You'll Build

By the end of this tutorial, you'll have:

- A functioning multichain indexer that tracks greeting events
- The ability to query these events through a GraphQL endpoint
- Experience with Envio's core indexing functionality

## Prerequisites

Before starting, ensure you have the following installed:

- **[Node.js](https://nodejs.org/en/download/current)** _(v22 or newer recommended)_
- **[pnpm](https://pnpm.io/installation)** _(recommended but not required)_
- **[Docker Desktop](https://www.docker.com/products/docker-desktop/)** _(required to run the Envio indexer locally)_

> **Note:** Docker is specifically required to run your blockchain indexer locally. You can skip Docker installation if you plan only to use Envio Cloud.

## Step 1: Initialize Your Project

First, let's create a new project using Envio's Greeter template:

1. Open your terminal and run:

```bash
pnpx envio init
```

2. When prompted for a folder name, press Enter to use the current directory or type another path:

```
? Specify a folder name (ENTER to skip):  (.)
```

3. Choose the **Evm** ecosystem:

```
? Choose blockchain ecosystem
> Evm
  Svm
  Fuel
```

4. Select the **Greeter** template:

```
? Choose an initialization option
  From Address - Lookup ABI from block explorer
  From ABI File - Use your own ABI file
  Template: ERC20
> Template: Greeter
  Feature: External Calls
  Feature: Factory Contract
```

5. Add your Envio API token. Pick **Create a new API token** to open the token page, or **Add an existing API token**, then paste it at the `? Add your API token:` prompt:

```
? Add an Envio API token to your .env file?
> Create a new API token (Opens https://envio.dev/app/api-tokens)
  Add an existing API token
```

After completing these steps, Envio will generate all the necessary files for your indexer project, with event handlers in TypeScript.

If you are running this through an AI agent or a script, skip the prompts with the non-interactive equivalent. It needs an Envio API token, so create one at [envio.dev/app/api-tokens](https://envio.dev/app/api-tokens) and export it first, or pass `--api-token <token>`.

```bash
export ENVIO_API_TOKEN=your_token_here
pnpx envio init template -t greeter -l typescript -d .
```

## Step 2: Understanding the Generated Files

Let's examine the key files that were created:

### `config.yaml`

This configuration file defines which chains and contracts to index:

```yaml
# Partial example
chains:
  - id: 137 # Polygon
    # ... Polygon chain settings
    contracts:
      - name: Greeter
        address: "0x9D02A17dE4E68545d3a58D3a20BbBE0399E05c9c"
        # ... contract settings
  - id: 59144 # Linea
    # ... Linea chain settings
    contracts:
      - name: Greeter
        address: "0xdEe21B97AB77a16B4b236F952e586cf8408CF32A"
        # ... contract settings
```

### `schema.graphql`

This schema defines the data structures for the indexed events:

```graphql
type User {
  id: ID!
  greetings: [String!]!
  latestGreeting: String!
  numberOfGreetings: Int!
}
```

### `src/handlers/Greeter.ts`

This file contains the logic to process events emitted by the Greeter contract.

## Step 3: Start Your Indexer

> **Important:** Make sure Docker Desktop is running before proceeding.

1. Start the indexer with:

```bash
pnpm dev
```

This command:

- Launches Docker containers for the database and Hasura
- Sets up your local development environment
- Begins indexing data from the specified contracts
- Opens a terminal UI to monitor indexing progress

The indexer will retrieve data from both Polygon and Linea blockchains, starting from the blocks specified in your `config.yaml` file.

## Step 4: Interact with the Contracts

To see your indexer in action, you can write new greetings to the blockchain:

### For Polygon:

1. Visit the contract on [Polygonscan](https://polygonscan.com/address/0x9D02A17dE4E68545d3a58D3a20BbBE0399E05c9c#writeContract)
2. Connect your wallet
3. Use the `setGreeting` function to write a new greeting
4. Submit the transaction

### For Linea:

1. Visit the contract on [Lineascan](https://lineascan.build/address/0xdEe21B97AB77a16B4b236F952e586cf8408CF32A#writeContract)
2. Connect your wallet
3. Use the `setGreeting` function to write a new greeting
4. Submit the transaction

Since this is a multichain example, you can interact with both contracts to see how Envio handles data from different blockchains simultaneously.

## Step 5: Query the Indexed Data

Now you can explore the data your indexer has captured:

1. Open Hasura at [http://localhost:8080](http://localhost:8080)
2. When prompted for authentication, use the password: `testing`
3. Navigate to the **Data** tab to browse the database tables
4. Or use the **API** tab to write GraphQL queries

### Example Query

Try this query to see the users with the most greetings:

```graphql
query GetUsers {
  User(limit: 10, order_by: { numberOfGreetings: desc }) {
    id
    chainId
    latestGreeting
    numberOfGreetings
    greetings
  }
}
```

## Step 6: Deploy to Production (Optional)

When you're ready to move from local development to production:

1. Visit [Envio Cloud](https://envio.dev/app/login)
2. Follow the steps to deploy your indexer
3. Get a production GraphQL endpoint for your application

For detailed deployment instructions, see the [Envio Cloud documentation](https://docs.envio.dev/docs/HyperIndex/hosted-service.md).

## What You've Learned

By completing this tutorial, you've learned:

- How to initialize an Envio project from a template
- How indexers process data from multiple blockchains
- How to query indexed data using GraphQL
- The basic structure of an Envio indexing project

## Next Steps

Now that you've mastered the basics, you can:

- Try the [Contract Import](https://docs.envio.dev/docs/HyperIndex/quickstart.md) feature to index any deployed contract
- Customize the event handlers to implement more complex indexing logic
- Add relationships between entities in your schema
- Explore [Preload Optimization](https://docs.envio.dev/docs/HyperIndex/preload-optimization.md) for faster handlers
- Create aggregated statistics from your indexed data

For more tutorials and examples, visit the [Envio Documentation](https://docs.envio.dev/) or join our [Discord community](https://discord.gg/envio) for support.
