|
| 1 | +# SubQuery - Example Project for Oasis Sapphire Devnet |
| 2 | + |
| 3 | +[SubQuery](https://subquery.network) 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](https://academy.subquery.network). |
| 4 | + |
| 5 | +**This SubQuery project indexes all transfers and approval events for the [OCEAN Token](https://explorer.sapphire.oasis.io/token/0x39d22B78A7651A76Ffbde2aaAB5FD92666Aca520/token-transfers) on Oasis Sapphire** |
| 6 | + |
| 7 | +## Start |
| 8 | + |
| 9 | +First, install SubQuery CLI globally on your terminal by using NPM `npm install -g @subql/cli` |
| 10 | + |
| 11 | +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. |
| 12 | + |
| 13 | +Don't forget to install dependencies with `npm install` or `yarn install`! |
| 14 | + |
| 15 | +## Editing your SubQuery project |
| 16 | + |
| 17 | +Although this is a working example SubQuery project, you can edit the SubQuery project by changing the following files: |
| 18 | + |
| 19 | +- The project manifest in `project.ts` defines the key project configuration and mapping handler filters |
| 20 | +- The GraphQL Schema (`schema.graphql`) defines the shape of the resulting data that you are using SubQuery to index |
| 21 | +- The Mapping functions in `src/mappings/` directory are typescript functions that handle transformation logic |
| 22 | + |
| 23 | +SubQuery supports various layer-1 blockchain networks and provides [dedicated quick start guides](https://academy.subquery.network/quickstart/quickstart.html) as well as [detailed technical documentation](https://academy.subquery.network/build/introduction.html) for each of them. |
| 24 | + |
| 25 | +## Run your project |
| 26 | + |
| 27 | +_If you get stuck, find out how to get help below._ |
| 28 | + |
| 29 | +The simplest way to run your project is by running `yarn dev` or `npm run-script dev`. This does all of the following: |
| 30 | + |
| 31 | +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 |
| 32 | +2. `yarn build` - Builds and packages the SubQuery project into the `/dist` directory |
| 33 | +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](https://docs.docker.com/engine/install) and running locally. The configuration for this container is set from your `docker-compose.yml` |
| 34 | + |
| 35 | +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](http://localhost:3000) - you should see a GraphQL playground showing with the schemas ready to query. [Read the docs for more information](https://academy.subquery.network/run_publish/run.html) or [explore the possible service configuration for running SubQuery](https://academy.subquery.network/run_publish/references.html). |
| 36 | + |
| 37 | +## Query your project |
| 38 | + |
| 39 | +For this project, you can try to query with the following GraphQL code to get a taste of how it works. |
| 40 | + |
| 41 | +```graphql |
| 42 | +{ |
| 43 | + query { |
| 44 | + transfers(first: 5, orderBy: VALUE_DESC) { |
| 45 | + totalCount |
| 46 | + nodes { |
| 47 | + id |
| 48 | + blockHeight |
| 49 | + from |
| 50 | + to |
| 51 | + value |
| 52 | + contractAddress |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + approvals(first: 5, orderBy: BLOCK_HEIGHT_DESC) { |
| 57 | + nodes { |
| 58 | + id |
| 59 | + blockHeight |
| 60 | + owner |
| 61 | + spender |
| 62 | + value |
| 63 | + contractAddress |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +You can explore the different possible queries and entities to help you with GraphQL using the documentation draw on the right. |
| 70 | + |
| 71 | +## Publish your project |
| 72 | + |
| 73 | +SubQuery is open-source, meaning you have the freedom to run it in the following three ways: |
| 74 | + |
| 75 | +- Locally on your own computer (or a cloud provider of your choosing), [view the instructions on how to run SubQuery Locally](https://academy.subquery.network/run_publish/run.html) |
| 76 | +- By publishing it to our enterprise-level [Managed Service](https://managedservice.subquery.network), 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](https://academy.subquery.network/run_publish/publish.html) |
| 77 | +- [Coming Soon] By publishing it to the decentralised [SubQuery Network](https://subquery.network/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 |
| 78 | + |
| 79 | +## What Next? |
| 80 | + |
| 81 | +Take a look at some of our advanced features to take your project to the next level! |
| 82 | + |
| 83 | +- [**Multi-chain indexing support**](https://academy.subquery.network/build/multi-chain.html) - 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. |
| 84 | +- [**Dynamic Data Sources**](https://academy.subquery.network/build/dynamicdatasources.html) - When you want to index factory contracts, for example on a DEX or generative NFT project. |
| 85 | +- [**Project Optimisation Advice**](https://academy.subquery.network/build/optimisation.html) - Some common tips on how to tweak your project to maximise performance. |
| 86 | +- [**GraphQL Subscriptions**](https://academy.subquery.network/run_publish/subscription.html) - Build more reactive front end applications that subscribe to changes in your SubQuery project. |
| 87 | + |
| 88 | +## Need Help? |
| 89 | + |
| 90 | +The fastest way to get support is by [searching our documentation](https://academy.subquery.network), or by [joining our discord](https://discord.com/invite/subquery) and messaging us in the `#technical-support` channel. |
0 commit comments