Skip main navigation

New offer! Get 30% off one whole year of Unlimited learning. Subscribe for just £249.99 £174.99. New subscribers only T&Cs apply

Find out more

Swapping Ethereum for Dai

In this video, Chris Berg from RMIT's Blockchain Innovation Hub shows us how to swap Ethereum tokens for Dai on a testnet
0.2
(upbeat music) <v ->Now that we’ve acquired some testnet Ethereum,</v> we can use our MetaMask wallets interact with protocols and dApps across the DeFi ecosystem. In this video, I’m going to show you how to use a decentralized exchange to swap some of our Ethereum for a stablecoin, DAI, and then how to add DAI so that it shows up in our MetaMask wallet. DAI is a cryptocurrency-backed stablecoin produced by MakerDAO. We’ll talk a lot about stablecoins in our next discussion, but for now what’s important is that DAI is designed to be pegged to the price of the US dollar. So one DAI equals one dollar. Of course, we’re still using testnet tokens today so these can’t be redeemed for real money.
46.8
But converting money in and out of stablecoins through a decentralized exchange is a very common DeFi task. To make this exchange, we’re going to use a decentralized exchange called Uniswap. Uniswap was one of the first major DeFi protocols. So to do so, we’ll first visit uniswap.org, and we’ll click Launch App. Once the app is open, we can see this simple interface where we can swap between two tokens. The first thing we’re going to want to do is connect our wallet to the Uniswap app. So we click Connect to a Wallet, and we’re going to use MetaMask obviously. Up in the top corner, we can see that MetaMask is asking for permission to connect.
89.9
Now, only connect to sites you trust, and we’ll choose the account we want to connect with. You can see that I’ve been playing around with lots of different accounts here. And then we choose that, and we click Next. After MetaMask confirms what permissions we’re granting, in this case, the ability to view the address of the account we chose, we click Connect. Now, we set up the swap. We’re happy swapping from Ethereum, and we’re going to click Select a token and choose DAI from the list. Then we need to enter an amount. In this case, I’m going to swap one testnet Ethereum, which they are happy to offer me 422 DAI. I click Swap.
132.8
In this dialog box, we’re going to confirm a few things about the swap. There are a few things to point out here. When we trade in Uniswap, we’re actually trading with a pool of two tokens. In this case, DAI and ETH, that keeping balance with each other in the pool by changing the price at which each of them trade. Liquidity providers have put in their own funds into the pool that we’re trading with. And they’re going to receive a small fee from each trade for their trouble. In this case, that fee is .1 ETH.
166
Because the price that Uniswap will offer us for each asset changes depending on the balance of the pool, the final price to us is just an estimate. Others may make some trades against the pool while we’re deliberating here. So we nominate a slippage tolerance. That is how much we are willing for the price to change from our estimate. As it says here, we will receive at least 420 DAI or the transaction will revert, that is be canceled by the protocol. Now, if we’re happy with all this, and I am, we click Confirm Swap.
206.7
MetaMask up here will ask us to confirm the trade and reveal how much gas we’ll have to pay in addition to the Uniswap fee in order to use the Ethereum network. Pay close attention to this gas price. It can vary wildly and can make trades uneconomical if you’re not careful. But I’m happy with this fee so I’m just going to click Confirm. The transaction has now been submitted. If I click View on Explorer in here, I can see the transaction pending on the Ropsten Testnet chain.
247
Once it goes through, however, I’m still going to have one more thing to do.
252.8
I have to teach MetaMask how to recognize DAI in my wallet. Happily, MetaMask has made this really easy. If I click Add DAI to MetaMask, I open MetaMask, and add suggested token DAI.
271.4
Now, if I returned to the Assets page, I can see that I’ve got nearly 4 Ethereum and 422 DAI in my wallet. Finally, to look at that on the blockchain explorer again, I click View on Etherscan, as always,
289.4
and I can see my most recent transaction here. And if I click the Token dropdown box, I can see my 422 newly acquired DAI.
302.6
So in this video, we’ve swapped Ethereum for the stablecoin DAI, added DAI to MetaMask, and viewed the transaction on a blockchain explorer. (upbeat music)

Now that we understand why you would want to swap tokens for stablecoins, let’s practice doing it.

Follow along with Associate Professor Chris Berg as he swaps Ethereum tokens for Dai on a testnet and adds the Dai token to his Metamask wallet.

Now it’s your turn

Share how much Ethereum you swapped and how much Dai you got for it in the comments. How does your rate compare to the other trades in the comments?

This article is from the free online

Decentralised Finance: Blockchain, Ethereum, and The Future of Banking

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now