logo

How to Create Your Own DEX

With a decentralized platform (DEX), you can launch new tokens, allowing users to interact with numerous DEXs and dApps on various networks. But creating a DEX from scratch can be cumbersome and resource-intensive. Luckily, it is possible to avoid the complex backend development process by using a reliable decentralized exchange Web3 development platform like OpenDAX.

Jul 13 2022 | Article

How to Create Your Own DEX

With a decentralized platform (DEX), you can launch new tokens, allowing users to interact with numerous DEXs and dApps on various networks. It is also safe to say that a DEX is a great way to acquire and provide tokens. The growing popularity of DEXs has left many crypto investors and blockchain developers looking for ideas on how to create their own DEXs. However, before you learn how to create your own DEX, you need to understand what a decentralized exchange is and the tools that can be used in the development process.

#What Is a Decentralized Exchange?

A decentralized exchange is a platform designed to facilitate currency transfers between two accounts with conservative financial systems. It is based on a decentralized system, meaning its backend exists on a blockchain. One of the main benefits of using a DEX is the opportunity to do away with intermediaries–with a DEX, the trade exchange of currency or tokens happens directly between two accounts.

#How to Create a DEX

Note that creating a DEX from scratch can be cumbersome and resource-intensive because it involves complex backend development. Luckily, it is possible to avoid the complex backend development process by using a reliable decentralized exchange Web3 development platform like OpenDAX. Created by Openware, a leading crypto software publisher, OpenDAX is an open-source platform for crypto exchanges with over 150 installations worldwide.

This hybrid open-source program comprises both public and private libraries that enable it to develop fully-featured exchange platforms, facilitating the exchange of digital assets, security tokens, and cryptocurrencies. It is also integrated with Yellow Network, a connection network utilizing state channels to merge all blockchains, allowing users to reach all tokens locked on inaccessible networks without bridging them. With this Web3 development platform, you can create your own DEX in the following simple steps.

Generating a New App

You can either generate a new NextJS or ReactJS app–whichever option you choose, start by running the initial script. The CLI will ask you to provide the name of your project, so type that in and hit Enter to complete the basic setup. To check if the setup has gone smoothly, run “npm run dev” (yarn dev) in the command prompt and open the port on a browser.  

Installing OpenDAX WEB SDK

To install OpenDAX WEB SDK, key in the following: npm install @openware/opendax-web-sdk@latest.

Adding CoreProvider

Open the project folder in a code editor like VSCode. Then open pages/_app.tsx using the following procedure:

├── pages

│ ├── _app.tsx

│ ├── api

│ │ └── hello.ts

│ └── index.tsx

The code in _app.tsx. looks like this:

  1. import '../styles/globals.css'
  2. import type { AppProps } from 'next/app'
  3. import { CoreProvider } from '@openware/opendax-web-sdk'
  4. function MyApp({ Component, pageProps }: AppProps) {
  5. return (
  6. <CoreProvider>
  7. <Component {...pageProps} />
  8. </CoreProvider>
  9. );
  10. }
  11. export default MyApp

All your providers are set. Now, it is time to create the layout and navigation bars.

Adding Layout

There are two options that you can use to create a layout. For instance, you can use the OpenDAX WEB SDK layout, which comes with a Sidebar (navigation) or create one. Then you need to import styles. So, update the code in _app.tsx. using this code:

  1. import '../styles/globals.css'
  2. import '@openware/opendax-web-sdk/index.css'
  3. import type { AppProps } from 'next/app'
  4. import { CoreProvider } from '@openware/opendax-web-sdk'
  5. function MyApp({ Component, pageProps }: AppProps) {
  6. return (
  7. <CoreProvider>
  8. <Component {...pageProps} />
  9. </CoreProvider>
  10. );
  11. }
  12. export default MyApp

To import the layout, you have to send navigation props. Write the following code in _app.tsx.:

  1. import "../styles/globals.css";
  2. import "@openware/opendax-web-sdk/index.css";
  3. import React, { useState } from "react";
  4. import type { AppProps } from "next/app";
  5. import {
  6. CoreProvider,
  7. Layout,
  8. SidebarProps,
  9. AccountButtonWidget,
  10. } from "@openware/opendax-web-sdk";
  11. function MyApp({ Component, pageProps }: AppProps) {
  12. const [collapseLeftBar, setCollapseLeftBar] = useState<boolean>(true); 
  13. const sidebarProps: SidebarProps = {
  14. classNames: 'bg-navbar-background-color sm:border-r border-divider-color-20',
  15. buttonsList: [
  16. {
  17. name: "Metamask",
  18. component: <AccountButtonWidget collapsed={collapseLeftBar} />,
  19. label: "",
  20. },
  21. ],
  22. onSidebarCollapse: (collapseLeftBar: boolean) => {
  23. setCollapseLeftBar(collapseLeftBar);
  24. },
  25. };
  26. return (
  27. <CoreProvider>
  28. <Layout sidebarProps={sidebarProps}>
  29. <Component {...pageProps} />
  30. </Layout>
  31. </CoreProvider>
  32. );
  33. export default MyApp;

Building Your Brokerage Trading Page

At this point, you only need to edit the pages/index.tsx. You will find all the features and tools needed to make your brokerage trading page as user-friendly and attractive as possible.

Adding Crypto Icons

For this task, update your next.config.js. Write the following code:

  1. module.exports = {
  2. images: {
  3. domains: ['cdn.jsdelivr.net']
  4. },
  5. };

Adding Your Trading Page

You can add all the necessary features, including the Toolbar and Trading Chart. The trading page requires two files: [marketID].tsx. and index.tsx. Then, you will need to create a new page and update the index.tsx file. Add a redirect to the trading page after you fetch markets.

Get your Trading chart running by copying the charting_library from the web-sdk and publishing it. Then update the [marketID].tsx file. Finally, run a mock server for fetching some OpenDAX BE data like markets, cryptocurrencies, klines, and so on.