如何使用UniswapV2交换ETH与WETH ?



我正试图使用UniswapRouterV2和ethers.js将ETH交换为WETH中的等价物,但我不知道在路径数组中放置什么地址作为ETH,因为它没有ETH,所以请让我知道我做错了什么。

await this.uniswapRouter.swapETHForExactTokens(
ethers.provider.getBalance(attacker.addres), // amountOut
[0, this.weth.address], // path: what should it be instead of 0?
attacker.address, // to
(await ethers.provider.getBlock('latest').timestamp) * 2, // deadline
{value: ethers.provider.getBalance(attacker.addres)} // msg.value
)

我明白了。它是如此简单,根本不需要UniswapRouterV2协议。一个人必须执行WETH合同的存款功能,合同就会把ETH还给他。像这样:

await this.weth.connect(attacker).deposit({value: ethToWETHAmount})