Dapp Project Setup
In the previous post I went through the steps to configure my local development environment, so now would be a good time to start creating the project skeleton.
Creating a Next.js project
As a memory refresher:
Next.js is an open-source web development framework built on top of Node.js, enabling React-based web application functionalities such as server-side rendering and generating static websites.
React is an open-source front-end JavaScript library that is typically used to build web applications and their user interfaces rendered in the client’s browser.
On Terminal, I first changed into the directory where I wanted the new project to be housed. Feel free to replace ~/Development
with your preferred directory.
Then I ran the following command to create an app named final-static
. All of the project files would be generated inside the final-static
folder.
If you didn’t already have it, you would be asked to install the create-next-app
package first.
When the command completed, I changed into the newly created project directory.
The next step would be to install the dependencies using a package manager like npm
, yarn
, or pnpm
.
I tried both npm
and yarn
, and it appeared that yarn
worked better for my particular setup. Feel free to pick whichever works better for you:
You might also need to follow the prompts to troubleshoot any warnings or errors.
Setting up Tailwind CSS
When it comes to customizing web-based user interfaces, I like the full control you get with Cascading Style Sheets (CSS), but honestly dread having to put in the sometimes counter-intuitive work just to get things to look good enough (let alone perfect).
If you are in the same boat as far as CSS is concerned, then you might also find Tailwind CSS helpful.
Tailwind CSS is a utility-first CSS framework for rapidly building custom user interfaces. It is a highly customizable, low-level CSS framework that gives you the building blocks you need to add styling and create good-looking designs the easy way.
Here’s the command I used to install the Tailwind dependencies:
Then, in order to create the configuration files needed for Tailwind to work with Next.js (namely, tailwind.config.js
and postcss.config.js
), I ran:
With said configuration files generated, I was able to make some preliminary updates.
To add custom template content paths in tailwind.config.js
:
The next thing I did was replacing the code in styles/globals.css
with the following:
Configuring Hardhat
One distinctive characteristic of decentralized applications (dapps) is the use of blockchain technology with smart contract functionality.
The blockchain platform of choice here is Ethereum. To support this, I went ahead and set up Hardhat.
Hardhat is a Solidity development environment to compile, deploy, test, and debug Ethereum software.
Solidity is an object-oriented programming language for implementing smart contracts on various blockchain platforms — most notably — Ethereum.
I started by initializing a new Hardhat development environment from the root of the /final-static
project:
At the prompt, I selected:
When asked about the project root, I went with the default. Your directories would be different.
After saying “yes” to adding a .gitignore
, I got a possibly git-related error:
And therefore I deleted README.md
and ran the initialization again.
When the initialization completed, I quickly checked to make sure the following files and folders were successfully generated in the project root directory:
hardhat.config.js
The entirety of your Hardhat setup (i.e. your config, plugins, and custom tasks) is contained in this file./scripts/
A folder containing a script named sample-script.js that will deploy your smart contract when executed./test/
A folder containing an example testing script./contracts/
A folder holding an example Solidity smart contract.
Next, per Nader’s tutorial, I updated the configuration at hardhat.config.js
by replacing the auto-generated code with the following:
The above configured the local Hardhat development environment as well as the Mumbai testnet (commented out for now until I got ready for the test).
They are both Polygon (formerly Matic) networks.
Polygon makes Web3 more accessible. It is a decentralized Ethereum scaling platform that enables developers to build scalable user-friendly dapps with low transaction fees.
Let’s break things up here for now. In the next post, I will proceed to set up smart contracts.