# WETH Gateway

If you need to use native ETH in the protocol, it must first be wrapped into WETH. The WETH Gateway contract is a helper contract to easily wrap and unwrap ETH as necessary when interacting with the protocol, since ETH is no longer used within protocol interactions.

The source code can be [found here](https://github.com/aave/protocol-v2/blob/master/contracts/misc/WETHGateway.sol), with the latest deployed address listed in the [Deployed Contracts](https://docs.aave.com/developers/getting-started/deployed-contracts).

## Methods <a href="#methods" id="methods"></a>

### depositET&#x48;**()** <a href="#depositeth" id="depositeth"></a>

**`function depositETH(address onBehalfOf, uint16 referralCode)`**

Deposits the `msg.value` amount of ETH into the protocol, minting the same amount of corresponding aWETH, and transferring them to the `onBehalfOf` address.

For `referralCode` input explanations, please refer to the [referral program section](https://docs.aave.com/developers/referral-program) of the documentation. During testing, you can use the referral code: `0`.

Ensure that the `depositETH()` transaction also includes the amount of ETH you are depositing in the `msg.value`.

| Parameter Name | Type    | Description                                                                                                         |
| -------------- | ------- | ------------------------------------------------------------------------------------------------------------------- |
| `onBehalfOf`   | address | address whom will receive the aWETH. Use `msg.sender` when the aTokens should be sent to the caller.                |
| `referralCode` | uint16  | referral code for our [referral program](https://docs.aave.com/developers/referral-program). Use 0 for no referral. |

### withdrawET&#x48;**()** <a href="#withdraweth" id="withdraweth"></a>

**`function withdrawETH(uint256 amount, address to)`**

Withdraws `amount` of the WETH, unwraps it to ETH, and transfers the ETH to the `to` address.

Ensure you set the relevant ERC20 allowance of aWETH, before calling this function, so the `WETHGateway` contract can burn the associated aWETH.

| Parameter Name | Type    | Description                                                                                    |
| -------------- | ------- | ---------------------------------------------------------------------------------------------- |
| `amount`       | uint256 | amount deposited, expressed in wei units. Use `type(uint).max` to withdraw the entire balance. |
| `to`           | address | address that will receive the unwrapped ETH                                                    |

### repayET&#x48;**()** <a href="#repayeth" id="repayeth"></a>

**`function repayETH(uint256 amount, uint256 rateMode, address onBehalfOf)`**

Repays `onBehalfOf`'s debt `amount` of ETH which has a `rateMode`.

Ensure that the `repayETH()` transaction also includes the amount of ETH you are repaying in the `msg.value`.

| Parameter Name | Type    | Description                                                                                                                                                                                                                                                                                                                                                   |
| -------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `amount`       | uint256 | <p>amount to be borrowed, expressed in wei units.</p><p>Use <code>uint(-1)</code> to repay the entire debt, <strong>ONLY</strong> when the repayment is not executed on behalf of a 3rd party.</p><p>In case of repayments on behalf of another user, it's recommended to send an <code>\_amount</code> slightly higher than the current borrowed amount.</p> |
| `rateMode`     | uint256 | <p>the type of borrow debt.</p><p>Stable: 1, Variable: 2</p>                                                                                                                                                                                                                                                                                                  |
| `onBehalfOf`   | address | <p>address of user who will incur the debt.</p><p>Use <code>msg.sender</code> when not calling on behalf of a different user.</p>                                                                                                                                                                                                                             |

### borrowET&#x48;**()** <a href="#borroweth" id="borroweth"></a>

**`function borrowETH(uint256 amount, uint256 interestRateMode, uint16 referralCode)`**

Borrows `amount` of WETH with `interestRateMode`, sending the `amount` of unwrapped WETH to `msg.sender`.

| Parameter Name     | Type    | Description                                                                                                              |
| ------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------ |
| `amount`           | uint256 | amount to be borrowed, expressed in wei units                                                                            |
| `interestRateMode` | uint256 | <p>the type of borrow debt.</p><p>Stable: 1, Variable: 2</p>                                                             |
| `referralCode`     | uint16  | referral code for our [referral program](https://docs.aave.com/developers/referral-program). Use 0 for no referral code. |

## View Methods <a href="#view-methods" id="view-methods"></a>

### getWETHAddres&#x73;**()** <a href="#getwethaddress" id="getwethaddress"></a>

**`function getWETHAddress()`**

Returns the WETH address used by the WETHGateway.

### getAWETHAddres&#x73;**()** <a href="#getawethaddress" id="getawethaddress"></a>

**`function getAWETHAddress()`**

Returns the aWETH address used by the WETHGateway.

### getLendingPoolAddres&#x73;**()** <a href="#getlendingpooladdress" id="getlendingpooladdress"></a>

**`function getLendingPoolAddress()`**

Returns the LendingPool address used by the WETHGateway.

​[PreviousIPriceOracle](https://docs.aave.com/developers/the-core-protocol/price-oracle/ipriceoracle)[Next - Protocol GovernanceVoting & Governance](https://docs.aave.com/developers/protocol-governance/governance)![](https://gblobscdn.gitbook.com/users%2FXop8Z8FnbaQwghvBNRtVtt08JKl2%2Favatar-1585133699521.png?alt=media)Last updated 3 days agoWAS THIS PAGE HELPFUL?
