Introduction
Today we are going to make our first simple decentralized app using the blockchain.
The app is going to be a simple micro blog service.
Setup
ethereumjs-testrc is for running a local dev blockchain
web3 is the ethereum js client
solc is for compiling smart contracts
http-server for running the web app in a dev env
Creating the smart contract
MyBlog.sol
Read more about solidity
Compiling the smart contract and deploying the code to the blockchain
compile.js
Run the test blockchain by executing ./node_modules/.bin/testrpc
Then execute ‘node compile.js’ and save the outputs.
Building the web app
index.html
app.js (Use the outputs from the compile.js)
Note:
Difference between contract.getMessages() and contract.getMessages.call()
call() is for read operations, doesn’t cost gas and doesn’t write in the blockchain.
Calling a method directly, like getMessages(), is for writing in the blockchain and costs gas.
Read more about gas
Running
Run the website http-server -a localhost -p 8000 -c-1 .
Download the full code at github