Code Monkey home page Code Monkey logo

subquery-tests's Introduction

SubQuery - Example Project for Stellar Soroban

SubQuery is a fast, flexible, and reliable open-source data indexer that provides you with custom APIs for your web3 project across all of our supported networks. To learn about how to get started with SubQuery, visit our docs.

The example project indexes all soroban transfer events on Stellar's Mainnet. It also indexes all account payments including credits and debits

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!

Editing your SubQuery project

Although this is a working example SubQuery project, you can edit the SubQuery project by changing the following files:

  • The project manifest in project.yaml defines the key project configuration and mapping handler filters
  • The GraphQL Schema (schema.graphql) defines the shape of the resulting data that you are using SubQuery to index
  • The Mapping functions in src/mappings/ directory are typescript functions that handle transformation logic

SubQuery supports various layer-1 blockchain networks and provides dedicated quick start guides as well as detailed technical documentation for each of them.

Run your project

If you get stuck, find out how to get help below.

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 try to query with the following GraphQL code to get a taste of how it works.

{
  query {
    transfers(first: 5, orderBy: VALUE_DESC) {
      totalCount
      nodes {
        id
        date
        ledger
        toId
        fromId
        value
      }
    }
    accounts(first: 5, orderBy: SENT_TRANSFERS_COUNT_DESC) {
      nodes {
        id
        sentTransfers(first: 5, orderBy: LEDGER_DESC) {
          totalCount
          nodes {
            id
            toId
            value
          }
        }
        firstSeenLedger
        lastSeenLedger
      }
    }
  }
}

Results:

{
  "data": {
    "query": {
      "transfers": {
        "totalCount": 0,
        "nodes": []
      },
      "accounts": {
        "nodes": [
          {
            "id": "gbtbdklzbabdgnpvdygchqzxqxkjfu73ayhls44j7u26ti6lzvlzfg5a",
            "sentTransfers": {
              "totalCount": 0,
              "nodes": []
            },
            "firstSeenLedger": 1700000,
            "lastSeenLedger": 1700000
          },
          {
            "id": "gdea4efymx2vcx7hduurwvuy6de36qihe6faouhuzaldgul4ooq5euvu",
            "sentTransfers": {
              "totalCount": 0,
              "nodes": []
            },
            "firstSeenLedger": 1700000,
            "lastSeenLedger": 1700000
          },
          {
            "id": "gcbwgcat2nhokpnr2toy6o3qdky22lzzeydwh4azhdyyl57qfu53ugzr",
            "sentTransfers": {
              "totalCount": 0,
              "nodes": []
            },
            "firstSeenLedger": 1700000,
            "lastSeenLedger": 1700000
          },
          {
            "id": "gb7yga2xmamr6wqb2z5c4l6s2imudrqzu7zxdpr4df2dewcxpxhmzjy5",
            "sentTransfers": {
              "totalCount": 0,
              "nodes": []
            },
            "firstSeenLedger": 1700000,
            "lastSeenLedger": 1700000
          }
        ]
      }
    }
  }
}

You can explore the different possible queries and entities to help you with GraphQL using the documentation draw on the right.

Publish your project

SubQuery is open-source, meaning you have the freedom to run it in the following three ways:

  • Locally on your own computer (or a cloud provider of your choosing), view the instructions on how to run SubQuery Locally
  • By publishing it to our enterprise-level Managed Service, where we'll host your SubQuery project in production ready services for mission critical data with zero-downtime blue/green deployments. We even have a generous free tier. Find out how
  • [Coming Soon] By publishing it to the decentralised SubQuery Network, the most open, performant, reliable, and scalable data service for dApp developers. The SubQuery Network indexes and services data to the global community in an incentivised and verifiable way

What Next?

Take a look at some of our advanced features to take your project to the next level!

  • Multi-chain indexing support - SubQuery allows you to index data from across different layer-1 networks into the same database, this allows you to query a single endpoint to get data for all supported networks.
  • Dynamic Data Sources - When you want to index factory contracts, for example on a DEX or generative NFT project.
  • Project Optimisation Advice - Some common tips on how to tweak your project to maximise performance.
  • GraphQL Subscriptions - Build more reactive front end applications that subscribe to changes in your SubQuery project.

Need Help?

The fastest way to get support is by searching our documentation, or by joining our discord and messaging us in the #technical-support channel.

subquery-tests's People

Contributors

joaquinsoza avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.