如何使用unisWAPV2与Weth交换ETH?

发布于 2025-02-12 01:18:36 字数 465 浏览 0 评论 0原文

我正在尝试使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云之铃。 2025-02-19 01:18:36

刚知道。它是如此简单,根本不需要UnisWapRouterV2合同。必须执行WETH合同的存款职能,并将合同退还ETH。这样的事情:

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

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:

 await this.weth.connect(attacker).deposit({value: ethToWETHAmount})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文