0

您好,我正在尝试通过 python web3 出售我的代币。但有时我会收到这样的错误“执行恢复:Pancake:K”。我研究了这个错误,但 pancake swap 告诉我他们网站上的滑点选项。但我想通过 python 出售这个代币如何添加滑点容限?这是我的 pancakeswap 合约:

spend = web3.toChecksumAddress("0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c")
balance = web3.eth.get_balance(sender_address)
humanReadable = web3.fromWei(balance, 'ether')
contract_id = web3.toChecksumAddress(contractaddress)
sellTokenContract = web3.eth.contract(contract_id, abi=sellAbi)
balance = sellTokenContract.functions.balanceOf(sender_address).call()
symbol = sellTokenContract.functions.symbol().call()
readable = web3.fromWei(balance, 'ether')
tokenValue = web3.toWei(readable, 'ether')
tokenValue2 = web3.fromWei(tokenValue, 'ether')
start = time.time()
approve = sellTokenContract.functions.approve(panRouterContractAddress, balance).buildTransaction({
        'from': sender_address,
        'gasPrice': web3.toWei('5', 'gwei'),
        'nonce': web3.eth.get_transaction_count(sender_address),
    })

signed_txn = web3.eth.account.sign_transaction(approve, private_key=config.private)
tx_token = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
print("Approved: " + web3.toHex(tx_token))
time.sleep(3)
print(f"Swapping {tokenValue2} {symbol} for BNB")


pancakeswap2_txn = contract.functions.swapExactTokensForETHSupportingFeeOnTransferTokens(
        tokenValue,0, 
        [contract_id,spend],
        sender_address,
        (int(time.time()) + 10000)
    ).buildTransaction({
        'from': sender_address,
        'gasPrice': web3.toWei(str(gwei), 'gwei'),
        'nonce': web3.eth.get_transaction_count(sender_address),

    })

signed_txn = web3.eth.account.sign_transaction(pancakeswap2_txn, private_key=config.private)
tx_token = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
print(f"Sold {symbol}: " + web3.toHex(tx_token)) 
4

0 回答 0