Skip to content

Instantly share code, notes, and snippets.

@sogoiii
Last active July 23, 2018 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sogoiii/a65f3e409b0a52cf2e13847d10de41ba to your computer and use it in GitHub Desktop.
Save sogoiii/a65f3e409b0a52cf2e13847d10de41ba to your computer and use it in GitHub Desktop.
Server that can be used with the ethereum-to-graphql package
const express = require('express')
const graphqlHTTP = require('express-graphql')
const Web3 = require('web3')
const TFcontract = require('truffle-contract')
const MetaCoinArtifact = require('./build/contracts/Metacoin')
const MetCoinContract = TFcontract(MetaCoinArtifact)
MetCoinContract.setProvider(new Web3.providers.HttpProvider('http://localhost:8545'))
const { genGraphQlProperties } = require('ethereum-to-graphql')
const { schema, rootValue } = genGraphQlProperties({ artifact: MetaCoinArtifact, contract: MetCoinContract })
const GRAPHQL_PORT = 4000
const app = express()
app.use('/graphql', graphqlHTTP({
schema,
rootValue,
graphiql: true
}))
app.listen(GRAPHQL_PORT, () => console.log(
`GraphiQL is now running on http://localhost:${GRAPHQL_PORT}/graphiql
Only for Development purposes!`
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment