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.
- How a decentralised application works
- Tools that will make your life easier
- 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)
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.
Secondly, let’s get into the tools you need.
You can check if you have it installed by writing this command on your terminal:
If you don’t have it, you can simply download it from the Node.js website.
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:
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.
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
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:
This will create all the project files you need and you should see something like this:
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!