Skip to main content

DeFi Course Lesson 7 - Frontend Deployment

Updated on
Oct 23, 2026

11 min read

Overview​

Welcome to the last lesson of our DeFi course dedicated to guiding you through the intricate process of building a Decentralized Exchange (DEX) platform. This lesson we'll guide you through the crucial steps of deploying your DEX frontend to a production environment.

We will also use Quicknode Webhooks to send liquidity events to a Telegram channel.

By completing this lesson, you will have a hosted Sepolia DEX and optional liquidity notifications.

Deploying the Frontend to Production​

By deploying our frontend and making it public on the web, users will be able to interact with our DEX worldwide.

Vercel is a cloud platform specializing in facilitating modern web application deployment and hosting. It is particularly well-suited for projects built using popular frontend frameworks like React, Vue.js, and Angular, as well as static site generators like Next.js. Vercel simplifies taking your web application code and making it accessible online, providing a seamless and efficient deployment experience. You can deploy from a Git repository, which means whenever you push changes to your repository, Vercel can automatically trigger new deployments, making updates to your live site effortless.

With that being said, we will use GitHub and Vercel to deploy the DEX frontend to the web.

Firstly, we upload the code to GitHub.

1. Log in to your GitHub account

2. Create a new repository by selecting a repository name. If you don't want anyone to see this repository, select Private instead of Public.

New Repository

3. Click Create Repository, and then once its created, copy the repository URL (such as https://github.com/YOUR_NAME/REPOSITORY_NAME.git).

4. Within your terminal window, navigate into your frontend's main directory (e.g. defi-dex-frontend) and run these commands below

Do not forget to change URL_OF_THE_REPOSITORY with your repository's URL.

caution

Before proceeding with any commits or pushes, take a moment to double-check your .gitignore file. This file is critical for excluding specific files and directories from Git tracking and typically located at the root directory of your Git repository. Accidentally, including sensitive information, large files, or build outputs could lead to a cluttered repository and security risks.

Double check your .gitignore file so that it matches the format below:

.env

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin URL_OF_THE_REPOSITORY
git push -u origin main

Let's explain these commands in detail. They are the fundamental steps for initializing and pushing code to a remote Git repository.


  • git init initializes a new Git repository in your project folder.
  • git add . stages all the changes in the repository.
  • git commit -m "first commit" creates a commit with a descriptive message.
  • git branch -M main renames the default branch to "main."
  • git remote add origin URL_OF_THE_REPOSITORY associates the remote repository's URL with the local repository.
  • git push -u origin main pushes the committed changes to the remote repository's "main" branch, establishing a connection and making your code available on the remote repository.

Authenticate Git with GitHub CLI (gh auth login) or use an SSH remote. If Vercel cannot find a private repository, grant its GitHub integration access to that repository.

4. Log in to Vercel with your GitHub account.

Login Page of Vercel

5. On your dashboard, Click Add New and then select Project.

6. Click Import next to the relevant Git repository.

7. Set the Framework Preset to Vite and add VITE_VERCEL_QUICKNODE_ENDPOINT from your local .env file. Commit package-lock.json so Vercel installs the same dependencies.

Vite embeds VITE_ values in the public browser bundle. Use a dedicated browser endpoint with the appropriate origin and usage restrictions; never put wallet private keys, Telegram tokens or Quicknode account API keys in these variables.


note

Make sure that Framework Preset is selected as Vite.

Project Deployment Settings

8. Click Deploy. It will take a few minutes for Vercel to deploy the application publicly. Once published, it'll display a domain link for your dApp.

9. Click the domain link to navigate to your dApp.

Congratulations on deploying the dApp to the web! 🎉

Testing the DEX using the Frontend​

With both smart contracts and frontend deployed to the public, it's time to demonstrate the functionality of the DEX platform.

1. Connect Wallet


  • Open the deployed frontend in your web browser.
  • Click Connect wallet in the header.
  • Follow the wallet's prompts to connect your wallet to the dApp.

You may temporarily change the wallet's network to a network other than Sepolia. The header then shows a Wrong network: switch button, and the main button changes to Switch to Sepolia.

Network Warning

2. Check Account Balance

Once connected, the header shows your wallet address. The Swap tab shows your testnet ETH and token balances.

Ensure that you have a sufficient balance of testnet ETH for transactions. If you don't have enough balance, feel free to use Quicknode's faucet.

3. Swap Tokens

The Swap tab opens first.


  • Click the arrow button between the fields to select the swap direction (ETH to token, or token to ETH).
  • Enter the amount to swap.
  • Click Swap. For a token to ETH swap, click Approve and swap.
  • Confirm the transaction in your connected wallet. A toast shows the status until the transaction is confirmed on the testnet.
  • Check that your balances update after the swap.

You may enter an amount higher than your balance. The main button then shows Insufficient ETH or the token equivalent.

Swap

4. Provide Liquidity


  • Open the Liquidity tab.
  • Select Add.
  • Enter the ETH amount. If the pool is empty, enter the token amount too.
  • Click Approve and add liquidity.
  • Confirm both transactions in your wallet. Wait for the transactions to complete.
  • Check that the pool values and your LP tokens update.

5. Remove Liquidity


  • In the Liquidity tab, select Remove.
  • Enter the amount of LP tokens to remove, or select a percentage.
  • Click Remove liquidity.
  • Confirm the transaction in your wallet. Wait for the transaction to complete.
  • Check that your balances update.

Liquidity Tracking with Webhooks​

In this part, we will show you how to create a Telegram bot that will send a notification to the Telegram channel whenever a user adds or removes liquidity with Webhooks.

This part is optional and is not required to complete the course. However, we highly encourage you to follow through with this part.

To do this, you will need to:


  • Create a Telegram bot
  • Set up a Quicknode Webhook
  • Write some code to send notifications to the Telegram bot

Creating a Telegram Bot​

In this part, we will create a bot and an announcement channel.


Telegram BotFather


  • Click Start.
  • Write /newbot.
  • Choose a name for the bot (i.e., QN DeFi Bot).
  • Choose a username for the bot. It should be ended with bot(i.e., qn_defi_bot).
  • It gives the link of your TG bot (e.g., https://t.me/qn_defi_bot) and a token to access the HTTP API. Save it securely, it can be used by anyone to control your bot.

Telegram Bot Token

  • Click (≡), and click New Channel.

  • Select a Channel Name (i.e., QN DeFi Bot)

    • (optional) Select the privacy setting. If you select Public channel, set a link and save. You can skip this part.
    • Click Skip for adding members.
  • Then, we need to find out the id of the channel.

    • Click the name of the channel, click settings (⋮), Manage Channel, Administrator, Add Administrator respectively.

Telegram Add Administrator


  • Search for myidbot and save the settings.
  • After adding the bot, write /getgroupid in the chat. The bot sends the group id. Save it to use in the following steps.
  • (optional) You can remove the myidbot from administrator.
  • Follow the same steps as you did to add a bot to the channel, click Add Administrator, search for your bot username (i.e., qn_defi_bot), select it, and save.

Setting Up the Backend​

Now, it's time to set up the backend.

Open your terminal in any directory you want and run following commands to create a new project.

mkdir telegram-bot
cd telegram-bot
npm init --yes
npm install --save-exact dotenv@18.0.8 express@5.3.0
npm pkg set scripts.dev="node --watch index.js" scripts.start="node index.js"
touch index.js .env

This code will install the following packages:


  • dotenv: This package is used to load environment variables from a file.
  • express: This package is a web framework used to create HTTP servers. Telegram messages use Node.js's built-in fetch. The dev script restarts the server when index.js changes.

Then, open your favorite code editor and modify the index.js file corresponding the code below.

const { createHmac, timingSafeEqual } = require("node:crypto");
require("dotenv").config();
const express = require("express");

const { TOKEN, CHAT_ID, WEBHOOK_SECURITY_TOKEN, EXCHANGE_ADDRESS, PORT = 5001 } = process.env;
if (!TOKEN || !CHAT_ID || !WEBHOOK_SECURITY_TOKEN || !/^0x[0-9a-f]{40}$/i.test(EXCHANGE_ADDRESS || "")) {
throw new Error("Set TOKEN, CHAT_ID, WEBHOOK_SECURITY_TOKEN and EXCHANGE_ADDRESS in .env");
}

const addTopic = "0xac1d76749e5447b7b16f5ab61447e1bd502f3bb4807af3b28e620d1700a6ee45";
const removeTopic = "0x96cd817c6329656790ef8fba7675405193677d39619571282f5e21f3a98cd059";
const delivered = new Set();
const inFlight = new Set();
const app = express();
app.use(express.raw({ type: "application/json", limit: "1mb" }));

app.post("/webhook", async (req, res) => {
const nonce = req.get("x-qn-nonce");
const timestamp = req.get("x-qn-timestamp");
const signature = req.get("x-qn-signature");
if (!Buffer.isBuffer(req.body) || !nonce || !timestamp || !/^[0-9a-f]{64}$/i.test(signature || "")) {
return res.sendStatus(401);
}
const expected = createHmac("sha256", WEBHOOK_SECURITY_TOKEN)
.update(nonce + timestamp + req.body.toString("utf8")).digest();
if (!timingSafeEqual(expected, Buffer.from(signature, "hex"))) return res.sendStatus(401);

let payload;
try { payload = JSON.parse(req.body.toString("utf8")); }
catch { return res.sendStatus(400); }
if (!Array.isArray(payload.matchingReceipts) ||
payload.matchingReceipts.some(receipt => !Array.isArray(receipt?.logs))) {
return res.sendStatus(400);
}

try {
for (const receipt of payload.matchingReceipts) {
for (const log of receipt.logs) {
if (log.address?.toLowerCase() !== EXCHANGE_ADDRESS.toLowerCase() || log.removed) continue;
const verb = log.topics?.[0] === addTopic ? "added" :
log.topics?.[0] === removeTopic ? "removed" : null;
if (!verb) continue;
const hash = log.transactionHash || receipt.transactionHash;
if (!/^0x[0-9a-f]{64}$/i.test(hash || "") || log.logIndex == null ||
!/^0x[0-9a-f]{64}$/i.test(log.topics?.[1] || "")) return res.sendStatus(400);
const id = `${hash}:${log.logIndex}`;
if (delivered.has(id)) continue;
if (inFlight.has(id)) return res.sendStatus(503);
inFlight.add(id);
try {
const provider = "0x" + log.topics[1].slice(-40);
const response = await fetch(`https://api.telegram.org/bot${TOKEN}/sendMessage`, {
method: "POST", headers: { "Content-Type": "application/json" },
signal: AbortSignal.timeout(10000),
body: JSON.stringify({ chat_id: CHAT_ID,
text: `${provider.slice(0, 6)}...${provider.slice(-4)} ${verb} liquidity.\nhttps://sepolia.etherscan.io/tx/${hash}` }),
});
const result = await response.json();
if (!response.ok || !result.ok) throw new Error("Telegram rejected the message");
delivered.add(id);
} finally {
inFlight.delete(id);
}
}
}
res.sendStatus(200);
} catch {
res.status(502).send("Telegram delivery failed; retry this payload.");
}
});

app.listen(PORT, () => console.log(`Listening on port ${PORT}`));

Then, modify the .env file like the one below.

TOKEN=<TELEGRAM_BOT_TOKEN>
PORT=5001
CHAT_ID=<TELEGRAM_CHAT_ID>
WEBHOOK_SECURITY_TOKEN=<YOUR_WEBHOOK_SECURITY_TOKEN>
EXCHANGE_ADDRESS=<YOUR_EXCHANGE_ADDRESS>

caution
  • Replace <TELEGRAM_BOT_TOKEN> with the bot token you get from BotFather in the Creating a Telegram Bot section.
  • Replace <TELEGRAM_CHAT_ID> with the channel ID you got from myidbot in the Creating a Telegram Bot section.
  • Set EXCHANGE_ADDRESS to the exchange used by your frontend, not the Factory or token address.
  • Choose WEBHOOK_SECURITY_TOKEN with openssl rand -hex 32 and use the same value in the webhook destination below. Keep .env out of Git.

Then, open a new Terminal window and run ngrok on a port. Make sure that the value of PORT in the .env file is exactly the same as the port number used with the ngrok command.

ngrok http 5001

If you don't have ngrok installed, check this page and install it globally on your system.

Copy the URL which you get after running the above command. NGROK

Setting Up Webhooks​

Use the Contract Events template on Ethereum Sepolia. Filter by the Exchange address and the two liquidity event topics. The topic is the hash of the event name and parameter types; the indexed provider address is in topics[1].

You can obtain the topics with Foundry:

cast keccak "LiquidityAdded(address,uint256,uint256)"
cast keccak "LiquidityRemoved(address,uint256,uint256)"

Create a Quicknode API key with Webhooks access. In a terminal, set QUICKNODE_API_KEY, EXCHANGE_ADDRESS, WEBHOOK_URL (your ngrok HTTPS URL followed by /webhook) and WEBHOOK_SECURITY_TOKEN. These are server-side values; do not add them to the Vite environment.

Create the webhook with the Webhooks REST API. Replace the placeholders in this request:

curl --fail-with-body https://api.quicknode.com/webhooks/rest/v1/webhooks/template/evmContractEvents \
--header "x-api-key: $QUICKNODE_API_KEY" \
--header "Content-Type: application/json" \
--data @- <<EOF
{
"name": "DeFi liquidity",
"network": "ethereum-sepolia",
"destination_attributes": {
"url": "$WEBHOOK_URL",
"security_token": "$WEBHOOK_SECURITY_TOKEN",
"compression": "none"
},
"templateArgs": {
"contracts": ["$EXCHANGE_ADDRESS"],
"eventHashes": [
"0xac1d76749e5447b7b16f5ab61447e1bd502f3bb4807af3b28e620d1700a6ee45",
"0x96cd817c6329656790ef8fba7675405193677d39619571282f5e21f3a98cd059"
]
}
}
EOF

Keep the returned webhook ID. Its status should be active. The receiver expects the template's matchingReceipts array and verifies the HMAC signature before reading events. See validating incoming messages for the signature headers and calculation.

Start the receiver in the telegram-bot directory and leave ngrok running:

npm run dev

Add and remove liquidity through the frontend. Each matching log should produce a message in your channel with a Sepolia transaction link. The server returns a non-success response if Telegram rejects a message, allowing the webhook to retry. Successfully sent events are skipped on a retry within the same process.

This local example keeps delivery IDs in memory. Restarting it clears those IDs, and a timeout after Telegram accepts a message can result in a duplicate. For a long-running service, persist delivery state and define a retention policy. Stop the webhook when you finish the exercise so it no longer targets your temporary ngrok URL.

Quiz​

Let's finish with a quiz to reinforce what you've learned. This quiz will cover the topics discussed during the lesson.


Sign in to track your course progress and interact with quizzes
Create a free Quicknode account to save your progress, complete knowledge checks, and mark lessons complete.
Create AccountSign In

Conclusion​

You have deployed the frontend and connected it to the contracts on Sepolia. The optional webhook receiver forwards liquidity events to Telegram. Keep this educational implementation on testnet; using real funds requires a separate security review and additional safeguards.