> ## Documentation Index
> Fetch the complete documentation index at: https://developers.stellar.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Submit a transaction to Stellar RPC using the JavaScript SDK

> Use a looping mechanism to submit a transaction to the RPC.

Here is a simple, rudimentary looping mechanism to submit a transaction to Stellar RPC and wait for a result.

```typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
import { Transaction, FeeBumpTransaction } from "@stellar/stellar-sdk";
import { Server, Api } from "@stellar/stellar-sdk/rpc";

const RPC_SERVER = "https://soroban-testnet.stellar.org/";
const server = new Server(RPC_SERVER);

// Submits a tx and then polls for its status until a timeout is reached.
async function submitTx(
  tx: Transaction | FeeBumpTransaction,
): Promise<Api.GetTransactionResponse> {
  return server
    .sendTransaction(tx)
    .then(async (reply) => {
      if (reply.status !== "PENDING") {
        throw reply;
      }

      return server.pollTransaction(reply.hash, {
        sleepStrategy: (_iter: number) => 500,
        attempts: 5,
      });
    })
    .then((finalStatus) => {
      switch (finalStatus.status) {
        case Api.GetTransactionStatus.FAILED:
        case Api.GetTransactionStatus.NOT_FOUND:
          throw tmpStatus;
        case Api.GetTransactionStatus.SUCCESS:
          return status;
      }
    });
}
```

> [!WARNING]
>
> Remember: You should always handle errors gracefully! This is a fail-hard and fail-fast approach that should only be used in these examples.
