Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add moonbeam substrate evm starter #85

Merged
merged 14 commits into from
Jul 25, 2023
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

while getopts p:o:e: flag
do
case "${flag}" in
e) ENDPOINT=${OPTARG};;
p) PROJECTNAME=${OPTARG};;
o) ORG=${OPTARG};;
*) echo "Usage: $0 [-p projectname] [-o org] [-e endpoint]" && exit 1;;
esac
done

IPFSCID=$(npx subql publish -o -f .)

npx subql deployment:deploy -d --ipfsCID="$IPFSCID" --projectName="${PROJECTNAME}" --org="${ORG%/*}" --endpoint="${ENDPOINT}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "CLI deploy"

on:
workflow_dispatch:
inputs:
projectName:
description: "Project name"
required: true
type: string
jobs:
deploy:
name: CLI Deploy
runs-on: ubuntu-latest
environment:
name: DEPLOYMENT
env:
SUBQL_ACCESS_TOKEN: ${{ secrets.SUBQL_ACCESS_TOKEN }}
ENDPOINT: ${{ secrets.ENDPOINT }}
steps:
- uses: actions/checkout@v2
- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 16
- run: yarn
- name: Codegen
run: yarn codegen
- name: Version
run: npx subql --version
- name: repo
run: echo ${{github.repository}}
- name: Publish and Deploy
run: |
sh .github/workflows/scripts/publish-deploy.sh -o ${{github.repository}} -p ${{github.event.inputs.projectName}} -e ${{secrets.ENDPOINT}}
24 changes: 24 additions & 0 deletions Moonbeam/moonbeam-substrate-evm-starter/.github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: PR
on:
pull_request:
paths-ignore:
- ".github/workflows/**"
jobs:
pr:
name: pr
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 16
- run: yarn
- name: Codegen
run: yarn codegen
- name: Build
run: yarn build
- name: Install subql-node
run: yarn global add @subql/node
- name: Run tests with Subquery Node
run: subql-node test -f ${{ github.workspace }}
57 changes: 57 additions & 0 deletions Moonbeam/moonbeam-substrate-evm-starter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore

# Node artifact files
node_modules/
dist/
.data/

# lock files
yarn.lock
package-lock.json

# Compiled Java class files
*.class

# Compiled Python bytecode
*.py[cod]

# Log files
*.log

# Package files
*.jar

# Maven
target/
dist/
src/types

# JetBrains IDE
.idea/

# Unit test reports
TEST*.xml

# Generated by MacOS
.DS_Store

# Generated by Windows
Thumbs.db

# Applications
*.app
*.exe
*.war

# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv

.data/*
1 change: 1 addition & 0 deletions Moonbeam/moonbeam-substrate-evm-starter/.project-cid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
QmcL3wVRtwgNYpgyfUfDJX3ZVUAe5j3qAmma9NN5DmCYtd
104 changes: 104 additions & 0 deletions Moonbeam/moonbeam-substrate-evm-starter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# SubQuery - Starter Package

A basic Frontier EVM + Substrate example project with an event handler for the FrontierEVM and call handler for Substrate calls. Read more about this at https://academy.subquery.network/quickstart/quickstart_chains/polkadot-moonbeam.html. This project can be used as a starting point for developing your SubQuery project

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 The SubQuery will index from the Substrate blockchain, and how it will store it.

## Preparation

#### Environment

- [Typescript](https://www.typescriptlang.org/) are required to compile project and define types.

- Both SubQuery CLI and generated Project have dependencies and require [Node](https://nodejs.org/en/).

#### Install the SubQuery CLI

Install SubQuery CLI globally on your terminal by using NPM:

```
npm install -g @subql/cli
```

Run help to see available commands and usage provide by CLI

```
subql help
```

## Initialize the starter package

Inside the directory in which you want to create the SubQuery project, simply replace `project-name` with your project name and run the command:

```
subql init project-name
```

Then you should see a folder with your project name has been created inside the directory, you can use this as the start point of your project. And the files should be identical as in the [Directory Structure](https://doc.subquery.network/directory_structure.html).

Last, under the project directory, run following command to install all the dependency.

```
yarn install
```

## Configure your project

In the starter package, we have provided a simple example of project configuration. You will be mainly working on the following files:

- The Manifest in `project.yaml`
- The GraphQL Schema in `schema.graphql`
- The Mapping functions in `src/mappings/` directory

For more information on how to write the SubQuery,
check out our doc section on [Define the SubQuery](https://doc.subquery.network/define_a_subquery.html)

#### Code generation

In order to index your SubQuery project, it is mandatory to build your project first.
Run this command under the project directory.

```
yarn codegen
```

## Build the project

In order to deploy your SubQuery project to our hosted service, it is mandatory to pack your configuration before upload.
Run pack command from root directory of your project will automatically generate a `your-project-name.tgz` file.

```
yarn build
```

## Indexing and Query

#### Run required systems in docker

Under the project directory run following command:

```
docker-compose pull && docker-compose up
```

#### Query the 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.

For the `subql-starter` project, you can try to query with the following code to get a taste of how it works.

```graphql
query {
erc20transfers (first: 10, orderBy: AMOUNT_DESC) {
nodes {
id
value
from
to
}
}
}
```
63 changes: 63 additions & 0 deletions Moonbeam/moonbeam-substrate-evm-starter/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
version: "3"

services:
postgres:
build:
context: .
dockerfile: ./docker/pg-Dockerfile
ports:
- 5432:5432
volumes:
- .data/postgres:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5

subquery-node:
image: onfinality/subql-node:latest
depends_on:
"postgres":
condition: service_healthy
restart: always
environment:
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
DB_HOST: postgres
DB_PORT: 5432
volumes:
- ./:/app
command:
#- test # set SUB_COMMAND env variable to "test" to run tests
- -f=/app
- --db-schema=app
healthcheck:
test: ["CMD", "curl", "-f", "http://subquery-node:3000/ready"]
interval: 3s
timeout: 5s
retries: 10

graphql-engine:
image: onfinality/subql-query:latest
ports:
- 3000:3000
depends_on:
"postgres":
condition: service_healthy
"subquery-node":
condition: service_healthy
restart: always
environment:
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
DB_HOST: postgres
DB_PORT: 5432
command:
- --name=app
- --playground
- --indexer=http://subquery-node:3000
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<EOF
CREATE EXTENSION IF NOT EXISTS btree_gist;
EOF
9 changes: 9 additions & 0 deletions Moonbeam/moonbeam-substrate-evm-starter/docker/pg-Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM postgres:12-alpine

# Variables needed at runtime to configure postgres and run the initdb scripts
ENV POSTGRES_DB 'postgres'
ENV POSTGRES_USER 'postgres'
ENV POSTGRES_PASSWORD 'postgres'

# Copy in the load-extensions script
COPY docker/load-extensions.sh /docker-entrypoint-initdb.d/
Loading