简体   繁体   English

如何使用 UniswapV2Router02 合约用 swapExactTokensForETH() 将 Token 换成 ETH

[英]how to swap Token for ETH with swapExactTokensForETH() using UniswapV2Router02 Contract

i'm traying to swap some DAI for ETH on the Ropsten Network using the UniswapV2Router02 on Etherscan (Ropsten Test Network).我正在尝试使用 Etherscan(Ropsten 测试网络)上的 UniswapV2Router02 将 Ropsten 网络上的一些 DAI 换成 ETH。

DAI Address on Ropsten = 0xad6d458402f60fd3bd25163575031acdce07538d WETH = 0xc778417E063141139Fce010982780140Aa0cD5Ab Ropsten 上的 DAI 地址 = 0xad6d458402f60fd3bd25163575031acdce07538d WETH = 0xc778417E063141139Fce010982780140Aa0cD5Ab

in my Wallet i have 2000 DAI (Ropsten)在我的钱包里我有 2000 DAI (Ropsten)

but when i put the data there.但是当我把数据放在那里时。 like this:像这样: 在此处输入图像描述

Metamask shows that there is an Error thrown by the Contract. Metamask 显示合约抛出了一个错误。 So i might be missing something or am'i doing it wrong.所以我可能会遗漏一些东西或者我做错了。

在此处输入图像描述

can please someone help and show me how can i make a successful transaction there?可以请人帮忙并告诉我如何在那里进行成功的交易吗?

i got this to work.我得到了这个工作。 i someone is interested on the solution, here is what i have done.我有人对解决方案感兴趣,这就是我所做的。

1- amountIn should be in 10^18, that means 100 was wrond, it should be 100x10^18 = 100 000000000000000000 1- amountIn应该是 10^18,这意味着 100 是错误的,它应该是 100x10^18 = 100 000000000000000000

2- i had to approve the UniswapRouterAddress to spend this 100 DAI. 2- 我必须批准 UniswapRouterAddress 才能花费这 100 DAI。 so on the DAI contract Address i had to put the data like this:所以在 DAI 合约地址上,我不得不像这样放置数据:

在此处输入图像描述

after that i was able t swipe the 100 DAI for ETH (as much as 100 DAI is worth of ETH)在那之后,我无法刷 100 DAI 换取 ETH(相当于 100 DAI 相当于 ETH)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM