This is a PoC project to attemt to create an ethereum based smart contract backend for TheCommunityMind. The repo for the current project can be found here
My vision for this project is explained in this article.
This project uses a number of different technologies that I am exploring in order to achieve my goal.
- Solidity - The language used to develop smart contracts for the Ethereum network
- Truffle - a suite of tools used to compile and develop smart contracts in Ethereum. These incude:
- TheGraph - Used to index events and enables queries of these events using GraphQl
- React - Frontend will be written using react
- Apollo - A connector used to wrap graphql queries in React components and inject responses as props
This project can be run locally but requires some quite complicated pre installations.
-
Install Ganache - This is for your local development blockchain
-
Install TheGraph node and dependencies - see Quick Start section
-
Clone the repo
git clone https://github.com/Blockternship/TheCommunityMind.git
- Install packages
cd TheCommunityMind
npm install
cd mind-subgraph
npm install
cd ../client
npm install
-
Start up Ganache
-
In the main folder TheCommunityMind compile and migrate contracts
truffle compile
truffle migrate
- Install modules in mind-subgraph folder
cd mind-subgraph
npm install
- Start IPFS in a fresh terminal
ipfs daemon
- Copy the address of the migtrated TheMind contract (should be printed to terminal) to the subgraph.yaml file under:
dataSources:
- kind: ethereum/contract
name: TheMind
source:
address: ***
- Create a symlink between your build folder containing the contract json files and an abis folder
ln -s ../build/contracts abis
- build and deploy subgraph to IPFS - This will produce an IPFS_HASH in the terminal
npm run build-ipfs
- Start a local Graph node - You need to be in the graph-node project which should have been cloned as part of step 2. See Running a Local Graph Node in the docs.
cargo run -p graph-node --release -- \
--postgres-url postgresql://USERNAME[:PASSWORD]@localhost:5432/adchain-subgraph \
--ethereum-rpc localhost:http://localhost:8545 \
--ipfs 127.0.0.1:5001 \
--subgraph IPFS_HASH
Note: 8545 should be the port your ganache blockchain is running on. Can be checked by going to settings in ganache.
- Visit the graphiql interface at http://127.0.0.1:8000/ where you can query your indexed events (There wont be any indexed events yet)
- Install node modules in client folder
cd ../client
npm install
- Start the client
npm start
- You will need to have MetaMask installed and pointing to your local blockchain - see here
The status of this project currently is a simple smart contract that allows users to ask a Question via a text input. All I currently aim to check is that the events are indexed and can be searched via the graphql interface. Give it a try.
I will be working to create a proper interface and integrate the graphql search into the frontend using Apollo.
Don't hesitate to get in touch if you want to get involved!