Skip to content

Create New Project

We advise anyone using rindexer to install docker which makes running locally with postgres storage a lot easier. If you not got docker you can install it here.

1. Create a new project

This will walk you through setting up your project by asking you a series of questions in the terminal.

no-code
rindexer new no-code

Example New

Initializing new rindexer project...
 
Project Name: RocketPoolETHIndexer
Project Description (skip by pressing Enter): My first rindexer project
Repository (skip by pressing Enter): https://github.com/joshstevens19/rindexer
What Storages To Enable? (graphql can only be supported if postgres is enabled) [postgres, csv, both, none]: postgres
Postgres Docker Support Out The Box? [yes, no]: yes
 
rindexer no-code project created with a rETH transfer events YAML template.

If any of the steps are unclear, you can find more information in the New Project Appendix.

Once completed a new boilerplate project will be created in the current directory. You can navigate to the project directory and start building your project. The boilerplate project is configured to index rETH transfer and approval events from ethereum mainnet between a specific block range.

2. Add Environment Variables

If you are not using postgres you can move straight to starting your project.

If you selected yes to the Postgres Docker Support Out The Box? question, a .env file has be generated for you with the required environment variables. You can move straight to starting your project.


Open up the generated .env file and fill in the required environment variables.

DATABASE_URL

For ease of running locally we suggest you enable docker support on the rindexer project, if you did not enable docker support with postgres storage you will need to provide a postgres database information in the .env file which has been generated for you.

sslmode=require is supported as well just include it in the connection string.

POSTGRES_PASSWORD

This is injected into the .env for your if you selected yes to the Postgres Docker Support Out The Box? question. This is used for the docker to create a postgres database for you locally. You do not need this if you have your own postgres database or on deployed environments. It is purely for local development.

POSTGRES_PASSWORD=password

Other Environment Variables

Every part of the rindexer.yaml file can be overridden by an environment variable. The syntax for this in the rindexer.yaml is ${ENV_VARIABLE_NAME} example ${POLYGON_RPC_URL}. This can be used in ANY field in the YAML file. Read more about the environment variables in the yaml configuration documentation.

3. Config your rindexer.yaml file

Generating a rindexer project will generate a rindexer.yaml file for you. This is where you will configure your project. You can read all about the rindexer.yaml settings in the yaml configuration documentation. You can also use the rindexer add command to add contracts to your project and pull in ABIs for you.

It will generate you an boilerplate project which is configured to index rETH transfer and approval events from ethereum mainnet between a specific block range.

name: rETHIndexer
description: My first rindexer project
repository: https://github.com/joshstevens19/rindexer
project_type: no-code
networks:
  - name: ethereum
    chain_id: 1
    rpc: https://mainnet.gateway.tenderly.co
storage:
  postgres:
    enabled: true
contracts:
  - name: RocketPoolETH
    details:
    - network: ethereum
      address: "0xae78736cd615f374d3085123a210448e74fc6393"
      start_block: 18600000
      end_block: 18718056
    abi: ./abis/RocketTokenRETH.abi.json
    include_events:
    - Transfer
    - Approval

4. Start the project

graphql and indexer
rindexer start all

5. Query the GraphQL API

GraphQL will be available at http://localhost:3001/graphql and the playground at http://localhost:3001/playground. You can read more about rindexer GraphQL API in the API documentation.

request
query AllTransfers($orderBy: [TransfersOrderBy!] = [BLOCK_NUMBER_DESC], $first: Int = 5) {
  allTransfers(orderBy: $orderBy, first: $first) {
    nodes {
      blockHash
      blockNumber
      contractAddress
      from
      network
      nodeId
      to
      txHash
      value
    }
    pageInfo {
      endCursor
      hasNextPage
      hasPreviousPage
      startCursor
    }
  }
}

Generate graphql queries

You can generate .graphql prebuilt queries to get up and running in seconds. These will be generated in a queries folder.

rindexer codegen graphql

TypeScript

graphql-codegen is the best tool on the market to generate TypeScript typings for your GraphQL queries, mutations, and subscriptions.

learn about the codegen.ts config here

the graphql API url is the schema in the config, you can set this to your graphql endpoint like so:

import { CodegenConfig } from '@graphql-codegen/cli'
 
const config: CodegenConfig = {
  // this is YOUR_GRAPHQL_API_URL
  schema: 'http://localhost:3001/graphql', 
  ...
}
 
export default config

then how you hook up the config with your tool of choice, below are some links to documentation:

.NET, Dart, Java, Flow

codegen for other languages can be found here

New Project Appendix

If you are not sure what to select this section will explain each step in more detail.

What Storages To Enable?

  • Postgres - This will use a postgres database to store the data.
  • Csv - This will store the data in a csv file on the machine.
  • Both - This will store the data in both a postgres database and a csv file.
  • None - This will not store the data anywhere.

Postgres Docker

  • Yes - This will use docker to spin up a postgres database for you, great for local development.
  • No - This will not use docker and you will need to provide a postgres database information in the .env file.