From 5d20283adfbd3a26daa2c269a79151e4ab1dbc3e Mon Sep 17 00:00:00 2001 From: riccardo <106812074+riccardo-gnosis@users.noreply.github.com> Date: Mon, 9 Sep 2024 17:02:18 +0200 Subject: [PATCH] update: fetch nonce before sending txn and use nonce in txn to avoid situation where nonce is not up to speed --- api/api/services/transaction.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/api/api/services/transaction.py b/api/api/services/transaction.py index d5c1f04..794ebfa 100644 --- a/api/api/services/transaction.py +++ b/api/api/services/transaction.py @@ -28,12 +28,26 @@ def claim_native(w3, sender, recipient, amount): - recipient: String - amount: integer in wei format """ + + nonce = w3.eth.get_transaction_count(sender) + tx_dict = { 'from': sender, 'to': recipient, - 'value': amount + 'value': amount, + 'nonce': nonce } - return w3.eth.send_transaction(tx_dict).hex() + + tx_hash = w3.eth.send_transaction(tx_dict).hex() + + # this may cause a timeout, keep here for testing purposes + # receipt = w3.eth.wait_for_transaction_receipt(tx_hash) + # if receipt.status == 1: + # print(f"transaction successful {tx_hash}") + # else: + # print(f"transaction failed {tx_hash}") + + return tx_hash def claim_token(w3, sender, recipient, amount, token_address):