ETH – How to Wrap ETH into WETH via ethers.js or web3.js

etherethers.jsuniswapuniswapv3wrapped-tokens

what function in a smart contract is responsible for this?

In the documentation of Uniswap I've found only one reference to what I might be looking — https://docs.uniswap.org/contracts/universal-router/technical-reference#wrap_eth

However, how to used and implement this in ethers or web3.js?

Best Answer

Here's the deposit method:

https://etherscan.io/token/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2#writeContract#F5

After calling deposit method, the caller will received WETH equal to the ETH amount paid to the contract.

As usual, double-check and triple-check the contract is actually authentic.

How to interact with contract in ethers.js or web3.js should already be covered in their documentation.