Server Side

DAPP Backend – Requires RPC Server. Remember DAPP backend runs on ALL the nodes (blockchain)!

DAPP Frontent – Requires a web server (for now) and a special browser (MIST) or an extension such as Metamask – which supports wallets..

Write your smart contract – An Auction Contract

Contract Data Storage

Storing data in smart contracts can be very expensive. Include a separate field for storing an IPFS hash. For things like the contract’s title and description, photo URLs, etc.   If you need to associate large amounts of metadata with your contract that isn’t critical to its business logic, it’s a much better idea to find an off-chain storage solution, and simply store a reference so that it can be retrieved separately. We’re not going to refer to the ipfsHash field in this tutorial; it’s included as a reminder of proper contract/dApp architecture.

Define Contract Preconditions

Implement preconditions with Solidity’s function modifiers. Let’s imagine we want to place the following constraints on our placeBid() function:

placeBid() Function – Users should be able to send ETH to this function, and depending on how much they sent, they will either become the highestBidder or will cause the highestBindingBid to increase.

Interacting with the Ethereum Blockchain

GETH is an entire blockchain – and you can download and run GETH locally. This will let you create one or more nodes on your local machine; which will still be synchronized with other GETH nodes.

Option 1-  MetaMask

Chrome extension to generate a wallet. This is going to be the owner of the smart contract

Option 2 – Mist

  • Mist connects to a single node on the GETH chain.  Mist is simply the browser, however, it allows you to perform all transactions on the GETH chain, without downloading the entire chain.
  • Mist is an electron app – meaning that it is a desktop hybrid app with a web interface as well. This allows for faster development and changes of the Mist interface and helps with the browser part of Mist.
  • Mist is powerful in that it includes a Geth node that runs in the background upon launch; a connection to the Ethereum blockchain (either a TEST BLOCKCHAIn or the MAIN EThereum Chain) is made right away.
  • Mist is different from just the ethereum wallet. The ethereum wallet takes hours to sync. The mist app synced in 30 minutes.
  • Tip : From the cmd prompt, remove chaindata and run geth --fast:
    • Opened the cmd prompt

    • Navigated to the directory containing geth.exe and opened it

    • Copied the file path from the bar Explorer

    • Typed cd path/to/geth (replace path/to/geth with what you copied) and hit enter.

    • Typed geth removedb and hit enter.

    • Once the blockchain was removed, I ran geth --fast

Compile your code – Options

  1. Sublime Text Editor
  2. Visual Studio Solidity Extension 
  3.  Remix IDE (an online solidity compiler and debugger) and paste the code you just modified. Ignore any warnings you see. Next go to settings and uncheck “Enable Optimizations” if it’s checked.

Run your own Private Ethereum Network

  • Geth is a popular fully fledged client and is able to do this out of the box. Setup is required, but it’s fairly straight forward.
  • TestRPC simulates an in-memory blockchain and provides a HTTP RPC server. It is extremely fast and easy to setup and tear down. However, as of today TestRPC does not implement every Ethereum API. These limitations are apparent, for example, when trying to use Mist to send personal transactions (see bug report here).

Server Side TestRPC Local Node

  1. npm install -g ethereumjs-testrpc   ethereumjs-testrpc has been renamed to ganache-cli (try npm install -g ganache-cli )
  2. To run testrpc, type > testrpc ; you should get a ‘Listening on localhost:8545’

Running Node Server Side Code

  • Navigate to the folder containing app.js –
  • To create a package.json, type npm init at the cmd prompt – and ENTER on all the defaults
  • If package.json already exists, type node app.js to run the node server

Client Side – Using Meteor

  1. Install Chocolatey – @”%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe” -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command “iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1′))” && SET “PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin”
  2. choco install meteor
  3. Once installed, you may not have the windows environment variable correct  – Create a new ENV variable called ‘meteor’  with the value  C:\Users\MYUSERNAME\AppData\Local\.meteor\packages\meteor-tool\1.6.1\mt-os.windows.x86_64\dev_bundle\bin
  4. meteor create MyDAPP  (this threw  a ‘missing’ release file error; just create a release file (no extension) and add METEOR@1.6.1 as the only line inside it.)
  5. meteor npm install (need this to get around any existing node installs/conflicts)
  6. Cannot read property ‘length’ error thrown by meteor on typing any command; This has to do with an existing node_modules folder. Rename (or delete) the c:/users/USERNAME/node_modules folder . That should fix this error).
  7. meteor add ethereum:web3
  8. meteor (should run meteor on localhost:3000)
  9. In the javascript console (F12) , if you see this error ‘DevTools failed to parse SourceMap: http://localhost:3000/packages/web3.js.map’, try emptying the browser cache and refreshing.
  10. frozeman:template-var  -meteor add frozeman:template-var

Client Side – Using Truffle

  • Use Truffle  WebPacks

  •  npm install -g truffle
  •  truffle unbox webpack
  •  truffle develop
  •  compile
     migrate
  • How do I use this with the EthereumJS TestRPC?

    It’s as easy as modifying the config file! Check out our documentation on adding network configurations. Depending on the port you’re using, you’ll also need to update lines 96 and 98 of app/javascripts/app.js.

  • I’m encountering this error: Error: Can’t resolve ‘../build/contracts/MetaCoin.json’

    This means you haven’t compiled or migrated your contracts yet. Run truffle develop, compile and migrate first.

Hosting

For

hosting this HTML and Javascript app we will initially use a traditional centralized web server. However, this is counter productive to the decentralized philosophy because you need to trust a central web server to serve the correct version of the app. So for this reason we will later explore decentralised hosting options such as IPFS.

Browser

The final thing to consider is a browser that can render your HTML5 user interface. Traditional “web 2.0” browsers won’t be enough in the case of decentralised apps for the following reasons:

  • They don’t have a wallet for digital currency (such as Ether) built-in. This is needed to make transactions super easy.
  • They would have to rely on a central/external RPC service to interact with the actual blockchain. We don’t like central things!

Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.

Initial Consultation

Anuj Varma – who has written posts on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.