API Version: v0.2.1 Not using latest version (v0.2.3)

WETH9 v0.2.1 API Reference

WETH9

WETH9 implements the Wrapped Ether (WETH) token standard. This contract allows users to wrap ETH into an ERC20-compatible token and unwrap it back to ETH.

Events

Approval

event Approval(address indexed src, address indexed guy, uint256 wad)

Emitted when an approval is set.

ParameterTypeDescription
srcaddressThe address giving approval (indexed)
guyaddressThe address receiving approval (indexed)
waduint256The amount of tokens approved

Deposit

event Deposit(address indexed dst, uint256 wad)

Emitted when ETH is wrapped to WETH.

ParameterTypeDescription
dstaddressThe address receiving WETH (indexed)
waduint256The amount of ETH wrapped

Transfer

event Transfer(address indexed src, address indexed dst, uint256 wad)

Emitted when tokens are transferred.

ParameterTypeDescription
srcaddressThe sender's address (indexed)
dstaddressThe recipient's address (indexed)
waduint256The amount of tokens transferred

Withdrawal

event Withdrawal(address indexed src, uint256 wad)

Emitted when WETH is unwrapped back to ETH.

ParameterTypeDescription
srcaddressThe address unwrapping WETH (indexed)
waduint256The amount of WETH unwrapped

Variables

allowance

mapping(address => mapping(address => uint256)) public allowance

Maps owner addresses to spender addresses to approved amounts.

balanceOf

mapping(address => uint256) public balanceOf

Maps addresses to their token balances.

decimals

uint8 public decimals = 18

The number of decimal places used by the token.

name

string public name = "Wrapped Ether"

The name of the token.

symbol

string public symbol = "WETH"

The symbol of the token.

Functions

_deposit

function _deposit() internal

Internal function to handle ETH deposits and mint corresponding WETH tokens.

approve

function approve(address guy, uint256 wad) public returns (bool)

Approves another address to spend tokens.

Parameters:

ParameterTypeDescription
guyaddressThe address to approve
waduint256The amount of tokens to approve

Returns:

TypeDescription
boolAlways returns true

deposit

function deposit() external payable

Deposits ETH and mints WETH tokens.

receive

receive() external payable

Fallback function to handle direct ETH transfers. Calls _deposit() to wrap received ETH into WETH.

totalSupply

function totalSupply() public view returns (uint256)

Returns the total supply of WETH tokens.

Returns:

TypeDescription
uint256The total amount of WETH in the contract

transfer

function transfer(address dst, uint256 wad) public returns (bool)

Transfers tokens to another address.

Parameters:

ParameterTypeDescription
dstaddressThe recipient's address
waduint256The amount of tokens to transfer

Returns:

TypeDescription
boolTrue if the transfer succeeded

transferFrom

function transferFrom(address src, address dst, uint256 wad) public returns (bool)

Transfers tokens from one address to another.

Parameters:

ParameterTypeDescription
srcaddressThe source address
dstaddressThe destination address
waduint256The amount of tokens to transfer

Returns:

TypeDescription
boolTrue if the transfer succeeded

withdraw

function withdraw(uint256 wad) external

Withdraws ETH by burning WETH tokens.

Parameters:

ParameterTypeDescription
waduint256The amount to withdraw

Get the latest Chainlink content straight to your inbox.