Reader small image

You're reading from  Building Full Stack DeFi Applications

Product typeBook
Published inMar 2024
PublisherPackt
ISBN-139781837634118
Edition1st Edition
Concepts
Right arrow
Author (1)
Samuel Zhou
Samuel Zhou
author image
Samuel Zhou

Samuel Zhou has over 15 years of software engineering experience in top high tech companies including being a blockchain developer as his hobby since 2018. In 2022, Samuel turned his enthusiasm on blockchain technology into a business by founding TiFi, which is a silicon valley based startup that builds e-Commerce platform on blockchain and brings blockchain to everyday life. Over there he has created TiFi Token that offers token rebates so people can get cash back when spending the token. Also he has built TiFi Bank which is a DeFi application that offers crypto saving, lending, trading, staking and liquidity management features. Samuel holds a Master Degree and a Bachelor Degree in Computer Science.
Read more about Samuel Zhou

Right arrow

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 page is locked
Previous PageNext Page
You have been reading a chapter from
Building Full Stack DeFi Applications
Published in: Mar 2024Publisher: PacktISBN-13: 9781837634118

Author (1)

author image
Samuel Zhou

Samuel Zhou has over 15 years of software engineering experience in top high tech companies including being a blockchain developer as his hobby since 2018. In 2022, Samuel turned his enthusiasm on blockchain technology into a business by founding TiFi, which is a silicon valley based startup that builds e-Commerce platform on blockchain and brings blockchain to everyday life. Over there he has created TiFi Token that offers token rebates so people can get cash back when spending the token. Also he has built TiFi Bank which is a DeFi application that offers crypto saving, lending, trading, staking and liquidity management features. Samuel holds a Master Degree and a Bachelor Degree in Computer Science.
Read more about Samuel Zhou