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

Viewed 11222

i'm traying to swap some DAI for ETH on the Ropsten Network using the UniswapV2Router02 on Etherscan (Ropsten Test Network).

DAI Address on Ropsten = 0xad6d458402f60fd3bd25163575031acdce07538d WETH = 0xc778417E063141139Fce010982780140Aa0cD5Ab

in my Wallet i have 2000 DAI (Ropsten)

but when i put the data there. like this: enter image description here

Metamask shows that there is an Error thrown by the Contract. So i might be missing something or am'i doing it wrong.

enter image description here

can please someone help and show me how can i make a successful transaction there ?

1 Answers

i got this to work. if someone is interested to know how, here is what i have done.

1- amountIn should be in 10^18, that means 100 was wrong, it should be 100x10^18 = 100000000000000000000

2- first i had to approve the UniswapRouterAddress to spend this 100 DAI. so on the DAI contract Address i had to put the data like this:

enter image description here

after that i was able t swap the 100 DAI for ETH (as much as 100 DAI is worth of ETH)

Related