Skip to content

Commit

Permalink
Content Rationalisation (#460)
Browse files Browse the repository at this point in the history
* Option Enabled; NEAR and EVM rationalised

* Cosmos snippets

* All snippets aggregated

* Intermediary Contributions [to be reset]

* snippets for Multi-Chain Removed

* Single-Chain EVM Quickstart Guides Rationalised

* Further Rationalisation

* Fixes

* Rationalised Multi-Chain Projects

* Reorganised Levels in Snippets

* Update location of snippets

---------

Co-authored-by: James Bayly <[email protected]>
  • Loading branch information
bgodlin and jamesbayly authored Jan 4, 2024
1 parent 7353930 commit 226349c
Show file tree
Hide file tree
Showing 105 changed files with 1,098 additions and 7,257 deletions.
88 changes: 5 additions & 83 deletions docs/quickstart/quickstart_chains/algorand.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
# Algorand Quick Start

## Goals

The goal of this quick guide is to adapt the standard starter project and start indexing [all the PLANET token transfers](https://algoexplorer.io/address/ZW3ISEHZUHPO7OZGMKLKIIMKVICOUDRCERI454I3DB2BH52HGLSO67W754) from Algorand. Check out the video or follow the step by step instructions below.

<br/>
<figure class="video_container">
<iframe src="https://www.youtube.com/embed/zWzKGT30zbE" frameborder="0" allowfullscreen="true"></iframe>
</figure>

::: warning Important
Before we begin, make sure that you have initialised your project using the provided steps in the **[Start Here](../quickstart.md)** section.
:::

Now, let's move forward and update these configurations.

Previously, in the [1. Create a New Project](../quickstart.md) section, you must have noted [3 key files](../quickstart.md#_3-make-changes-to-your-project). Let's begin updating them one by one.
<!-- @include: ../snippets/quickstart-reference.md -->

::: tip Note
The final code of this project can be found [here](https://github.com/subquery/algorand-subql-starter/tree/main/Algorand/algorand-starter).
Expand Down Expand Up @@ -169,71 +161,11 @@ Here, the function receives a `AlgorandTransaction` which includes all transacti

Check out our [Mappings](../../build/mapping/algorand.md) documentation to get more information on mapping functions.

## 4. Build Your Project

Next, build your work to run your new SubQuery project. Run the build command from the project's root directory as given here:

::: code-tabs
@tab:active yarn

```shell
yarn build
```

@tab npm

```shell
npm run-script build
```

:::

::: warning Important
Whenever you make changes to your mapping functions, you must rebuild your project.
:::

Now, you are ready to run your first SubQuery project. Let’s check out the process of running your project in detail.

## 5. Run Your Project Locally with Docker

Whenever you create a new SubQuery Project, first, you must run it locally on your computer and test it and using Docker is the easiest and quickiest way to do this.

The `docker-compose.yml` file defines all the configurations that control how a SubQuery node runs. For a new project, which you have just initialised, you won't need to change anything.

However, visit the [Running SubQuery Locally](../../run_publish/run.md) to get more information on the file and the settings.
<!-- @include: ../snippets/build.md -->

Run the following command under the project directory:
<!-- @include: ../snippets/run-locally.md -->

::: code-tabs
@tab:active yarn

```shell
yarn start:docker
```

@tab npm

```shell
npm run-script start:docker
```

:::

::: tip Note
It may take a few minutes to download the required images and start the various nodes and Postgres databases.
:::

## 6. Query your Project

Next, let's query our project. Follow these three simple steps to query your SubQuery project:

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

2. You will see a GraphQL playground in the browser and the schemas which are ready to query.

3. Find the _Docs_ tab on the right side of the playground which should open a documentation drawer. This documentation is automatically generated and it helps you find what entities and methods you can query.

Try the following query to understand how it works for your new SubQuery starter project. Don’t forget to learn more about the [GraphQL Query language](../../run_publish/query.md).
<!-- @include: ../snippets/query-intro.md -->

```graphql
query {
Expand Down Expand Up @@ -431,14 +363,4 @@ You will see the result similar to below:
The final code of this project can be found [here](https://github.com/subquery/algorand-subql-starter/tree/main/Algorand/algorand-starter).
:::

## What's next?

Congratulations! You have now a locally running SubQuery project that accepts GraphQL API requests for transferring data.

::: tip Tip

Find out how to build a performant SubQuery project and avoid common mistakes in [Project Optimisation](../../build/optimisation.md).

:::

Click [here](../../quickstart/whats-next.md) to learn what should be your **next step** in your SubQuery journey.
<!-- @include: ../snippets/whats-next.md -->
143 changes: 15 additions & 128 deletions docs/quickstart/quickstart_chains/arbitrum.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
# Arbitrum Quick Start

## Goals

The goal of this quick start guide is to index the total claimed dividends paid to users on the [WINR staking contract](https://arbiscan.io/address/0xddAEcf4B02A3e45b96FC2d7339c997E072b0d034) on Arbitrum. Check out the video or follow the step by step instructions below.

<br/>
<figure class="video_container">
<iframe src="https://www.youtube.com/embed/7N-GE3ZuNdM" frameborder="0" allowfullscreen="true"></iframe>
</figure>

::: warning
Before we begin, **make sure that you have initialised your project** using the provided steps in the [Start Here](../quickstart.md) section. Please initialise an Arbitrum Nova project
:::

In every SubQuery project, there are [3 key files](../quickstart.md#_3-make-changes-to-your-project) to update. Let's begin updating them one by one.
<!-- @include: ../snippets/evm-quickstart-reference.md -->

::: tip Note
The final code of this project can be found [here](https://github.com/subquery/ethereum-subql-starter/tree/main/Arbitrum/arbitrum-one-winr). We use Ethereum packages, runtimes, and handlers (e.g. `@subql/node-ethereum`, `ethereum/Runtime`, and `ethereum/*Hander`) for Arbitrum. Since Arbitrum is an EVM-compatible layer-2 scaling solution, we can use the core Ethereum framework to index it.
The final code of this project can be found [here](https://github.com/subquery/ethereum-subql-starter/tree/main/Arbitrum/arbitrum-one-winr).
:::

## 1. Your Project Manifest File
We use Ethereum packages, runtimes, and handlers (e.g. `@subql/node-ethereum`, `ethereum/Runtime`, and `ethereum/*Hander`) for Arbitrum. Since Arbitrum is an EVM-compatible layer-2 scaling solution, we can use the core Ethereum framework to index it.

The Project Manifest (`project.ts`) file works as an entry point to your Arbitrum project. It defines most of the details on how SubQuery will index and transform the chain data. For Arbitrum, there are three types of mapping handlers (and you can have more than one in each project):

- [BlockHanders](../../build/manifest/arbitrum.md#mapping-handlers-and-filters): On each and every block, run a mapping function
- [TransactionHandlers](../../build/manifest/arbitrum.md#mapping-handlers-and-filters): On each and every transaction that matches optional filter criteria, run a mapping function
- [LogHanders](../../build/manifest/arbitrum.md#mapping-handlers-and-filters): On each and every log that matches optional filter criteria, run a mapping function

Note that the manifest file has already been set up correctly and doesn’t require significant changes, but you need to import the correct contract definitions and update the datasource handlers.
<!-- @include: ../snippets/evm-manifest-intro.md#level2 -->

As we are indexing all claimed dividends from the WINR contract, the first step is to import the contract abi definition which can be obtained from [here](https://arbiscan.io/address/0xddaecf4b02a3e45b96fc2d7339c997e072b0d034#code). Copy the entire contract ABI and save it as a file called `winr-staking.abi.json` in the `/abis` directory.

Expand Down Expand Up @@ -74,11 +62,9 @@ As we are indexing all claimed dividends from the WINR contract, the first step

The above code indicates that you will be running a `handleDividendBatch` mapping function whenever there is a `ClaimDividendBatch` log on any transaction from the [WINR contract](https://arbiscan.io/address/0xddaecf4b02a3e45b96fc2d7339c997e072b0d034#code).

Check out our [Manifest File](../../build/manifest/arbitrum.md) documentation to get more information about the Project Manifest (`project.ts`) file.
<!-- @include: ../snippets/arbitrum-manifest-note.md -->

## 2. Update Your GraphQL Schema File

The `schema.graphql` file determines the shape of your data from SubQuery due to the mechanism of the GraphQL query language. Hence, updating the GraphQL Schema file is the perfect place to start. It allows you to define your end goal right at the start.
<!-- @include: ../snippets/schema-intro.md#level2 -->

Remove all existing entities and update the `schema.graphql` file as follows. Here you can see we are indexing block information such as the id, blockHeight and timestamp along with the user, the total rewards and the dividends.

Expand All @@ -98,48 +84,17 @@ type User @entity {
}
```

SubQuery makes it easy and type-safe to work with your GraphQL entities, as well as smart contracts, events, transactions, and logs. SubQuery CLI will generate types from your project's GraphQL schema and any contract ABIs included in the data sources.

::: code-tabs
@tab:active yarn

```shell
yarn codegen
```

@tab npm

```shell
npm run-script codegen
```

:::
<!-- @include: ../snippets/note-on-entity-relationships.md -->

This will create a new directory (or update the existing one) `src/types` which contains generated entity classes for each type you have defined previously in `schema.graphql`. These classes provide type-safe entity loading, and read and write access to entity fields - see more about this process in [the GraphQL Schema](../../build/graphql.md). All entities can be imported from the following directory:
<!-- @include: ../snippets/evm-codegen.md -->

```ts
import { Dividend, User } from "../types";
```

As you're creating a new EVM based project, this command will also generate ABI types and save them into `src/types` using the `npx typechain --target=ethers-v5` command, allowing you to bind these contracts to specific addresses in the mappings and call read-only contract methods against the block being processed.

It will also generate a class for every contract event to provide easy access to event parameters, as well as the block and transaction the event originated from. Read about how this is done in [EVM Codegen from ABIs](../../build/introduction.md#evm-codegen-from-abis).
<!-- @include: ../snippets/schema-note.md -->

In this example SubQuery project, you would import these types like so.

```ts
import { ClaimDividendBatchLog } from "../types/abi-interfaces/WinrStakingAbi";
```

::: warning Important
When you make any changes to the schema file, please ensure that you regenerate your types directory using the SubQuery CLI prompt `yarn codegen` or `npm run-script codegen`.
:::

Check out the [GraphQL Schema](../../build/graphql.md) documentation to get in-depth information on `schema.graphql` file.

## 3. Add a Mapping Function

Mapping functions define how chain data is transformed into the optimised GraphQL entities that we previously defined in the `schema.graphql` file.
<!-- @include: ../snippets/mapping-intro.md#level2 -->

Navigate to the default mapping function in the `src/mappings` directory. You will be able to see three exported functions: `handleBlock`, `handleLog`, and `handleTransaction`. Replace these functions with the following code:

Expand Down Expand Up @@ -186,71 +141,13 @@ The `handleDividendBatch` function receives a `batchDividendLog` parameter of ty

Check out our [Mappings](../../build/mapping/arbitrum.md) documentation to get more information on mapping functions.

## 4. Build Your Project

Next, build your work to run your new SubQuery project. Run the build command from the project's root directory as given here:

::: code-tabs
@tab:active yarn

```shell
yarn build
```

@tab npm

```shell
npm run-script build
```

:::

::: warning Important
Whenever you make changes to your mapping functions, you must rebuild your project.
:::

Now, you are ready to run your first SubQuery project. Let’s check out the process of running your project in detail.

## 5. Run Your Project Locally with Docker

Whenever you create a new SubQuery Project, first, you must run it locally on your computer and test it and using Docker is the easiest and quickest way to do this.
<!-- @include: ../snippets/arbitrum-mapping-note.md -->

The `docker-compose.yml` file defines all the configurations that control how a SubQuery node runs. For a new project, which you have just initialised, you won't need to change anything.
<!-- @include: ../snippets/build.md -->

However, visit the [Running SubQuery Locally](../../run_publish/run.md) to get more information on the file and the settings.
<!-- @include: ../snippets/run-locally.md -->

Run the following command under the project directory:

::: code-tabs
@tab:active yarn

```shell
yarn start:docker
```

@tab npm

```shell
npm run-script start:docker
```

:::

::: tip Note
It may take a few minutes to download the required images and start the various nodes and Postgres databases.
:::

## 6. Query your Project

Next, let's query our project. Follow these three simple steps to query your SubQuery project:

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

2. You will see a GraphQL playground in the browser and the schemas which are ready to query.

3. Find the _Docs_ tab on the right side of the playground which should open a documentation drawer. This documentation is automatically generated and it helps you find what entities and methods you can query.

Try the following query to understand how it works for your new SubQuery starter project. Don’t forget to learn more about the [GraphQL Query language](../../run_publish/query.md).
<!-- @include: ../snippets/query-intro.md -->

```graphql
# Write your query or mutation q{here
Expand Down Expand Up @@ -315,14 +212,4 @@ You will see the result similar to below:
The final code of this project can be found [here](https://github.com/subquery/ethereum-subql-starter/tree/main/Arbitrum/arbitrum-one-winr).
:::

## What's next?

Congratulations! You have now a locally running SubQuery project that accepts GraphQL API requests for transferring data.

::: tip Tip

Find out how to build a performant SubQuery project and avoid common mistakes in [Project Optimisation](../../build/optimisation.md).

:::

Click [here](../../quickstart/whats-next.md) to learn what should be your **next step** in your SubQuery journey.
<!-- @include: ../snippets/whats-next.md -->
Loading

0 comments on commit 226349c

Please sign in to comment.