Instant Crypto Exchange Dapp (Ethereum, Smart contracts)

Introduction:

Crypto Exchange Dapp serves as an instant exchange for swapping a ERC-20 crypto Token with ETH at a fixed rate.

Features:

  1. Built on robust smart contracts using Solidity programming
  2. Instant crypto Exchange with no time wait needed to fill orders.
  3. Deployed to Rinkeby network and available on GitHub pages here
  4. Users/Investors can buy and sell tokens (swap) with ETH instantly.
  5. Test driven development (JS) for handling exceptions and smart contract logic.
  6. Async / await to handle JS promises & asynchronous function calls.
  7. App Frontend built using React JS reusable components and JS/HTML.
  8. Displays account details, ETH & Token Balance in app UI along with custom avatar.
  9. Easy toggle between buy and sell interfaces using react state handler.
  10. Window alerts to check Metamask integration in browser and dapp deployment.

Tools:

Ethereum, Solidity, Ganache CLI, Truffle framework, Metamask, web3.JS, React.JS, HTML

Working:

  • Contain the main business logic of the application (dapp).
  • Immutable and execute on the (Ethereum) blockchain.
  • Reads and writes data (uses gas fee) on the blockchain.
  1. Browser needs to be connected to the blockchain (refer Metamask section below)
  • Keep track of token purchase and sale using events in the smart contract.
  • BuyForm.js (token < > ETH swap)
  • SellForm.js (token < > ETH swap)
  • Navbar.js
  • This generates a blockchain transaction receipt along with a hash.
  • Hence, this sale should be approved by the user through an approve function, which is called on the token smart contract (and not the exchange contract) and only then the selltokens function gets executed on the blockchain.

Events:

Solidity allows for events to be emitted when something happens, for example when tokens are purchased and/or tokens are sold. ( TokensPurchased , TokensSold events )

Tests:

Tests built with Truffle test framework using Mocha Framework & Chai assertion.

  • Users can’t sell to the exchange, more tokens that they have.
  • Exchange should have sufficient tokens for the exchange.

Metamask:

Dapp Backend to Frontend Integration:

Web3 to Metamask connection config code:

Deployment:

Crypto exchange Dapp is currently deployed to Rinkeby Ethereum test network.

Resources:

Deployed Dapp (GitHub pages): https://itznishant.github.io/CryptoExchangeDapp/

Prolific Blockchain Smart Contract Developer, Experienced Data Scientist , forever Learner