How to Swap Tokens on the Blockchain With DEXs
You can swap tokens by connecting your non-custodial wallet (like MetaMask) to decentralized exchanges (DEXs). Input the token you wish to swap and the token you wish to buy, approve tokens, click swap, and sign the transaction with your wallet.
Key Takeaways
-
Token swaps are essential in allowing users to buy and sell their tokens over the blockchain on their own self custodial wallets through decentralized exchanges (DEXs).
-
Users must consider gas fees, token approvals and token contract addresses before they perform their token swap.
-
Token swaps are best conducted at the largest DEXs which differs from blockchain to blockchain. Alternatively, users can also use DEX aggregators to find the best token swap rates.
In this series, we will cover everything you need to know about swapping tokens on the blockchain using decentralized exchanges (DEXs), where to do it, the common pitfalls and much more! Before we begin on where and how to do it, let’s go through some of the basic concepts of token swaps.
What Are Token Swaps?
Token swaps on the blockchain are akin to you buying/selling things online, while you exchange money for goods and services in real life. On the blockchain, we exchange one token for another. If you were to live in the United States, the United States Dollar (USD) is the common currency used to buy and sell goods. Similarly, on Ethereum, ETH is the commonly used currency to exchange for other tokens.
What Are Gas Tokens and What Are They Used For?
The reason why ETH is commonly used to exchange for other tokens on Ethereum is because ETH is the gas token of the Ethereum blockchain. Gas tokens are the tokens needed to pay for transaction fees. This is another important consideration for users before you conduct your token swaps. In addition to swapping your tokens, you must also consider how much funds are needed to pay for fees. Let’s say you have $100 worth of ETH and you wish to buy/swap into $100 worth of USDC, you must have more than $100 worth of ETH so that you may buy/swap into $100 worth of USDC and have enough to pay for transaction fees too.
A general rule of thumb is that you should have at least $10 worth of gas tokens set aside to pay for your transaction fees at all times. This will help you avoid the situation where you wish to swap tokens but not have enough to pay for fees.
Note: If you are transacting on Ethereum (mainnet), transaction fees are much higher and it's recommended to have at least $50 worth of gas tokens (ETH) set aside.
Token Approvals: For Ethereum/EVM Blockchains
If you are transacting on blockchains that are EVM compatible such as Ethereum, BSC, Base, Arbitrum, Avalanche, Polygon, Optimism, etc. Token approvals is something you should know about. On these blockchains, token approvals will be needed if you attempt to transact anything other than the gas token of the respective blockchains. Token approvals are a security feature of EVM chains. Smart contracts that wish to transfer or interact with any of your holdings other than gas tokens will require additional explicit permission (via token approvals) before they can do so. Below are some examples of how token approvals on EVM chains work.
Example 1: Swapping USDC to ETH on Arbitrum (Ethereum Layer 2)
ETH is the gas token on Arbitrum, this means that if you wish to swap (sell) any other tokens, you will need to approve the token you wish to sell. In the example below, an approval for the amount of USDC you want to swap will be required before you can do a token swap to exchange USDC for ETH. If you reverse the transaction order, swapping ETH to USDC, token approvals are not required before you can swap your tokens.
Example 2: Swapping AVAX to USDC on Avalanche (Layer 1)
On Avalanche, AVAX is the gas token. Swapping AVAX to USDC thus requires no token approval and you can go straight to swapping without token approval. Intuitively, this means that if you’re transacting on EVM chains, holding and transacting with the gas token will be more convenient compared to transacting with other tokens.
Cautionary Note on Token Approvals
When prompted for token approvals, there may be cases where the decentralized application (dApp) you are interacting with will autofill the amount of tokens approved to be infinite (or just an obscenely large number). This is bad practice as it can lead to your crypto wallet being opened up for potential exploitations by crypto hackers. Although it can be slightly more cumbersome, always approve only the amount of tokens you are going to transact with and revoke unused approvals occasionally. Learn more about how to revoke token approvals in our crypto security article here!
An example of a dApp requesting for infinite token approval by default.
General Flow of How Token Swaps are Done
That’s all the basic information you need, now you are ready to perform your token swaps! Where you swap your tokens and what you swap your tokens with will differ from blockchain to blockchain, but the general flow is usually as follows:
-
Go to a decentralized exchange (DEX).
-
Connect your crypto wallet (Metamask, Rabby, Phantom, Keplr, etc.).
-
Select your input token (the token you wish to sell).
-
Select your output token (the token you wish to buy).
-
Approve tokens if needed (Only for EVM chains).
-
Click ‘swap’.
-
Complete the transaction.
Full Example of Swapping ETH to USDC on Base
Below we will go through in detail how to perform a swap on Base, you may replicate this process on the various other DEXes for the other blockchains. The process will be highly similar with the exception of token approvals for EVM chains.
Step 0.5: Ensure that you have sufficient gas tokens for this transaction (ETH on Base)
Step 1: Go to your choice of a DEX on Base and connect your wallet
Aerodrome Finance will be used in this example. You may refer to https://defillama.com/chain/Base for the full list of Base dApps to choose your preferred DEX. DefiLlama is a good resource for users who wish to explore and find new dApps to interact with.
Step 2: Select your input token (selling) and your output token (buying)
When selecting your output token (token you wish to buy), ensure that the contract address (“0x8335…02913” for USDC) of the token you have selected is the correct one. This is important because in crypto there are many derivatives of the same asset you wish to swap for. For instance, axlUSDC also exists on Base, which can confuse new users, to ensure that you swap for the correct token you intend to buy, always verify the token contract address (CA for short), you may use CoinGecko’s token information page to do this as these have been carefully vetted by our operations team!
Author’s note: Personally, I recommend searching for tokens via contract address, meaning to copy and paste the full CA of USDC (0x833589fcd6edb6e08f4c7c32d4f71b54bda02913) when searching for the token. It is more cumbersome but it is good practice and ensures that you are swapping for the intended token.
Step 3: Enter the amount to swap, signing any token approvals if needed
ETH has been selected as the base to swap into USDC. Since ETH is the gas token used on Base, no token approvals are needed prior to swapping.
Step 4: Perform the swap
You can check the status of your transaction in your crypto wallet, it may take some time for the transaction to go through especially during periods of network congestion. Once the transaction is finalized, it will be recorded on the blockchain explorer and you can view it on Base’s blockchain explorer, by searching for your transaction ID.
Token Swap Masterlist
In this section, we will provide you with summarized key information on all leading blockchains where decentralized finance (DeFi) activities occur. We will share the top DEX in each blockchain (by Total Value Locked) and the gas token the blockchain uses. Generally, users would prefer to swap their tokens on the largest DEX as token liquidity is generally the largest on these DEXs. Large and deep liquidity pools are preferred as traders would typically enjoy lower slippage on their trades. Lower slippage ensures traders get token swap rates closer to the displayed prices and makes transactions more likely to go through on the blockchain (high slippage transactions tend to fail).
How and Where to Swap Tokens on Ethereum
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and Where to Swap Tokens on Base (Ethereum L2)
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and Where to Swap Tokens on Arbitrum (Ethereum L2)
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and Where to Swap Tokens on Optimism (Ethereum L2)
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and where to swap tokens on Linea (Ethereum L2)
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and where to swap tokens on Scroll (Ethereum L2)
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and where to swap tokens on ZKsync (Ethereum L2)
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and Where to Swap Tokens on Solana
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and Where to Swap Tokens on Binance Smart Chain
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and Where to Swap Tokens on Sui
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and Where to Swap Tokens on TON
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and Where to Swap Tokens on Avalanche
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and Where to Swap Tokens on Polygon
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and Where to Swap Tokens on Aptos
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and Where to Swap Tokens on Tron
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and Where to Swap Tokens on Cronos
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and Where to Swap Tokens on Fantom
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
How and Where to Swap Tokens on Osmosis (Cosmos)
Top decentralized exchange (DEX) by Total Value Locked:
Gas Token:
Decentralized Exchange (DEX) Aggregator
While the above list shows you the top DEXs by TVL in each blockchain at the time of writing, this is still subject to market changes in the future. To help traders achieve the best possible rates with the lowest slippage, traders may use a decentralized application (dApp) tool called DEX aggregators.
Functionally, DEX aggregators appear to work the same as DEXs, the front-end and user interface (UI) is similar to that of DEXs and the process to use them for token swaps remains the same. On the back end, DEX aggregators are different in that they scour their respective blockchain and all the DEXs within to find the most efficient and effective way to route your trades to get users the best possible rates. These aggregators may charge a small fee for this service, or free in the case of Solana’s Jupiter.
Consider using DEX aggregators when you are unsure of which DEX to use to perform token swaps. Currently, the most popular DEX aggregators are:
For Ethereum/EVM chain users – 1inch
For Solana users – Jupiter
Solana’s DEX aggregator, Jupiter.
Conclusion
That’s it! This should be everything you need to know to get you started on your DeFi journey whether it be trading memecoins, trying out DEXs or simply buying your favorite non-listed crypto token.
This article is only for informational and educational purposes and should not be taken as financial advice. Always do your own research before engaging with any protocol.
Subscribe to the CoinGecko Daily Newsletter!