Decentralized Finance


This is module 6 of 10 for the Blockchain and Cryptocurrency course.

Module 5 << | >> Module 7

Readings

Decentralized Finance (DeFi)

Liquidity Pool

ERC-20 Tokens

+

Self-Directed Learning

  • Explore the range of DeFi applications. There are DeFi applications for trading crypto, for borrowing and lending crypto, and other traditional financial services. You should try to gauge the full spectrum of possibilities in the DeFi world before digging too deeply into any one. For instance, try to find a DeFi application the resembles a traditional financial service and one that is more unique.
  • Use a DeFi application. Just like in the previous module, use your wallet to interact with a DeFi application. This could be trading some of your crypto on a decentralized exchange, lending some of your crypto, or posting crypto as collateral and borrowing against it. Try to find a DeFi application that is particularly interesting to you and then engage with it as a user. Check out your transactions on Etherscan to see how it works.

+

Online Discussion of Module Topic

Write down what you are learning and questions that you may already have about DeFi. Here are some prompts to get you thinking:

  • How is DeFi similar to traditional finance? How is it different?
  • What are the pros and cons of DeFi relative to traditional finance?
  • Explain how DeFi uses the decentralized structure of blockchain.
  • What is the range of DeFi applications that are available?
  • Which of the DeFi applications resemble traditional financial services and which are more unique?
  • What was your experience of interacting with a DeFi application?
  • How much ETH was required to make a transaction?
  • Having engaged with a DeFi application, would you recommend it to others?
  • DeFi offers much higher rates of return than traditional lending. What are the risks?
  • What will it take to make DeFi more user friendly?

+

Technical Exercise

The technical exercise for Module 6 is to complete steps 6 and 7 of the Hardhat tutorial started in Module 5. 

Step 1. Open the Hardhat tutorial (https://hardhat.org/tutorial/) and pick up the tutorial on step 6: “Debugging with Hardhat Network.”  In this step, you will learn how to print or “log” messages with your program output. Add the suggested code to your Token.sol file in the contracts directory. This code will import console.log and provide some additional log messages. After updating the code, the output from running npx hardhat test will include the addresses involved in the transactions and the amount of tokens sent.

Step 2. Complete the first part of step 7 in the Hardhat tutorial on “Deploying to a live network.” In this step, you will learn how to deploy a smart contract to your local Hardhat blockchain network. From your hardhat-tutorial directory, run the npx hardhat run scripts/deploy.js command and you should see the three lines of output (it will take some time to run).

Step 3. Before starting the “Deploying to remote networks” in step 7, log into Alchemy and click on “+CREATE APP” like we did in an earlier module. Give your new app the name “token” and change the Network to Goerli. You should now see your token app in your list of apps.

Step 4. Complete the second part of step 7 in the Hardhat tutorial on “Deploying to remote networks.” In this step, you will learn how to deploy a smart contract to the Goerli Testnet. Replace the code in your config file with the code in this part of the tutorial. You will replace KEY with the API Key from your Alchemy app and put in the private key from the address where you have some Goerli ETH. (Note: You only replace these in the const lines, not in the lower lines.) You should also keep the listed version of solidity as your current version, which is probably 0.8.17. Running the deployment can take a little time. Once it completes, you should see the smart contract address, the account balance, and the token address.

Step 5. Take a screenshot of the deployed contract address and other information in your terminal and post your screenshot in the D2L discussion. 

Step 6. Go to etherscan.io and see your where your contract was created. In the top right of the Etherscan site, click on the Ethereum logo and change the network to Goerli. Then copy the address from Token address: in your Hardhat output and paste this into the Etherscan search bar. This should show the transaction that created your contract. Take a screenshot and post it in D2L.