Skip to content

LottoDapp/lotto-subquery

Repository files navigation

SubQuery for the Lotto Dapp

**This SubQuery project indexes all events from the Lotto dApp **

Start

First, install SubQuery CLI globally on your terminal by using NPM npm install -g @subql/cli

You can either clone this GitHub repo, or use the subql CLI to bootstrap a clean project in the network of your choosing by running subql init and following the prompts.

Don't forget to install dependencies with npm install or yarn install!

Run your project

The simplest way to run your project is by running yarn dev or npm run-script dev. This does all of the following:

  1. yarn codegen - Generates types from the GraphQL schema definition and contract ABIs and saves them in the /src/types directory. This must be done after each change to the schema.graphql file or the contract ABIs
  2. yarn build - Builds and packages the SubQuery project into the /dist directory
  3. docker-compose pull && docker-compose up - Runs a Docker container with an indexer, PostgeSQL DB, and a query service. This requires Docker to be installed and running locally. The configuration for this container is set from your docker-compose.yml

You can observe the three services start, and once all are running (it may take a few minutes on your first start), please open your browser and head to http://localhost:3000 - you should see a GraphQL playground showing with the schemas ready to query. Read the docs for more information or explore the possible service configuration for running SubQuery.

Query your project

For this project, you can use the following GraphQL code to query the data.

Query all participations

    query {
      participations {
        nodes { id, accountId, numRaffle, numbers }
      }
    }

Query a participation for a given raffle and given account

    query GetParticipations($numRaffle: BigFloat, $accountId: String){      
      participations(filter: {and: [{numRaffle: {equalTo: $numRaffle}}, {accountId: {equalTo: $accountId}}]}){
        nodes{ accountId, numRaffle, numbers }
      }  
    }

Query all results

    query {      
      results(orderBy: NUM_RAFFLE_DESC){
        nodes{ numRaffle, numbers }
      }  
    }

Query all winners

    query{      
      winners(orderBy: NUM_RAFFLE_DESC){
        nodes{numRaffle, accountId}
      }
  }