1

I am not pro, but can someone check please why my transaction was cancelled on Ethereum after sending to Swap token on Uniswap v2?

https://etherscan.io/tx/0xbecb8ad0abc8459e378feed4c70740253436ee2d02df86a222e5cfea345c3d1f

Transaction is marked as failed and the only message I see is Warning! Error encountered during contract execution [execution reverted]

If I send eth_getTransactionReceipt RPC, I will not get any message error why it happened. Account has 33.43$. Transaction was about to buy token for 3.59$. Priority fee is more than base.

Full code:

base_fee_per_gas = w3.eth.gas_price   # baseFeePerGas in the latest block (in wei)
max_priority_fee_per_gas = w3.to_wei(1, 'gwei') # Priority fee to include the transaction in the block
max_fee_per_gas = base_fee_per_gas + int(0.5 * base_fee_per_gas) + max_priority_fee_per_gas # Maximum amount you’re willing to pay

buy_tx_params = {
    "nonce": w3.eth.get_transaction_count(account.address),
    "from": account.address,
    "chainId": 1,
    "gas": 500_000, # this I don't know how much to set up
    "maxPriorityFeePerGas": max_priority_fee_per_gas,
    "maxFeePerGas": max_fee_per_gas,
    "value": int(0.001 * 10**18), # 0.001 ETH
}

buy_path = [WETH_TOKEN_ADDRESS, UNISWAP_TOKEN_ADDRESS]

buy_tx = router_contract.functions.swapExactETHForTokens(
    0, # min amount out
    buy_path,
    account.address,
    int(time.time())+180 # deadline now + 180 sec
).build_transaction(buy_tx_params)

signed_buy_tx = w3.eth.account.sign_transaction(buy_tx, account.key)
0

1 Answer 1

4

No pair exists for the tokens in your path, it fails at calling getReserves on the pair, since the function doesn't exist there. You can try a tool like tenderly.co to easily analyse the revert point if verified. The second token being passed is a pair, I imagine the one you want to swap on.

Change this:

buy_path = [WETH_TOKEN_ADDRESS, UNISWAP_TOKEN_ADDRESS]

To:

buy_path = [WETH_TOKEN_ADDRESS, ELON_TOKEN_ADDRESS]

Simulation: enter image description here

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.