Code Monkey home page Code Monkey logo

smart-contract-backend's Introduction

Smart Contract Service

The purpose of this repository is to demonstrate how to use smart contracts and any tools in the etherium development environment to successfully demo a working implementation of a smart contract. The smart contract created is a simple implementation of a storage for user's looking to store personal descriptors (weight, height, or any other units they want).

Install

Ensure that you have the latest Node.js installed.

Download ganache GUI. This is a local blockchain that you can run on your own computer for development/tests. There is a command line version that we use as well but this can be a lot easier to visualize.

Sometimes the compilation of some libraries can fail if you don't have a c/c++ compiler installed since the Solidity compiler needs it. For linux systems, ensure gcc/g++ is installed; for Windows install VS2019 and ensure that you download the C++ windows toolchains.

Install all needed libraries with the following npm (Node Package Manager) command:

npm install         # This will install all dependencies listed in package.json in ./node_modules

To generate the final GraphQL Schema, compile Smart Contracts, generate types for TypeScript from the Smart Contracts(to make development easier), and finally compiling TypeScript down to JavaScript, run the following:

npm run build       # This should run automatically after npm install for the first time

How to start the service

First we need to get the Etherium Blockchain ready, start the Genache GUI. Run the following command afterwards to upload the smart contracts. In addition to this, dummy data will be put in for testing (might take awhile!).

npm run migrate

Then just start the server!

npm start

Query the GraphQL API!

The GraphQL API endpoint is the following

http://localhost:8080/graphql     #POST Request Only!

You can query the API after starting the server by using a Altair GraphQL frontend client (available in Chrome/Firefox/etc).

It looks something like this:

Try pasting the following query after following the above steps

query {
  getPaginatedDescriptors(unit:"lb", start: 0, count: 15) {
    value
    latitude
    longitude
  }
}

Prepare your editor

The editor of choice is VSCode for its extensive support for JavaScript and TypeScript development. it is strongly suggested that you use it. Two MUST HAVE extensions for VSCode is TSLint (deprecated) and Prettier. TSLint catches errors and enforces policies for TypeScript code, and Prettier formats your code when you save to a standard format. Configurations for TSLint can be found at tslint.json. Please ensure you are downloading the deprecated version of TSLint as that has Autosave functionality.

License

MIT

smart-contract-backend's People

Contributors

akashworld avatar rizthe1andonly avatar suvashahria avatar

Watchers

 avatar  avatar  avatar

Forkers

suvashahria

smart-contract-backend's Issues

Set up test infrastructure for NodeJS

While we have a working test for etherium smart contracts, we need to set up the infrastructure for unit tests and integration tests for our Node server.

Figure out first schema for data

We want to create a line graph that represents data over a period of time for a specific unit. Create a schema that needs to be implemented by both front end and back end.

Example:
Input Parameters: Unit, Amount of Values, etc
Return Values:

Then show examples

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.