Introduction to Wrapped Tokens
Wrapped tokens, often referred to as Wrapped Tokens, are ERC-20 compliant representations of native cryptocurrencies. Examples include WETH (Wrapped Ether), WBNB (Wrapped BNB), and WBTC (Wrapped Bitcoin). These tokens bridge the gap between native assets and smart contract compatibility.
Why Wrapped Tokens Exist
- ERC-20 Standardization: Native coins like ETH aren’t ERC-20 compliant, limiting their use in DeFi applications such as Uniswap or Curve. Wrapped tokens solve this by providing a standardized interface.
- Interoperability: Enables seamless interaction between native assets and smart contracts.
- 1:1 Peg: Each wrapped token is backed 1:1 by its native counterpart, ensuring value parity.
👉 Learn more about DeFi token standards
How Wrapped Tokens Work: The WETH Example
Key Features of WETH
- Name: Wrapped Ether
- Symbol: WETH
- Functionality: Converts ETH into an ERC-20 token and vice versa.
Use Cases
- Trading: Swap ETH for WETH to participate in ERC-20 token pools.
- Lending/Staking: Use WETH as collateral in DeFi protocols.
- Gas Efficiency: Reduces transaction complexity in smart contracts.
Building a WETH Smart Contract in Solidity
Below is a step-by-step implementation of a WETH contract using OpenZeppelin’s ERC-20 standard:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract WETH is ERC20 {
event Deposit(address indexed account, uint amount);
event Withdrawal(address indexed account, uint amount);
constructor() ERC20("Wrapped Ether", "WETH") {}
receive() external payable {
deposit();
}
function deposit() public payable {
_mint(msg.sender, msg.value);
emit Deposit(msg.sender, msg.value);
}
function withdraw(uint amount) public {
require(balanceOf(msg.sender) >= amount, "Insufficient WETH");
_burn(msg.sender, amount);
payable(msg.sender).transfer(amount);
emit Withdrawal(msg.sender, amount);
}
}Key Functions
deposit(): Converts ETH to WETH.withdraw(): Burns WETH to redeem ETH.- Events: Track deposits and withdrawals.
👉 Explore Solidity smart contract templates
Testing and Deploying WETH
Step 1: ETH → WETH
- Send ETH to the contract via
deposit()or direct transfer. - Verify WETH balance using
balanceOf().
Step 2: WETH → ETH
- Call
withdraw()with the amount in Wei (e.g., 2 ETH =2000000000000000000). - ETH is transferred back to the sender’s wallet.
FAQs About Wrapped Tokens
Q1: What’s the difference between ETH and WETH?
A1: ETH is native currency; WETH is its ERC-20 wrapper for DeFi compatibility.
Q2: Is WETH secure?
A2: Yes, it’s audited and widely used, with 1:1 ETH backing.
Q3: Can I wrap other assets like BTC?
A3: Yes—WBTC wraps Bitcoin for Ethereum-based DeFi.
Q4: Are there fees for wrapping/unwrapping?
A4: Only gas fees; no additional charges.
Key Takeaways
- Standardization: Wrapped tokens ensure native assets work in ERC-20 ecosystems.
- Utility: Critical for DeFi, trading, and smart contract interoperability.
- Trustless Design: 1:1 peg maintained via transparent smart contracts.
For further reading, check our advanced guides on tokenization and cross-chain bridges. 🚀
This optimized version: