Uniswap Tutorial For Absolute Beginners

Behzad Pournouri
7 min readNov 4, 2020

Uniswap is a decentralized exchange that allows anyone to swap ERC20 tokens. in this article, we are going to learn about swapping Ethereum-based tokens(ERC20) on the uniswap as well as borrowing these tokens on the Compound application!

Installing MetaMask

First of all, you should create a MetaMask crypto wallet. MetaMask lets you connect to blockchain based applications like Uniswap. It can be installed as a browser extension or mobile application.

After installing and creating an account, you will get your seed phrase. Don’t lose or share this phrase with anyone.

By entering the MetaMask application, you have an ethereum wallet address that starts with 0x characters. it’s something like: 0xE349fBbeDA6642BF459f4957b6D6AbcCBA8bA74c

Getting some Ethers

We are just about to learn using uniswap. so, it’s better to use one of ethereum test networks.
Test networks basically allow us not to use our real ethers. instead, we will use some fake ethers that worth nothing in the real world.
Inside the MetaMask, look for network dropdown and change the network to the Ropsten Test Network and leave it like this until the end of the tutorial.

As you know, we are not going to use real ether! we are going to use some fake Ethers on the Ropsten test network. but, how can we get these fake ethers? that’s the next step!

Copy your account address, then go to https://faucet.dimensions.network , paste your account address and hit the button.

You will get 5 fake ether after a couple of minutes!

Why You Will Need Ether?

As I said, uniswap is an Ethereum-based exchange that allows anyone to swap ERC20 tokens. to swap these tokens, you have to pay a gas fee to the Ethereum blockchain.
Even if you already have any ERC20 tokens and want to trade these for Ether or other ERC20s, you’ll still need Ether to cover the gas fee.
If you don’t have Ether in your MetaMask wallet, you won’t be able to swap any token!

What is Gas?

Every single operation that takes part in Ethereum, be it a transaction or smart contract execution requires some amount of gas.
For example, let’s say sending a transaction may cost 1000 gas. we set the gas price to 0.000002 Ether. so our transaction gas fee will be 1000 * 0.000002 = 0.002 eth.
The best way to calculate all of this is to visit the gas station — ETH Gas Station.
I’ve taken this screenshot from ETH Gas Station website. It shows you the recommended gas price in gwai.

Well, it seems we need some calculations here!🚶‍♂️
1 Ether is equal to 1,000,000,000 Gwei. (just search Ethereum Units in Google)
As you see in the above picture, for a fast transaction, the gas price should be 53 gwei (53 Gwei / 1,000,000,000 = 0.000000053 Eth).

So, If your transaction costs 1000 gas and you set gas price to 0.000000053 Ether (or 53 Gwei), the transaction gas fee will be:
1000 * 0.000000053 = 0.000053 Ether😊

These recommended gas prices may be changed at the time you visit the ETH Gas Station website.

Now it’s time to use the uniswap!

Open the uniswap. In the top right corner, click on the ‘Connect to a wallet’ button.

Your wallet is now connected to the uniswap on the Ropsten test network! Like mine:

It’s time to trade on uniswap.🔥🦄

Trading on the Uniswap Decentralized exchange

Open uniswap and exchange some of the fake Ethers you’ve received with the UNI token. this means you’re sending Ether from your MetaMask wallet to the liquidity pool for some UNI token.

Something to be aware of here is the price impact value!

What is price impact?

Basically, the price impact refers to your buy size relative to the amount of liquidity in that pool. If you have a large order relative to the pool size, the price impact will increase (and your exchange rate declines).
In practice, it happens when you enter your order and click swap, but get an error because the price changed between when you entered the order and clicked swap.
Remember, more price impact means fewer tokens.👈

Swap!

Hit the swap button.
Here you see the details of the transaction. If all looks good and as it should, Confirm swap.

After confirmation, MetaMask will pop up, asking you to confirm or reject the transaction.

I have set gas price to 53 Gwei for my transaction to be as fast as possible!

The transaction is now pending. Once you confirm the transaction in your MetaMask wallet, you have to wait a few moments for the tranaction to hit the blockchain.

After less than a minute, my transaction submitted to the blockchain! now my ethers balance has been decreased from 6 to 5.893.
Here is my transaction on the Ropsten test network!

If I hit the purple UNI button, I can see I have 0.27 from the UNI token!

Congrats, You learned to trade on the uniswap exchange🥳

Borrow Ethereum Assets

Go to Compound website. It needs your MetaMask wallet to be connected to the website. just like the uniswap.
Notice that we want to use our fake Ethers, so we still live on the Ropsten test network.

You’ll see supply markets on the left, borrow markets on the right, and Summary Information on top.
From the left column, click on Ether.

We want to deposit some of the test Ethers as collateral in the decentralized Compound Bank. By doing this, you will receive an annual profit with variable percentage (APY).

Now you can borrow on your collateral😎

You can enable or disable an asset to be used as collateral by pressing the toggle on the right.

You’ll be presented with a confirmation modal, which will display how your Borrow Limit will change.

The Compound protocol relies on collateral to determine how much you can borrow!

click on an asset in the Borrow panel on the right for borrowing and then, enter the quantity of the asset you’d like to Borrow.
The SAFE MAX button will borrow up to 80% of your Borrow Limit.

If your Borrow Balance exceeds your Borrow Limit, your account will be partially liquidated. This can occur when collateral declines in value, or borrowed assets increase in value.

Conclusion

Congratulations, you have already learned to exchange your digital assets freely in a decentralized, secure, borderless exchange, or to use them as collateral and borrow without selling your assets.

Once you have learned this process, you can use the DeFi products you have learned in the real Ethereum environment👍

My name is Behzad. I work as a blockchain developer and have experience with Ethereum development and Hyperledger fabric for the enterprise blockchain platforms.

Currently, I am writing an article series that teach you how to build a real-world DAPP using Solidity and Reactjs. You can take a look at the introduction of project here: Delance Project

After that, I plan to write another article series about DeFi programming. you can follow me here on Medium or on Twitter to be noticed whenever I published an article.

--

--

Behzad Pournouri

I build smart contracts and distributed applications | Blockchain developer | Hyperledger Fabric | Ethereum