Skip to content

DoraFactory/amaci-indexer

Repository files navigation

SubQuery - Starter Package for Cosmos/CosmosHub

A basic Cosmos (based on CosmosHub) example project with an event and message handler. Read more about SubQuery support for Cosmos at https://academy.subquery.network/quickstart/quickstart_chains/cosmos.html.

The Starter Package is an example that you can use as a starting point for developing your SubQuery project.

A SubQuery package defines which data SubQuery will index from the blockchain, and how it will store it.

This Starter Package by default allows indexing transfer events and messages from CosmosHub.

Preparation

Environment and dependencies

  • Typescript is required to compile project and define types.

  • Both SubQuery CLI and generated Project have dependencies and require Node.

  • You will also need Yarn or NPM and Docker.

Install the SubQuery CLI and Project Dependencies

Install SubQuery CLI globally on your terminal by using NPM (we don't recommend using Yarn to install global dependencies):

npm install -g @subql/cli

Under the project directory, install the node dependencies by running the following command (Learn more):

yarn OR npm install

Configure the Project Further

If you want to change your project you will need to work on the following files:

  • The Manifest in project.yaml to configure your project
  • The GraphQL Schema in schema.graphql to define shape of the data
  • The Mapping functions in src/mappings/ directory to transform data coming from blockchain

Learn more

Build the Project

1. Generate Associated Typescript

We will generate the defined entity models with the following command:

yarn codegen OR npm run-script codegen

If you change any data in your schema.graphql, you should run this command again. You should also consider deleting your local database in the .data/ directory.

2. Build the project

This builds your project into static files within the /dist for running.

yarn build OR npm run-script codegen

If you change any data in your src/mappings/ directory you should run this command again.

Indexing and Query

1. Run Docker

Under the project directory run following command:

yarn start:docker

This will download packages from Docker, create a new Postgres database, and start an indexing an query service. When you first run this, it may take some time to start, please be patient.

2. Query this Project

Open your browser and head to http://localhost:3000.

Finally, you should see a GraphQL playground is showing in the explorer and the schemas that ready to query. On the right hand side is a documentation button that shows you what models you have to construct queries.

With this project can try to query with the following code to get a taste of how it works.

{
  query {
    transferEvents(first: 5) {
      nodes {
        id
        blockHeight
        txHash
        recipient
        sender
        amount
      }
    }
    messages(first: 5) {
      nodes {
        id
        blockHeight
        txHash
        from
        to
        amount
      }
    }
  }
}

**Query transacions **

# Write your query or mutation here
{
  query {
    transactions(first: 10, after: "",orderBy: [TIMESTAMP_DESC]) {
      pageInfo {
        endCursor
        hasNextPage
      }
      nodes {
        id
        blockHeight
        txHash
        timestamp
        type
        status
        roundId
        roundDescription
        circuitName
        fee
        gasUsed
        gasWanted
        caller
        contractAddress
        other
      }
      totalCount
    }
  }
}


# Write your query or mutation here
{
  query {
    transaction(id: "27C36133BC69F293E65425A82E6B8ABD5F4E4D7A1E95E2FE0EC305D8D3E4A9B6") {
        id
        blockHeight
        txHash
        timestamp
        type
        status
        roundId
        roundDescription
        circuitName
        fee
        gasUsed
        gasWanted
        caller
        contractAddress
        other
    }
  }
}

# query by filter
query HomePage {
  rounds(filter:{
    contractAddress:{
      equalTo: "dora1qv74a65wmarqwn6lhuj3mzwgn9jpljc2x0hc9w5d4hcgyhle2vtskv7t7t"
    }
  }){
    nodes {
        id
        blockHeight
        txHash
        operator
        contractAddress
        circuitName
        timestamp
        status
        period
        actionType
        roundId
        roundDescription
        maciDenom
        other
    }
  }
}

Query rounds

{
  query {
    rounds(first: 10, after: "",orderBy: [TIMESTAMP_DESC]) {
      pageInfo {
        endCursor
        hasNextPage
      }
      nodes {
        id
        blockHeight
        txHash
        operator
        contractAddress
        circuitName
        timestamp
        status
        period
        actionType
        roundId
        roundDescription
        maciDenom
        other
      }
      totalCount
    }
  }
}

Useful Resources

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages