Error in sending future transactions with Algorand Python SDK

I am trying to send a transaction 20 minutes into the future but I end up with this error

Traceback (most recent call last):
  File "C:\Users\0xEarl\anaconda3\lib\site-packages\algosdk\v2client\algod.py", line 73, in algod_request
    resp = urlopen(req)
  File "C:\Users\0xEarl\anaconda3\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\0xEarl\anaconda3\lib\urllib\request.py", line 531, in open
    response = meth(req, response)
  File "C:\Users\0xEarl\anaconda3\lib\urllib\request.py", line 640, in http_response
    response = self.parent.error(
  File "C:\Users\0xEarl\anaconda3\lib\urllib\request.py", line 569, in error
    return self._call_chain(*args)
  File "C:\Users\0xEarl\anaconda3\lib\urllib\request.py", line 502, in _call_chain
    result = func(*args)
  File "C:\Users\0xEarl\anaconda3\lib\urllib\request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\0xEarl\anaconda3\lib\site-packages\algosdk\v2client\algod.py", line 78, in algod_request
    raise error.AlgodHTTPError(json.loads(e)["message"], code)
algosdk.error.AlgodHTTPError: TransactionPool.Remember: txn dead: round 16527277 outside of 16527542--16528542

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:/Users/0xEarl/Desktop/Learn_Algo/futuretx.py", line 41, in <module>
    txid = algod_client.send_transaction(signed_txn) # send the transaction
  File "C:\Users\0xEarl\anaconda3\lib\site-packages\algosdk\v2client\algod.py", line 195, in send_transaction
    return self.send_raw_transaction(encoding.msgpack_encode(txn),
  File "C:\Users\0xEarl\anaconda3\lib\site-packages\algosdk\v2client\algod.py", line 214, in send_raw_transaction        
    return self.algod_request("POST", req, data=txn, **kwargs)["txId"]
  File "C:\Users\0xEarl\anaconda3\lib\site-packages\algosdk\v2client\algod.py", line 80, in algod_request
    raise error.AlgodHTTPError(e, code)
algosdk.error.AlgodHTTPError: {"message":"TransactionPool.Remember: txn dead: round 16527277 outside of 16527542--16528542"}

I attached the code as a image


ignore the empty variables I removed for safety concerns

Welcome to Algorand!

The node will only accept the transaction when the current round is in the validity window.

You need to have a service/script that waits until the moment the current round passes the first valid round of the transaction, and then only send the transaction.

PS: I’ve edited your post to put the error between triple backquotes ``` which makes it much nicer. Similarly, you should post the code this way instead of an image so that it is searchable and people can more easily copy-paste it to help you.

1 Like

Hello @fabrice i have attached the code for your review, thanks.

import json
from algosdk.v2client import algod
from algosdk import transaction

algod_address = "https://mainnet-algorand.api.purestake.io/ps2" # network address
algod_token = "🔑" # api key
headers = {
    "X-API-Key": algod_token,
}

# initiate a new client with the given parameters
algod_client = algod.AlgodClient(algod_token, algod_address, headers)

params = algod_client.suggested_params()
params.flat_fee = True
params.fee = 1000
fee = params.fee
gh = params.gh

# check node status
status = algod_client.status()
# to read json data
node_stat = json.dumps(status, indent=4)
node_stat = json.loads(node_stat)

current_round = int(node_stat["last-round"])
avg_block_time = 4.5
target_submission_time_in_seconds = 1200
avg_number_of_block_produced_within_time = int(target_submission_time_in_seconds/avg_block_time)
first_round = int(current_round + avg_number_of_block_produced_within_time)
last_round = int(first_round + 1000)

sender = 'I76WK5LC6JDKOIQ4AZ2BKGENET37AUR57V4NRKKDY3UARDTJ534LGPPVCE'
sender_key = '🔑'
reciever = '7WEP4COP42SO6XPCIUIEXYPBYWL2K3QNEV73FPNSU5WC26JYTXMNSC6QJI'
amount = 100000

payit = transaction.PaymentTxn(sender, fee, first_round, last_round, gh, reciever, amount)
signed_txn = payit.sign(sender_key)
# submit the transaction
txid = algod_client.send_transaction(signed_txn) # send the transaction
print(f"Successfully sent transaction with txID: {txid}") # prints the transaction id


In this specific case, the issue is that

1 Like

Hello Fabrice, i have fixed the issue thanks

Hello Obi, Can you please share the code with the solution. Thank you


"""SENDING FUTURE TRANSACTIONS"""
# import tools we need
from algosdk.future.transaction import PaymentTxn
from algosdk.v2client import algod

algod_address = "https://testnet-algorand.api.purestake.io/ps2" # network address
algod_token = "🔑" # api key
headers = {
    "X-API-Key": algod_token,
}

# initiate a new client with the given parameters
algod_client = algod.AlgodClient(algod_token, algod_address, headers)

params = algod_client.suggested_params()
status = algod_client.status()
print(status['last-round'])
current_round = status['last-round']
avg_blocktime = 4.35
avg_no_of_blocks = 200/4.35
first_valid_round = int(current_round + avg_no_of_blocks)
last_valid_round = int(first_valid_round + 1000)
params.flat_fee = True
params.fee = 1000
params.first = first_valid_round
params.last =last_valid_round

sender = 'I76WK5LC6JDKOIQ4AZ2BKGENET37AUR57V4NRKKDY3UARDTJ534LGPPVCE'
sender_key = '🔑'
receiver = '7WEP4COP42SO6XPCIUIEXYPBYWL2K3QNEV73FPNSU5WC26JYTXMNSC6QJI'
amount = 20000000

while 1 > 0:
    status = algod_client.status()
    current_round = int(status['last-round'])
    print('yep')
    if current_round > first_valid_round:
        print('swear word')
        payit = PaymentTxn(sender, params, receiver, amount)
        signed_txn = payit.sign(sender_key)
        # submit the transaction
        txid = algod_client.send_transaction(signed_txn) # send the transaction
        print(f"Successfully sent transaction with txID: {txid}") # prints the transaction id
        break