Deploy a dApp
Deploy a decentralized application on KiiChain.
Introduction
In this tutorial, you will learn how to create a simple decentralized application (dApp) built on KiiChain. We will use tools such as React, TypeScript, and Ethers.js to build a basic wallet management system.
Project setup
Tools
We will be using the following tools:
npx
for managing Node.js packages and running commands.ethers
for interacting with the Ethereum blockchain and other compatible chains like KiiChain.React
for building the user interface.TypeScript
for adding static types to JavaScript.
Create project
First, navigate to your working directory, open a terminal, and run the following commands to create a new React project with TypeScript:
After the project is set up, open the code in your preferred editor. If you are using Visual Studio Code, you can do this with:
You should now see the following project structure:
Install dependencies
Next, you need to install the ethers
library. Run the following command in the terminal within your project directory:
The version used in this tutorial is Ethers.js v6.
Coding the dApp
Create the Repository
Create a new file at src/repository/kiichain.repository.ts
. The directory needs to be created.
This repository file contains functions for basic operations like creating a wallet, connecting to a wallet using a seed phrase, and getting the balance of a wallet.
What is a Signer and a Provider?
In decentralized application (dApp) development, especially when interacting with blockchains like KiiChain, it's essential to understand the concepts of Provider and Signer. These components play crucial roles in communicating with and managing transactions on the blockchain.
Provider
A Provider is a component that allows your dApp to connect to and interact with the blockchain. It provides methods to read data from the blockchain, such as transaction statuses, account balances, and other network details. The provider does not have access to private keys and therefore cannot sign transactions.
Signer
A Signer is a component that represents an entity capable of making transactions on the blockchain, meaning it can sign them. A signer has access to the private keys necessary to authorize and send transactions, allowing you to modify the blockchain state, such as transferring tokens or interacting with smart contracts.
Create the Wallet Manager Component
Create a new file at src/components/WalletManager.tsx
. The directory needs to be created
This component implements the functions from the repository and displays the relevant information, such as the wallet address and balance.
Run the dApp
To check if everything is working correctly, you need to run the project. Open your terminal in the project directory and execute the following command:
If everything is set up properly, your application should start, and the following screen will appear:
Testing the Wallet Functionality
Create a New Wallet: Click the "Create New Wallet" button. A new wallet will be generated, and the address along with the seed phrase will be displayed in the console.
Access the Developer Console:
Right-click anywhere on the page and select "Inspect" to open the Developer Tools.
Navigate to the "Console" tab to see the output.
Connect to the Wallet: Copy the seed phrase from the console, paste it into the input field under "Enter your seed phrase," and click "Connect Wallet via Seed Phrase."
View Wallet Balance: If connected successfully, the wallet's balance should be displayed on the screen.
By following these steps, you can confirm that the dApp is functioning as expected.
Deploying the dApp Using Firebase
To deploy your decentralized application (dApp) using Firebase Hosting, follow these steps:
Step 1: Set Up a Firebase Project
Create a Project in Firebase:
Visit the Firebase Console.
Click on "Create a project".
Name your project and disable Google Analytics (optional for this tutorial).
Click "Continue" once the project is ready.
Access Firebase Hosting:
In the left menu, go to Build → Hosting.
Click "Get started" to begin setting up Firebase Hosting.
Step 2: Initialize Firebase Hosting
Install Firebase CLI:
Open your terminal and install Firebase CLI globally
Login and Initialize Firebase:
Inside your project directory, run
During initialization, select the following options:
Features: Hosting: Configure files for Firebase Hosting
Project Setup: Use an existing project
Public Directory: ‘build’
Single-page App: No
Automatic Builds/Deploys: No
Step 3: Build and Deploy Your dApp
Build the project:
Run the following command to generate the production-ready files
Deploy to Firebase
Deploy your built project to Firebase Hosting
Once the deployment is complete, the URL of your live dApp will be shown in the terminal.
Last updated