This example shows how to build a social network on a Loom DAppChain, using Web3
and Loom.js.
In this simple social network, users can post and comment on posts. The source is available on Github.
We used Solidity version 0.4.24 to compile this smart contract.
Development
1.) Run your own DappChain
First, please ensure you've installed Golang as documented in the prerequisites.
Let's start by cloning the solidity-social-example
repo:
git clone https://github.com/loomnetwork/solidity-social-example
cd solidity-social-example
Next, we need to download the loom binary:
cd dappchain
curl https://raw.githubusercontent.com/loomnetwork/loom-sdk-documentation/master/scripts/get_loom.sh | sh
chmod +x loom
and configure it:
./loom init
cp genesis.example.json genesis.json
To start loom, type:
./loom run
2.) Start ElasticSearch and Redis
Note that both services are required in order to run and interact with the application
If you are using macOS, run the following commands to install elasticsearch
and redis
:
brew tap homebrew/services
brew install elasticsearch
brew install redis
Start the services with
brew services start elasticsearch
brew services start redis
3.) Start indexer
The indexer is a service that will receive all events from the smart contract and feed a cache layer built on a message queue and a fast database (Redis + ElasticSearch).
The data accumulated by this service is served at http://localhost:8081/posts
and http://localhost:8081/comments
For the best performance, we recommend you use Node8:
brew install node@8
In a new terminal, run the following:
cd solidity-social-example/webclient
yarn
node indexer.js
4.) Start the web server
The webserver will serve the content which allows users to interact with the smart contracts on the Loom DappChain.
First, fire up a third terminal, cd
into the webclient
directory, and install dependencies:
cd solidity-social-example/webclient
yarn
Finally, let's start the front-end:
yarn start
5.) Interacting with the application
Open http://localhost:8080
in your web browser of choice.