I have been trying to solve this issue for a while now and would really appreciate any help i can get.
i am essentially trying to create a loop that doesnt stop after one succesful tx. End goal is to produce a loop that will run the function which sends a tx to the smart contract. I have the function all sorted and its a simple tx to a smart contract on pancakeswap router.
Ive now tried a While True: loop, as well as the Scheduler but can never get it to run the function more than once, as once the statement is 'True' it simply stops. I just want to send tx every 3 seconds to a smart contract its that simple ahha!!
I would really appreciate any guidance
Thank you!
Example Code:
Pancakeswaptx = contract.functions.swapExactETHForTokens(
0,
[spend,tokentobuy],
my_address,
(int(start)+ 10000)
).buildTransaction({
'from': my_address,
'value': web3.toWei(0.001,'ether'),
'gas': 250000,
'gasPrice': web3.toWei('5','gwei'),
'nonce': web3.eth.get_transaction_count(my_address),
})
def runtx():
signed_tx = web3.eth.account.signTransaction(Pancakeswaptx, privatekey)
transaction = web3.eth.send_raw_transaction(signed_tx.rawTransaction)
print(web3.toHex(transaction))
while True:
time.sleep(1)
runtx()
Note: i get the following error after 1 iteration and succesful tx, both when i use the loop and scheduler:
ValueError: {'code': -32000, 'message': 'already known'}