Skip to main content
This guide builds submitTx, a helper that sends a signed transaction to Stellar RPC and waits for the result. Other guides reuse it.

Send statuses

sendTransaction returns right away with one of four statuses. Only ERROR is a final rejection. For more about these statuses and the errors behind them, see Debugging errors.

Wait for the result

getTransaction returns NOT_FOUND until the transaction is in a ledger. NOT_FOUND does not mean that the transaction failed. The transaction can go into a ledger at any time until its time bound (maxTime) passes. Poll until getTransaction returns SUCCESS or FAILED. If it still returns NOT_FOUND after a ledger closes later than maxTime, the transaction can never go into a ledger. Only then is it safe to build and send a new transaction.
server.pollTransaction() stops after a fixed number of attempts (30 by default) and then returns the last NOT_FOUND response. Do not treat that response as a failure. If you send a new transaction at that point, the network can apply both transactions, and you pay twice.

The submitTx helper

RPC sends latestLedgerCloseTime as a string, so the helper converts it with Number() before it compares it with maxTime.
Remember: You should always handle errors gracefully! This is a fail-hard and fail-fast approach that should only be used in these examples.