GithubHelp home page GithubHelp logo

mdawn / eospackandpull Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 91 KB

NodeJS EOS block store app using Docker, MongoDB & GraphQL

Dockerfile 1.57% JavaScript 90.87% HTML 7.56%
nodejs eos mongodb graphql blockchain

eospackandpull's Introduction

EOS Block Pack & Pull

A nodeJS app with a GraphQL endpoint. It pulls and stores EOS blocks in MongoDB through courtesy of a Docker image.

Description

This app can answer two questions:

  1. What was the last block ID we pulled into MongoDB, including timestamp and block number?

and

  1. Given a specific block number, what is our block's ID and timestamp?

Getting Set Up

STEP 1: Clone this repo. Cd in there.

STEP 2: Start Docker and run docker-compose up in your terminal.

STEP 3: Open a browser and navigate to http://localhost:4000/

Example Usage

  1. We want to pull an EOS block and store it in our database.
  • Click Pull Most Recent Block. Our click returns object info in a single line:
{"data":{"lastBlock":{"id":"000008f3080d4474105b3b76e0d4a28ac96ad2479bcdc4dcb136f6c5a759c64f","timestamp":"2019-02-18T00:59:48.000","txn_count":null,"block_num":"2291"}}}

In our case, we can see the last block pulled and stored is block number 2291.

  1. Now we want to get info related to a specific block we've previously stored.
  • Let's check on that last block we just pulled to make sure it went into the database. We enter 2291 into the text field and click the Pull by Block ID button. It returns:
{"data":{"blocks":[{"id":"000008f3080d4474105b3b76e0d4a28ac96ad2479bcdc4dcb136f6c5a759c64f","timestamp":"2019-02-18T00:59:48.000","txn_count":null,"block_num":"2291"}]}}

Success!

Try the GraphQL endpoint!

We can also use a GraphQL endpoint to request a wider variation of information by accessing http://localhost:4000/graphQL.

On the left side of the GraphQL pane, let's enter a query on the last block pulled (a.k.a. our favorite block 2291) by entering the following query into the left side of the GraphQL pane:

 {
   blocks(numbers: [2291]) {
     id
     block_num
     timestamp
     input_transactions {
       hex_data
     }
   }
   lastBlock{
     id
     block_num
   }
 }

We can then click the Execute Query button (or ^C + enter) and the right side of the GraphQL pane is populated like so:

{
  "data": {
    "blocks": [
      {
        "id": "000008f3080d4474105b3b76e0d4a28ac96ad2479bcdc4dcb136f6c5a759c64f",
        "block_num": "2291",
        "timestamp": "2019-02-18T00:59:48.000",
        "input_transactions": []
      }
    ],
    "lastBlock": {
      "id": "00000946ed91ee8931a32cf8f9e1bf2fdbe94dc6bf2805bfd6f80ab0f252f818",
      "block_num": "2374"
    }
  }
}

Our query returns information on block 2291 as well as information on the last pulled block, which is 2374.

eospackandpull's People

Contributors

mdawn avatar dependabot[bot] avatar

Watchers

James Cloos avatar  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.