0

I've made a python web3 script that swaps ETH to Token using exactInputSingle function on Uniswap v3 Abritrum chain.

Transactions are successful and the script is working, but the problem is, when I reverse the swap (selling tokens to get ETH), I receive wETH instead of ETH. On Uniswap v2, this can be easily be solved by using swapExactTokensForETH, but Uniswap v3 is different.

Here's a sample portion of the txn in my code:

    # Txn Params
    fee = 3000
    min_out = 0
    deadline = int(time()) + 900
    txn_params = (token_address, weth_address, fee, wallet_address, deadline, amount_to_sell, min_out, 0)

    uniswapv3_txn = router.functions.exactInputSingle(txn_params).buildTransaction(
        {
            'from': wallet_address,
            'gas': int(gas_limit),
            'maxFeePerGas': web3.toWei(data_gas_max_fee, 'gwei'),
            'maxPriorityFeePerGas': web3.toWei(gas_max_priority, 'gwei'),
            'nonce': web3.eth.get_transaction_count(wallet_address),
        })

        signed_txn = web3.eth.account.sign_transaction(uniswapv3_txn, private_key=private_key)
        tx_token = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
        receipt = web3.eth.wait_for_transaction_receipt(tx_token, timeout=900)

How would I be able to receive ETH instead of wETH?

1 Answer 1

1

In this context I do not see similar function in UniswapV3 like you have in uniswapV2. But you can create a simple withdraw from weth contract after you have received WETH back.

You have to approve maximum weth to WETH contract and send transaction to withdraw(wethAmount).

  1. wethContractAddress.approve(wethContractAddress, wethAmount)
  2. wethContractAddress.withdraw(amountWeth)
2
  • I have thought of this before. I was just thinking if there was a way to do this in a single transaction (at least to save gas). But I appreciate your input!
    – Austin
    Commented Feb 22, 2023 at 4:56
  • 1
    Yes, there is refundETH(), you can call uniswapv3Router.refundETH(), but not in single transaction.
    – Safi
    Commented Feb 22, 2023 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.