Before we begin, I’d like to mention that I, DeFi Owl, am presently a member of The Gwei is Too Damn High party. Please send this to Vitalik with captions such as ‘Wen ETH2?’ and ‘Wen EIP-1559?’ Thank you in advance.
INTRODUCTION
This guide is aimed at the complete novice who doesn’t fully understand exactly what’s going on with Slippage Tolerance and Gwei/Gas Fees when putting transactions through Uniswap whilst connected with a Metamask wallet.
There are tons of guides out there already but I decided to write one up myself in layman’s terms based on how I personally understand this to work in the hopes of providing some tricks and tips to help new users get comfortable. Well… That and cause you guys voted in my Telegram to make me do work for free (jk jk, I love this shit frens).
I’m going to start with an explanation of what Slippage Tolerance does on Uniswap and why we need it. Then I’ll go into a brief overview of Ethereum gas fees, why we pay them, how they work, and how Metamask’s front end helps us to interact with the Ethereum blockchain to put our transactions through (with added tricks & tips about Gas and Slippage combinations).
This is from my own experience and knowledge I’ve gained, I don’t claim to be an expert and I might gloss over details others will find very important. Any feedback, please message me on Twitter or Telegram so I can improve!
PART 1: UNISWAP SLIPPAGE TOLERANCE
Due to the decentralized structure of Uniswap, transactions happen as a direct swap based on the current price of the tokens you are swapping. This is unlike the transaction mechanisms you’d typically find on a centralized exchange like Binance where you’d place buy and sell orders at a specific price and wait for them to fill. I like to think of Uniswap as trading in real-time, based off the “now” price.
For this to work, Uniswap has implemented a slippage tolerance that you can adjust. (See image below).
Without the slippage mechanism, during times of high trading activity where the price of a token is moving constantly due to increased volume (buys and sells), we would encounter constant failed swaps.
The reason for this is that if your slippage tolerance was set to 0 (or the slippage mechanism simply didn’t exist), you would be submitting transactions for the EXACT price you want to buy or sell the token at. Now remember, swaps happen in “real time” on Uniswap, so if the token changed price at all from the moment you went to submit your buy/sell, whether the price moved up or down, your transaction would not be fulfilled.
With no slippage, the price would have to remain constant throughout your transaction, however long that may take to go through, which can sometimes be minutes.
In comes slippage tolerance to fix this problem. Think of it as a percentage difference from the price that you want to buy/sell at that you are willing to accept if the price was to move.
During times of low or zero volume (no trading activity), setting a 0.1% slippage or even lower is totally fine because the price isn’t moving. I often do this with trading into stable coins like USDC as their price is pegged to the dollar. You rarely get a fail at 0.1% on USDC because the micro fluctuations in stable coin pegs don’t cause a fail unless there’s seriously crazy pumps happening.
However, if you’re fighting with others to buy in whilst a token is pumping in value, or you’re fighting to sell out of something that’s rapidly dumping, you will almost certainly have to increase your slippage to account for the volatile changes in price so that you can guarantee your buy or sell goes through.
Let’s look at what increasing your slippage does in the following examples.
Here in the example above, I’m swapping some of my ETH in my MetaMask wallet for USDC stable coin. (For example’s sake, let’s pretend USDC isn’t a stable coin and actually moves up and down in price like a normal ERC20 token, it’s just easy to use USDC because it’s worth a dollar per token!).
Anyway, as you can see above, Uniswap is showing me that this particular amount of ETH is worth an estimated 5000 USDC if I am to make the swap.
With a 0.1% Slippage Tolerance, let’s see how Uniswap estimates the actual amount of tokens I will receive. It shows that, in the menu below, with a 0.1% slippage I can expect to receive a minimum of 4990 USDC as shown in the menu below.
However, if I increase slippage to 1%, look what happens to the minimum received amount. It reduces to around 4950, so I might get less USDC for my 5000 USDC order.
Now let’s look at increasing slippage to 10%. It reduces the minimum amount I’ll receive even more drastically. (We would never ever, or very rarely use 10% slippage these days, this is just for example’s sake).
These examples just show how slippage affects the minimum amount of tokens you could receive with your swap if the price changes from the moment you submit your transaction.
Pro-Tip: You can actually swap much higher than the “Slippage Too High” amount. You just need to toggle into expert mode. Not relevant to this tutorial though!
What’s the correlation?
With higher slippage, you may receive less (or sometimes more) tokens than your swap amount, up to a maximum threshold that you’ve set.
The risk here is your minimum received amount. The more slippage you use the more of a hit you’re willing to potentially take if the price of the token you want moves up. (If the price moves down though, great, more tokens for you!)
The lower your slippage, the closer you will be to your exact swap price.
Why would we want higher slippage?
Because when the price moves, you have a higher chance of your transaction succeeding.
So how much slippage do I actually need then?
There is no set answer. As a rule of thumb, I go with anywhere from 0.01% to 0.1% for stablecoins, 0.5% if there’s not much volume on a normal token, and up to 5% if something is rapidly pumping.
What’s the maximum you’d use?
The maximum slippage I would personally set is up to 5% if I’m fighting to get into a token that’s started pumping hard. If you go higher than this, bots may front-run your transaction and use your slippage against you to buy in before you and sell after you buy. This can happen instantly and you might not even notice it.
DexTools has a a good visualiser tool under Trade History in the Pair Explorer for seeing these frontrunning bots benefit from people’s transactions.
Other considerations
There are other circumstances too, where for example a token might have an inbuilt metric that requires you to have higher slippage. Stuff like 1% taxes and 1% burns on transaction might force you to use 1% or 2% higher slippage than you normally would need to in order to account for the tax/burn or whatever metric it is.
Closing advice
When it comes to trading ERC20s on Uniswap, it’s always important to know what you are swapping into or out of. Make sure you understand what the token does and if there are any gremlins within the smart contract requiring you to use higher slippage. Sometimes you’ll receive a weird error like the one below if your slippage is too low for that token.
Another bit of closing advice on Slippage alone is to be aware of front-running bots. At all times I always try to opt for the lowest slippage possible in any situation. Optimizing your slippage and calculating it effectively will help to optimize your profits and not get rekt needlessly when trading on Uniswap.
PART 2: METAMASK & GWEI
Context
So we’ve already learned about Slippage in Part 1 and I want to now shift the focus over to Gwei and Gas fee estimation. We can then look at how Slippage and Gwei work together when trading on Uniswap so that you can balance both of these metrics efficiently.
MetaMask
MetaMask is my ERC20 wallet of choice. I personally use this wallet over other wallets when swapping tokens around with Uniswap. It’s the most commonly used wallet for this purpose and, in my opinion, the best optimized wallet for gas-fee estimation and ease-of-use. We’re also going to cover things like stuck transactions in MetaMask and how to easily fix them.
I’m going to completely gloss over all of the other important details of MetaMask (custody, security, test-nets, etc) that aren’t specifically pertinent to gas fee estimation and customization because this is what we want to focus on for this guide.
When you’ve set your slippage and hit Confirm Swap on Uniswap to swap to a token, you’ll then get a popup from your MetaMask wallet prompting you to evaluate your gas fee & total, and then confirm or reject the transaction.
In the example above, I’m simply swapping 0.01 ETH into some USDC. As you can see, MetaMask has automatically estimated that the best gas fee for this transaction is $55.26 in order for it to go through successfully and in a plausible amount of time. As a heads up, this estimation is not at all related to the amount you are swapping, and typically trading on a decentralized exchange is expensive relative to trading on centralized exchanges where fees are minimal.
But, I hear you asking yourself in your head; how on earth does MetaMask even know what gas fee is the correct amount to use for my transaction?
Simplified Gas Overview
Well, let’s take a look at this screenshot of the Ethereum Gas Tracker on Etherscan below for context. I’ve only included the simple and relevant metrics on the page that you need to pay attention to in order to get a solid overview.
The gas tracker is a vital tool to pay attention to, especially with the recent spike in gas fees due to increased volume on the Ethereum blockchain as of posting this tutorial.
What we can see above are three base numbers referred to as Gwei. The Gwei number is like a multiplier that tells us how expensive the completion time might be for a transaction on the Ethereum blockchain at that given moment.
Rule of thumb
The lower Gwei number you use, the longer the transaction takes to complete, however it is cheaper. The opposite is also true. The higher the Gwei number you use, the quicker the transaction takes to complete, but the more expensive it is.
The Gwei estimate for low, average, and high on the gas tracker above are constantly changing depending on how much traffic is going through the Ethereum network.
The higher the traffic, the higher the fees. We can see Gwei hit very high numbers when there is, for example, a massive pump in the trading volume and Ethereum has either rapidly increased or decreased in price.
To put it simply, there are good times of the day to use the Ethereum network where there are not too many people overwhelming it, making the fees cheaper, and there are bad times of the day where network usage is too high.
For the context of this guide, the area we want to pay most attention to is how much it costs to put a Uniswap transaction through.
Back to MetaMask
As you can see in the screenshot below, I put through the same identical transaction again about 20 minutes later. The automatic gas estimation by MetaMask is much lower at $39.27 because the estimated Gwei required to complete the transaction is lower at that moment in time simply because fewer people are flooding the Ethereum blockchain with transactions now than they were 20 minutes ago.
Custom Gwei
Sometimes, MetaMask might put a transaction through that gets stuck. This could be because, for example, MetaMask estimated that the appropriate Gwei for your transaction would be 100 at that moment. But then, by the time you confirmed your transaction, the gas price for an average or slow transaction moved up to a minimum of 150 Gwei. This can cause your 100 Gwei transaction to be stuck until Gwei calms down again.
To avoid this, it’s always good to set your own custom Gwei. I avoid messing with the Gas Limit on MetaMask too much and only focus on the Gwei because generally, increasing the Gas Limit is not required in a normal trading situation, so we will gloss over the Gas Limit to keep things simple for now.
If you see in the previous screenshot, above the number to the right of Gas Fee, you will see an EDIT button. When you click on this button you can set a custom gas fee. MetaMask has provided some handy presets that will allow you to get your transaction through from slow to fast.
The faster you want your transaction to go through, the more you will have to pay in fees so that miners are more incentivized to include your transaction over your peer’s transactions. We are essentially paying miners more to include us in their block and competing to be included in the block.
The fast option can often be very necessary, especially when trading volatility is high on an ERC20 token that you want to swap into. You would want to go with the fast option so that you can get your buy or sell in before anyone else gets theirs in. There is, however, more customization available than just the presets. If you click on the Advanced tab, you will be able to completely customize your gas.
Above I have changed the Gwei amount to 170, which costs significantly more. The reason I might want to do this is to absolutely ensure that I have the quickest transaction possible over my peers to get in the earliest. Be aware of setting Gwei too low. Of course, you might think you’re saving a lot of money by customizing your fee to a lower amount, but the likelihood is that it’ll be too low and time-out/fail. There are also other considerations, such as how this interacts with your slippage.
Why would I use custom Gwei for Uniswap?
Remember how I explained that Uniswap happens in real-time? This is why you want to customize your gas. If the price of a token is moving very quickly and your slippage tolerances are moderate to low for the speed at which the price is changing, you want to use fast gas to ensure that the transaction goes through as quickly as possible/reasonably affordable.
This is to ensure that the price does not move outside of your slippage tolerance and then fail before the transaction can be confirmed on the blockchain. If the price moves outside of your slippage tolerance, your swap will fail and you’ll pay a (reduced) fee for the failed transaction. These can add up though, and we can also lose a strong investment opportunity while the pump happens in our absence because we’re too busy messing around with putting through another failed transaction, or worse, spending time correcting a stuck transaction.
I rarely use slow Gwei for trading on Uniswap. It is possible when the Ethereum network is less volatile and when there’s low volume in the token you are trading, but during a bull run like the one we are currently experiencing as of the date this guide is being written, Gwei tends to stay quite high and there are fewer moments where you might find it getting low. I might also use it to do a simple transfer from one wallet to another when the transfer is not time-critical. The risk with using slow Gwei when trading though is that you will likely end up with a stuck transaction. This is the worst, but it can be fixed quickly.
Custom Nonce to fix stuck MetaMask transactions
Each time you send a transaction from your Ethereum address, it is given a Nonce, or transaction number. If you have a stuck transaction, a quick way to rectify this is to send a zero transaction to your own address with the same Nonce. Let me explain how to set this up.
Go to your MetaMask settings, then the Advanced tab, then toggle ON “Customize transaction nonce”.
TIP: This will change how your MetaMask transactions look, so please already make sure you’re used to using custom Gwei and Gas Limits before you attempt this as estimations might be wildly different at first. Consider it turning off auto-pilot and manually flying the plane.
Once this setting is enabled, you will need to find your stuck transaction in your MetaMask Activity tab and expand it to find the Nonce of that stuck transaction. For example, within Metamask it may look like this:
Or failing that, you can find the Etherscan entry and locate the Nonce under the “Click to see More” tab.
Once you have found the Nonce of the stuck transaction, simply send yourself 0 ETH (to your own address) with the Send function within MetaMask. Note that this will still cost a standard ERC20 Transfer fee (refer to the Ethereum Gas Tracker estimation).
Choose your slow/fast/average gas, and then hit Next and set the Nonce to the same Nonce as the stuck transaction:
The above example is if I had a stuck transaction with a Nonce of 62. Once this is confirmed, the 0 ETH transfer transaction will go through and your stuck transaction will fail. You can always then turn off Custom Nonce once you’ve resolved the issue.
PART 3: SUMMARY
In summary, we’ve independently covered how slippage works, the basics of how gas works and how you can customise your Gwei and mess with your Nonce settings to ensure transactions go through how you want them to go through.
The main take away from this is that it’s all a balancing act. Slippage tolerances in combination with custom gas fees is just something that you will get used to over time and you’ll figure out what works as you gain experience with Uniswap.
I hope you found this guide useful in answering some of those trickier questions about how these features all interact with each other. If you have any questions or feedback, please always feel free to get in touch on Twitter or Telegram. Love to hear from you always frens!
Oh and, FYI, a personal favourite YouTuber called Finematics has done a comprehensive video on the current gas fee model, miner incentivization, and proposed upgrades to the current gas model (EIP1559) that aims to make Ethereum a more usable network for everyone by reducing fees. He has covered a LOT more in his video and provides an in-depth overview of the whole model and how it works. There are also the ETH2 upgrades to look foward to which, at the time of this guide, haven’t been fully implemented yet.
Anyhow, thanks for reading and stay bullish on Ethereum!
Ya boy,
DeFi Owl