nautls / ergo-graphql

Ergo Platform GraphQL server
MIT License
16 stars 1 forks source link
blockchain ergo explorer graphql

ergo-graphql

Ergo GraphQL server is on top of Ergo Platform's explorer database schema.

This repository also includes a TypeScript package for client-side static typing.

Project Setup (Manual)

$ npm ci

Environment file pattern

The .env file must be placed in the root directory following the pattern described below.

DB_HOST =                 # database host address
DB_PORT =                 # database host port
DB_NAME =                 # database name
DB_USER_NAME =            # database username
DB_USER_PWD =             # database password
DB_SSL =                  # optional: true or false

ERGO_NODE_ADDRESS =       # http ergo node address

REDIS_HOST = localhost    # optional: redis host address
REDIS_PORT = 6379         # optional: redis host port
REDIS_USER_NAME =         # optional: redis username
REDIS_USER_PWD =          # optional: redis user password

MAX_QUERY_DEPTH = 5       # optional: maximum query depth

Compile and run for development

$ npm run dev

Compile and run for production

$ npm run build
$ npm run start

Run unit tests

$ npm run test

Lint

$ npm run lint

Project Setup (Docker)

You can use Docker to setup the project, or just the redis, as well.

Building the ergo-graphql Docker image

$ docker -t ergo-graphql build .

Using docker-compose, you can run the whole project, or just the redis container.

Running the redis container

$ docker compose up -d redis # For older versions, use docker-compose

Running the whole project

$ docker compose up -d

Requesting Data

You can either install some REST-API client (like Insomnia and Postman). Or you can use curl to send a query as well:

$ curl -H 'Content-Type: application/json' -X POST -d '{"query": "query {...}"}' http://server.url

We have a set of queries/mutation as well:

Boxes (Query)

With this query, you can get boxes of the ergo blockchain. The arguments of this query are:

Tokens (Query)

Get tokens that have been minted on the ergo blockchain. The arguments of this query are:

Inputs (Query)

To get input boxes of transactions in the ergo blockchain. The arguments of this query are:

Transactions (Query)

To get the transactions of Ergo Blockchain. The arguments of this query are:

DataInputs (Query)

To get information about boxes that have been used as data input in the blockchain. The arguments of this query are:

BlockHeaders (Query)

To get info about the block headers of the blockchain. The arguments of this query are:

Addresses (Query)

To get information about some addresses on the blockchain. The argument of this query are:

Mempool (Query)

To get mempool boxes of the blockchain. This query does not have any arguments/filters.

Block (Query)

To get info about the block headers of the blockchain. The arguments of this query are:

State (Query)

To get the state of the graphql instance. This status contains difficulty, height, and the network. This query does not have any arguments/filters.

Info (Query)

To check info of the running graphql instance. This contains version for now.

CheckTransaction (Mutation)

To check whether a transaction is valid. It will return transaction id if it's valid, and empty string otherwise. The input of ths mutation is signedTransaction of type SignedTransaction which is:

type SignedTransaction {
  id: String!
  inpts: [TransactionInput!]!
  dataInputs: [TransactionDataInput!]!
  outputs: [TransactionOutput!]!
  size: Int
}

SubmitTransaction (Mutation)

To submit a transaction into the ergo blockchain. This will send the tx to the instance's node; if the operation suceeds it'll return the id of transaction. Input is the same SignedTransaction as defined above.