Last active
July 23, 2018 21:16
-
-
Save sogoiii/a65f3e409b0a52cf2e13847d10de41ba to your computer and use it in GitHub Desktop.
Server that can be used with the ethereum-to-graphql package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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