Web3.py uniswap 的状态是 :0 with swapExactTokensForTokens

问题描述 投票:0回答:1

我一直在 python3 上用 python web3.py 测试交换功能。 但它在收到时只有状态:0。 我尝试使用 getAmountsOut 函数中的 amountin 和 amountout,但它们是一样的。

approve = tokenContract.functions.approve(ROUTER_ADDRESS, am).buildTransaction({
        'from': SENDER_ADDRESS,
        # 'gas' : 250000,
        'gasPrice': web3.toWei('40', 'gwei'),
        'nonce': web3.eth.getTransactionCount(SENDER_ADDRESS),
        # 'value':0
    })

    signed_txn = web3.eth.account.sign_transaction(
        approve, private_key=PRIVATE_KEY)
    tx_token = web3.eth.sendRawTransaction(signed_txn.rawTransaction)

    print("approved : " + web3.toHex(tx_token))

    receipt = web3.eth.waitForTransactionReceipt(
        tx_token, timeout=30000, poll_latency=0.1)
    
    amount = routerContract.functions.getAmountsOut(am,[TOKEN_ADDRESS,TARGET_ADDRESS]).call()
    print(amount)

    swap = routerContract.functions.swapExactTokensForTokens(
        web3.toWei('0.0001', 'ether'),#am,
        0,
        [TOKEN_ADDRESS,TARGET_ADDRESS],
        SENDER_ADDRESS,
        (int(time.time()) + 1000000)
    ).buildTransaction({
        'from': SENDER_ADDRESS,
        # 'value': web3.toWei('0.0001','ether'),
        'gas': 250000 ,
        'gasPrice': web3.toWei('60', 'gwei'),
        'nonce':  web3.eth.getTransactionCount(SENDER_ADDRESS),
    })

    signed_txn = web3.eth.account.sign_transaction(
        swap, private_key=PRIVATE_KEY)
    tx_swap = web3.eth.sendRawTransaction(signed_txn.rawTransaction)

    print(web3.toHex(tx_swap))

    print("Wait...")
    time.sleep(5)
    receipt = web3.eth.waitForTransactionReceipt(
        tx_swap, timeout=30000, poll_latency=0.1)
    print(receipt)```

This is transaction link from my swap testing : https://etherscan.io/tx/0x995ca7515fa7e2afe429cf248d772121aaeb456088b2fd674dd30b5816a2a33b
Thanks.
python swap web3py uniswap
1个回答
0
投票

目前尚不清楚您在代码中批准的

am
的价值是多少,但从我在 Etherscan 上的活动中可以看出,您:

  1. 批准POM 414998989012 wei
  2. 尝试交换POM的100000000000000 wei

您需要将您的津贴增加到大于您交换的金额。

© www.soinside.com 2019 - 2024. All rights reserved.