katopz / ethereum-to-graphql

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ethereum ABI to GraphQL Scheme

This will consume an ABI object created when deploying a Solidity/Viper/Serpent Smart contract, and return a graphql schema and resolver. This object can be plugged into a the graphql server of your choice.

Setup:

Install the package with npm or yarn.

  1. npm install ethereum-to-graphql
  2. yarn add ethereum-to-graphql

Your server will have to read an abi file and pass it through this package. We return an object that you pass into your graqhQL server.

const express = require('express');
const graphqlHTTP = require('express-graphql');
const graphql = require('graphql')

const app = express();
const MetaCoinArtifact = require('./build/contracts/Metacoin')
const url = 'http://localhost:8545'

const { genGraphQlProperties } = require('ethereum-to-graphql')
const { schema, rootValue } = genGraphQlProperties({ artifacts: [MetaCoinArtifact], provider: { url }, graphql })


app.use('/graphql', graphqlHTTP({
  schema: schema,
  rootValue: rootValue,
  graphiql: true
}));

app.listen(4000);

Testing

To run tests, you will need to have truffle and testrpc installed globally.

  1. Terminal Window 1: cd <this project>
  2. Terminal Window 1: testrpc
  3. Terminal Window 2: cd <this project>
  4. Terminal Window 2: truffle migrate
  5. Terminal Window 2: npm test

Gotcha

FYI : use "web3": "0.19.0" to not breaking thing

testrpc
yarn install
yarn build
yarn deploy
yarn test
yarn server
yarn client-react
open http://localhost:4000/graphql

About


Languages

Language:JavaScript 100.0%