Decentralized Exchanges are a type of dApp that facilitate self-custody token swaps.
There is some practical knowledge required for confidently interacting with a DEX.
We can use block explorers to inspect our on-chain transactions.
The Decentralized Exchange (DEX) is the most commonly used application in the world of Decentralized Finance
(DeFi) — and for good reason! DEXs enable automated swapping of one cryptocurrency token for another, without need for a mediator. Unlike Centralized Exchanges (CEXs), this type of swap also enables users to swap while retaining full ownership of their assets.
Autonomy, and permissionless protocols, are backbone features of DeFi. They empower DeFi users with true ownership over their digital assets, and open access to fundamental blockchain services 24/7. Anyone with an internet connection can access DeFi, regardless of their personal background, beliefs, or geographical location.
In this handbook entry, we will cover how to use your self-custody wallet to interact with a DEX, with the goal of swapping one token for another. You can learn more about the mechanics, qualities, and risk profile of this technology, and how it compares to CEXs, in our lesson on Decentralized Exchanges.
Selecting an affordable and safe platform is the first step in performing a token swap. In this walkthrough we will be using Velodrome, the most popular DEX on the Optimism network (at time of writing). As you become more confident in blockchain navigation, you’ll learn how to evaluate other exchanges and find the best fit for your needs. Our Decentralized Exchanges lesson includes a comprehensive list of qualities to look out for.
DEXs are a great start to your web3 journey because most dApps follow a user interface layout similar to DEXs, and use similar interactions with your self-custody wallet.
Let’s begin our token swap.
1. Load the dApp:
Open Velodrome in a new browser tab.
2. Connect your wallet:
Use the standard ‘Connect’ button typically located in the top right corner of any dApp.
If you are on desktop, connect with your browser wallet.
If you are on mobile, you will be prompted to use WalletConnect — the web3 standard for connecting mobile wallets to dApps.
3. Approve the connection:
Select ‘Connect’ in your wallet application to confirm the site connection. This allows the dApp to see your wallet address and token balances. You haven’t granted any other permissions yet.
4. Check and sign the terms of service (if you accept):
Many dApps will ask you to sign a message to confirm you have read their terms and conditions. Signing messages doesn’t cost gas, and doesn’t store any information on the blockchain. If you agree with the terms, you can sign the message.
5. Switch to the right network:
For this walkthrough, make sure your wallet is set to the Optimism network.
6. Customize your swap:
It’s time to select your desired input and output tokens. In this example, we will be swapping ETH for OP — but you can swap whatever tokens you like!
7. Approve token permissions:
You will be prompted to set and approve permission for Velodrome to access your wallet funds. We recommend limiting this to your trade size to limit future interactions with your tokens. (Stay tuned for future content on token permissions!)
8. Confirm the transaction:
Once you’re happy with your swap quote and settings, you can begin the swap. This step includes confirming on the dApp, and again in your wallet.
9. Check your balance:
Your transaction should take around 40 seconds to confirm, after which you will see your new token balance in your wallet. If your token type is not displayed, make sure you’ve imported the token addresses.
Optimism token contract address: 0x4200000000000000000000000000000000000042
10. Fetch your transaction hash:
To complete the quest for our Decentralized Exchanges lesson, you’ll need the transaction hash of the swap (not to be confused with the hash from your token permission transaction, or your wallet address). A block explorer link will usually appear on the DEX interface, letting you view the confirmed transaction details.. If you missed it, or it’s missing, you’ll find another link in your wallet activity log — tied directly to your trade.
It’s time to explore the world of decentralized trading! We hope you’ve enjoyed this entry in the Explorer’s Handbook: ‘Swapping on a Decentralized Exchange’.
Don’t forget to collect this entry if you want to own a copy for easy reference on your travels, or to support future content at Bankless Academy. Safe travels, Explorer!
Price quotes are typically calculated at the time you enter your desired swap into the DEX interface. As time goes by, other users are making swaps and affecting token supply on the exchange. The DEX will regularly refresh your quote to stay up to date.
The answer depends on a variety of factors, primarily the block speed of the blockchain and how much you underpay or overpay the gas fee. DEX transactions submitted to Ethereum Mainnet typically take between 15 seconds and a couple of minutes to be confirmed. Layer 2 transactions are usually faster!
There are a number of reasons why a transaction could fail: insufficient funds to pay gas, gas limit set too low, or slippage set too low. The best way to begin troubleshooting is to look for User Interface error messages. You can also view your transaction on a block explorer, like Etherscan, to check if there are any on-chain error messages. We’ll cover more troubleshooting specifics in future content!
Granting token permissions to a smart contract can leave our wallet vulnerable to unwanted future interactions, in the case of a smart contract hack. It is possible to change or remove token permissions using apps like Revoke.cash. As adjusting permissions costs gas, this precaution can quickly become expensive. This is one of the reasons why many users store their digital assets in one wallet (cold wallet), while interacting with dApps on another (trading wallet). Users transfer assets between them only as necessary.
If your token isn’t listed by default, you’ll have to paste the token contract address into the list. To find the token contract address, check https://www.coingecko.com/ or the official project website.
Note: Token addresses can change for a given token on different networks. For example the USDC contract on Mainnet is different than the USDC contract on Optimism. Always verify token addresses before swapping!
Author
Tetranome is the Project Champion at Bankless Academy, focusing on user experience, UI, design, and platform curriculum.
Editor
Trewkat is a writer and editor at BanklessDAO. She’s interested in learning as much as possible about crypto and NFTs, with a particular focus on how best to communicate this knowledge to others.
Patron
This unsponsored article is part of your free Bankless Academy education. Collect the article to support future content!
This article does not contain financial or tax advice. Bankless Academy is strictly educational and is not investment advice or a solicitation to buy or sell any assets or make any financial decisions. Talk to your accountant. Do your own research.
Explore more lessons on Bankless Academy to level up your web3 knowledge.