I have been immersed in the blockchain web3 space for a few months. Well, this has been an intriguing ride thus far. I wish I had begun this earlier in my professional career. I adore this new journey, and every morning I look forward to learning something new and trying something different. Part of that journey led me to develop a dApp (decentralized Application) for a house rental platform.
How it worksThe application is a partial clone of the Airbnb website where users can list properties/rooms to rent out to travelers (i.e. a marketplace where people rent out their properties). As the owner of a property, you will be able to create, update, and delete a property, in the same way, customers will be able to view the listed property and if they like it, they can book and check in to the property when the time reach and can also request for a refund (perhaps, they don’t like it). If a user has successfully checked in to an apartment, they will be qualified to post a review of that property.
Technologies/toolsNext.js, Solidity, Redux, NodeJs, Hardhat, Ether.js
LESSONS LEARNTLesson 1: First, you need to design your application’s (dApp) front-end user interface.As a frontend engineer, I am more interested in the front-end/user interface (UI) of the dApp, The front-end is the part of the dApp that users interact with directly. By focusing on the front-end design first, I can prioritize creating a user-friendly and intuitive interface. This ensures that users will have a positive experience, which is essential for the adoption and success of the dApp.
Also, designing the front end forces me to think through the core functionalities of the dApp. This facilitates early in the development process clarification and consolidation of the functional requirements. A well-thought-out front-end design can guide the development of the back-end (in this case, the smart contract). It provides a clear understanding of what needs to be built on the smart contract to support the front-end’s functionality, leading to a more efficient and aligned development process.
With a well-designed front end, integrating with the smart contract becomes more straightforward. You already know what data (or parameter) is needed, and how it should be presented, making the smart contract integration smoother. In summary, designing the front end first sets a solid foundation for the rest of the dApp development, ensuring that the end product is user-friendly, functional, and aligned with user needs.
Lesson 2: The need to use dummy data to populate the front-end components/UI.As front-end engineers, dummy data allows us to see how our front-end UI will look and behave with real content. This visual feedback helps to ensure that our UI components are correctly displayed and function as expected. With dummy data, I can test how my design adapts to different screen sizes and devices. This ensures that the dApp is fully responsive and looks good across various platforms/screen sizes.
Meanwhile, dummy data gives me the privilege of simulating user interactions with the dApp, this ensures that the logic behind these interactions is sound before real data is introduced from the smart contract
Generally, using dummy data enables front-end developers to work independently of the back-end (smart contracts). While the back-end logic is still being developed, the front-end can be built and tested using placeholder data. This parallel development speeds up the overall process and when it’s time to integrate the smart contracts, having a front-end already populated with dummy data makes the process smoother. You can replace the dummy data with real data from the blockchain, ensuring that the front-end components are ready to handle the actual data structure and types. Examples of dummy data providers include DummyJson, JsonPlaceholder and you can get more from here
In summary, dummy data gives me the privilege to thoroughly test and refine the front end before integrating the smart contracts, ensuring a smooth and efficient development process with fewer surprises and issues during integration.
Lesson 3: The importance of using Redux (Redux toolkit) for state management and its importance on the UX.Redux provides a single, centralized store for the entire application’s state. This is crucial in a dApp, where the state can be influenced by both on-chain data (from smart contracts) and off-chain data (from the UI or other external sources). Having a single source of truth ensures that all parts of the application are consistent and up-to-date.
Aside from this, Redux allows for optimized UI updates by controlling how and when components re-render based on state changes. It also enforces a predictable state management pattern by using pure functions (reducers) to update the state. In a dApp, where data integrity is critical, this predictability ensures that state changes are transparent, traceable, and can be easily debugged. This is important in a dApp to ensure that the UI remains responsive, even when dealing with large amounts of data or frequent updates.
In summary, Redux (most especially using the redux toolkit) provides a robust and scalable solution for managing the state in a dApp. It gives me the privilege of having a smooth UI update as soon as the state changes or when a new apartment/review is created/updated. It’s such a nice experience for the user.
Lesson 4: The use of Hardhat to compile, debug, deploy, and test Ethereum Smart contractHardhat is a development environment for Ethereum smart contracts that facilitates testing, debugging, deploying, and compilation. It has local testing, Solidity compilation, and easy contract deployment. Hardhat allows developers to run a local Ethereum network for testing and development. This network simulates the Ethereum blockchain, enabling developers to deploy, test, and debug smart contracts in an isolated environment.
Hardhat allows for detailed network configuration, letting developers easily switch between different Ethereum networks (local, testnet, mainnet) and manage multiple network environments in a single project. Hardhat can analyze and report on the gas usage of smart contract functions, helping developers optimize their contracts for lower gas costs. This is crucial for making dApps more cost-effective for users, especially in environments where gas prices can fluctuate significantly.
Hardhat supports thorough testing of smart contracts using tools like Mocha and Chai. Developers can write unit tests to ensure that individual functions work as expected and integration tests to verify that smart contracts interact correctly with each other
Here is a quick guide to hardhat project structure after setup
Hardhat Project Structure
When you initialize a Hardhat project in your local environment, the structure includes the following important files/folders:
Please note: The hardhat.config.js file is the most important in your project!
In summary, Hardhat is crucial in dApp development because it provides a powerful, flexible, and user-friendly environment for building, testing, and deploying smart contracts. Its features are designed to streamline the development process, reduce errors, and ensure that the resulting dApp is secure, efficient, and ready for deployment on the Ethereum blockchain.
Lesson 5: The importance of testing your smart contract before front-end integration. [VERY IMPORTANT]Testing a smart contract is the process of making sure its code functions as intended. Testing helps determine whether a certain smart contract meets the necessary standards for security, usability, and reliability.
Therefore:
TESTING SMART CONTRACTS IS A MUST !!!So let’s talk about the dangers of not testing smart contracts.
In summary, testing your smart contract before front-end integration is crucial for ensuring its correctness, security, and functionality. It saves time and costs in the long run, helps prevent serious issues, and provides a solid foundation for the rest of your dApp development.
The five points I listed above summarize the knowledge I gained while working on this project.
The source code for this project can be found here.
Disclaimer: I would like to say that, this is a tutorial done by Darlington Gospel and the full video can be found on his YouTube account, while the source code can be found here as well.
Useful ResourcesWhat I learned while developing a decentralized House Rental Platform with Next.js, was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story.