Set up your first Decentralised Application

This post will guide you through the initial steps in building your first decentralised application (Dapp) using Smart Contracts. I chose the Ethereum network and the Solidity programming language as they are the most widely used and they already have a few great tools that support the development process.

Nonetheless, the most basic option for building Smart Contracts would be using the Remix IDE which is limited in terms of testing. This post will not be about Remix.

Content:

  1. How a decentralised application works
  2. Tools that will make your life easier
  3. Starting up

1. Basic architecture of a Dapp

Firstly, to understand the tools to install, we need to know how a Dapp usually works.

It usually has two main components:

  • Smart Contracts (essentially the backend)
  • User Interface (usually a website)
Dapp architecture

The Smart Contracts represent the “brain” of a decentralised application. Instead of having a script run on a server, we deploy the smart contracts on the blockchain and allow the web interface to talk to the blockchain. Additionally, The web interface references the smart contracts through their Ethereum address and calls their functions according to the user’s actions.

2. Tools

Secondly, let’s get into the tools you need.

Node.js

The 1st thing to install is Node.js. This will allow you to smoothly build your web interface with JavaScript and interact with the blockchain.

You can check if you have it installed by writing this command on your terminal:

node -v

If you don’t have it, you can simply download it from the Node.js website.

Truffle Suite

Truffle is a very nice and flexible development environment for Smart Contracts. You can easily write and test your code and later deploy it on either a test-network or the main-network.

Because you already have Node.js installed, you can install Truffle with the following command:

npm install -g truffle

It will take a few minutes to install it’s done when you see something like this:

+ truffle@5.3.11

Ganache

To test your smart contracts, it’s very useful to have a local blockchain. However, you can certainly deploy on one of the test-nets like Ropsten or Kovan, but it is easier at the beginning to test locally.

Ganache is part of the Truffle suite and it provides you with a local “network” showing accounts and transaction on a nicely designed console.

Ganache screenshot

What can Ganache do?

  • Transactions are validated immediately (can be both an advantage or a disadvantage)
  • It gives you a few addresses with their private keys (default is 10) – you can use those for impersonating your users
  • Each address owns 100 ETH
  • It displays each transaction
  • Customisability in terms of gas price, limits

You can download Ganache from this link https://www.trufflesuite.com/ganache is you are working on macOS. For Windows and Linux follow this link https://git@github.com/trufflesuite/ganache.

3. Start the project

Now that all the tools are installed, we can create the project.

Lastly, create a new folder and move to it from the terminal. Initialise the project with Truffle by writting:

truffle init

This will create all the project files you need and you should see something like this:

Folder screenshot

The contracts folder is where you are going to write your smart contracts, the migrations files will handle deployments on the blockchain and the test files are, I think, self-explanatory.


The next blog posts will cover how to navigate the development environment (read Working with Truffle and Ganache) and how to link it to a web interface. Stay tuned!

I hope this was helpful. Any suggestions are more than welcomed in the comments!

2 Comments Add yours

Leave a Reply