How to withdraw the WETH from the contract

go-ethereumsolidity

I deployed this contract.

https://github.com/flashbots/simple-arbitrage/blob/master/contracts/BundleExecutor.sol

And I transferred WETH to this contract.

How can I withdraw the WETH from this contract?

In the first place, was it not necessary to send WETH to this contract?

Best Answer

You need to keep WETH in the contract I believe to make the swaps.

To withdraw, you can call the call(_to, _value, _data) function with:

  • _to = WETH_ADDRESS
  • _value = 0
  • _data:
_data = ethers.utils.hexConcat([
    '0xa9059cbb',  // selector of transfer(address,uint256)
    ethers.utils.defaultAbiCoder.encode(
        ['address', 'uint256'],
        [MY_ADDRESS, WETH_AMOUNT_IN_WEI]
    )
])

with MY_ADDRESS your wallet address, and WETH_AMOUNT_IN_WEI the amount in the contract you want to withdraw.

Basically with this method your contract will call WETH to make a transfer to your wallet.

Related Topic