Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
 Building Full Stack DeFi Applications

You're reading from  Building Full Stack DeFi Applications

Product type Book
Published in Mar 2024
Publisher Packt
ISBN-13 9781837634118
Pages 490 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Samuel Zhou Samuel Zhou
Profile icon Samuel Zhou
Toc

Table of Contents (21) Chapters close

Preface 1. Part 1: Introduction to DeFi Application Development
2. Chapter 1: Introduction to DeFi 3. Chapter 2: Getting Started with DeFi Application Development 4. Chapter 3: Interacting with Smart Contracts and DeFi Wallets in the Frontend 5. Part 2: Design and Implementation of a DeFi Application for Trading Cryptos
6. Chapter 4: Introduction to Decentralized Exchanges 7. Chapter 5: Building Crypto-Trading Smart Contracts 8. Chapter 6: Implementing a Liquidity Management Frontend with Web3 9. Chapter 7: Implementing a Token-Swapping Frontend with Web3 10. Chapter 8: Working with Native Tokens 11. Part 3: Building a DeFi Application for Staking and Yield Farming
12. Chapter 9: Building Smart Contracts for Staking and Farming 13. Chapter 10: Implementing a Frontend for Staking and Farming 14. Part 4: Building a Crypto Loan App for Lending and Borrowing
15. Chapter 11: An Introduction to Crypto Loans 16. Chapter 12: Implementing an Asset Pool Smart Contract for a Crypto Loan 17. Chapter 13: Implementing a Price Oracle for Crypto Loans 18. Chapter 14: Implementing the Crypto Loan Frontend with Web3 19. Index 20. Other Books You May Enjoy

Diving into the WETH smart contract

Wrapped ETH (WETH) is an example of a wrapped native token on Ethereum. The smart contract of WETH doesn’t only implement the required interfaces of an ERC20 token but also the functions to wrap and unwrap the native token, ETH. Figure 8.1 shows how a user interacts with a WETH smart contract to wrap ETH and unwrap WETH.

Figure 8.1 – The process of wrapping ETH and unwrapping WETH

Figure 8.1 – The process of wrapping ETH and unwrapping WETH

As shown in Figure 8.1, a user can deposit ETH to a WETH smart contract, and the user will get the same amount of WETH with the given amount of ETH. The user can withdraw the original ETH by redeeming the same amount of WETH. Based on this, we will need to implement the deposit function to wrap ETH and the withdraw function to unwrap WETH in the WETH smart contract.

Demystifying the WETH smart contract

Now, let’s create a new solidity source file at src/backend/contracts/WETH.sol for the WETH smart contract, and copy...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime}