Creating decentralized applications (dApps) involves more than just crafting smart contracts; it’s about establishing a fully integrated, user-friendly experience. Smart contracts form the blockchain backbone, executing the core tasks, but a robust frontend is essential for user interaction, making complex smart contracts accessible and manageable.
In our previous article, we went through the process of cloning and deploying UniswapV2 smart contracts, in this article, you will learn how to clone the UniswapV2 frontend and connect it with the deployed smart contract on any EVM blockchain.
Before you begin with this tutorial, make sure you've got the following ready:
A clear understanding of how UniswapV2 architecture functions (you can refer back to the first tutorial here).
You've already cloned and deployed the UniswapV2 Smart Contracts.
A good understanding of JavaScript.
Knowledge of building frontend applications using React.js.
Node.js, NPM, and Yarn are installed on your computer.
UniswapV2 frontend is built with React.js and Typescript, and it uses the UniswapV2 SDK as its connection point with the smart contract. Connecting the frontend and making it work on any EVM-based blockchain requires modifying the SDK to make use of the same chainID where the smart contracts were deployed. This article will be focused on pointing out all modification points necessary for customizing the UniswapV2 frontend and making it work on any EVM chain where our smart contracts were deployed and not go through the entire frontend codebase. Buckle up as we embark on this ride!
This tutorial will be divided into two sections:
Cloning and setting up the UniswapV2 SDK.
Cloning and setting up the UniswapV2 Interface.
1
1.1
2
yarn
to install all dependencies.3
ChainId
enum, add the chain ID of the EVM chain where your contracts were deployed if it doesn’t exist already. We will be adding the Sepolia testnet chain ID, which is 11155111
.FACTORY_ADDRESS
to the address of your own V2 factory contract you deployed.INIT_CODE_HASH
to the one in your UniswapV2Library found in the Router.sol contract. Refer back to the previous article here.4
WETH
constant and add your own ChainId
and the address of the WETH smart contract you deployed earlier.5
public readonly ETHER
and change the symbol(ETH)
and name(Ether)
to that of your preferred chain. The decimal can also be changed if the decimal of the native token of the chain where your contracts are deployed is not 18.Ether(ETH)
.6
yarn build
.After cloning and setting up the V2 SDK, we can now proceed with cloning the UniswapV2 frontend interface.
1
1.1
2
@uniswap/sdk
.“file:../v2-sdk”
.yarn
and wait for all dependencies to be installed.3
ROUTER_ADDRESS
to the address of the Router02.sol contract we deployed in the previous tutorial.ChainId
of the new chain where our smart contracts were deployed, in our case Sepolia.4
supportedChainIds
array and add the chain ID of our own chain where we deployed our smart contracts if it doesn’t exist in the array; in our case, it’s Sepolia and the chain ID is 11155111
.appName
if you wish to customize that.5
MULTICALL_NETWORKS
constant, add the network on which our smart contracts were deployed if it doesn’t exist already. In this case, add Sepolia.6
NETWORK_LABELS
constant, add Sepolia
to the list of values on the object.7
V1_FACTORY_ADDRESSES
, add ChainID.SEPOLIA
to the list and set the value to the address of the UniswapV2 Factory contract we had deployed earlier in the previous article.8
EMPTY_LIST
constant, add ChainId.SEPOLIA
to the list of values.9
ETHERSCAN_PREFIXES
constant, add 11155111: ‘sepolia.’
to the list of key-value pairs.10
yarn start
for your frontend to compile and open in a browser.11
This is a bonus section to add some more UI modifications and changes on the UniswapV2 frontend, making it look more like your own thing.
1
2
ETH
symbol to any symbol of your choice, for example, MATIC, if your smart contracts were deployed on the Polygon chain.3
VersionSwitch
import and comment out where it was used.3.1
3.2
There are no limits to how you can customize and modify the UniswapV2 frontend interface to your desired design. All you need is to study the codebase closely and locate the files you intend to modify. In this tutorial, we have successfully cloned and modified the UniswapV2 Frontend Interface and UniswapV2 SDK to connect with our deployed smart contracts, which we covered in our previous tutorial here. This can be done for any EVM-compatible blockchain if the above steps are properly followed. You can now call yourself a UniswapV2 master. Happy building!