Search code examples
transactionsethereumswap

Invalid batchSwap transaction in Arbitrum Mainnet


I tried to simulate batch swap transaction in Arbitrum Mainnet. I want to swap ETH to VST token throw Balancer. I found example of batch swap here (https://github.com/gerrrg/balancer-tutorials/blob/master/python/swaps/batch_swap.py)

So, I prepared the same data from example. Moreover, I have a successfull transaction for example: https://arbiscan.io/tx/0x87b72f870bb23ba0183dbbea2218c9f81e26965f47e98d4a5dff66f04467731f

But I can't send it to RPC endpoint. I got an error every time: ValueError: {'code': 0, 'message': "we can't execute this request"}

This is my code for transaction:

estimate_txn = BALANCER_VAULT_CONTRACT.functions.batchSwap(
    0,
    [
        ("0x64541216bafffeec8ea535bb71fbc927831d0595000100000000000000000002", 0, 1, value_of_eth, eth_abi.encode_abi(['uint256'], [0])),
        ("0x5a5884fc31948d59df2aeccca143de900d49e1a300000000000000000000006f", 1, 2, 0, eth_abi.encode_abi(['uint256'], [0])),
    ],
    [
        w3.toChecksumAddress("0x0000000000000000000000000000000000000000"),
        w3.toChecksumAddress("0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8"),
        w3.toChecksumAddress("0x64343594Ab9b56e99087BfA6F2335Db24c2d1F17"),
    ],
    (w3.toChecksumAddress(your_wallet), False, w3.toChecksumAddress(your_wallet), False),
    [value_of_eth, 0, 0], #Specifying a negative limit of VST doesn't solve the problem
    int(time.time() + 100 * 60)
).buildTransaction({
    "nonce": nonce,
    "from": your_wallet,
    "value": value_of_eth,
    "gasPrice": 100000000, #0.1 Gwei
    "gas": 2000000,
    #"chainId": 42161 #Specifying chainId has no effect
})

What wrong with my code? I tried to use a different RPC nodes.

enter image description here


Solution

  • I spent a lot of time trying to figure out what caused the error. First, the lack of error is due to the response from RPC, you can link to this problem here: https://github.com/ethers-io/ethers.js/issues/2749#issuecomment-1268638214

    I had to change my RPC handpoint, public RPC, such as:

    1. https://arbitrum.public-rpc.com
    2. https://rpc.ankr.com/arbitrum

    RPC doesn't accept this transaction, and doesn't return the error result. I don't know what this has to do with. I changed my RPC to QuickNode and then the transaction was sent to the network and successfully validated.