如何使用unisWAPV2与Weth交换ETH?
我正在尝试使用uniswaprouterv2和ethers.js在weth中交换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
)
I'm trying to swap ETH for its equivalent in WETH using UniswapRouterV2 and ethers.js but I don't know what address to put in as ETH in the path array since it doesn't have one, so please let me know what I'm doing wrong.
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
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚知道。它是如此简单,根本不需要UnisWapRouterV2合同。必须执行WETH合同的存款职能,并将合同退还ETH。这样的事情:
Just got it. It was so simple and the UniswapRouterV2 contract was not needed at all. One has to execute the deposit function of WETH contract and the contract gives ETH back. Something like this: