Implementing a Token-Swapping Frontend with Web3
Token swapping is the key feature of liquidity pool-based decentralized exchanges (DEXs). Token swapping is the operation to exchange one token with another token. It enables people to buy or sell tokens on DEXs.
In Chapter 5, Building Crypto-Trading Smart Contracts you learned that token swapping is performed by an AMMRouter
smart contract through interaction with smart contracts with the Hardhat console. Token swapping requires a user to transfer an amount of a token to a liquidity pool (the TokenPair
smart contract) and the smart contract will transfer some other token from the liquidity pool back to the user. In this chapter, we will learn how to interact with smart contracts using JavaScript and implement the frontend of the token swapping feature.
Token swapping involves multiple liquidity pools if there are no token pairs for the two tokens for swapping. This may bring complexity for token swapping. However, we will show...