Submit a Signed Solana Transaction Through an RPC Endpoint

Send an already-signed Solana transaction with Node.js, keep the RPC API key out of source code, and handle common submission errors.

To submit a signed Solana transaction, send its serialized bytes to a Solana JSON-RPC endpoint with the sendTransaction method. The endpoint does not sign the transaction for you: your wallet or signing code must produce the signed bytes first. This guide uses Node.js 18+ and environment variables so the endpoint and any API key stay out of the source file.

Prepare the endpoint and signed transaction

Use a Solana RPC endpoint, such as one configured through OnFinality’s Solana network page. Set SOLANA_RPC_URL to the endpoint URL supplied for your account; do not copy an endpoint from an example or commit a credential-bearing URL to your repository.

Set SIGNED_TRANSACTION_BASE64 to the base64-encoded serialized transaction after signing. The transaction must contain a valid recent blockhash and signatures for all required signers. Protect both environment values as secrets.

  • This example submits an existing signed transaction; it does not create or sign one.
  • sendTransaction returns a transaction signature when the RPC accepts the submission. That response alone does not establish that the transaction has been confirmed or finalized.

Send the transaction with Node.js

The example uses Node.js 18+’s built-in fetch. Solana JSON-RPC uses HTTP POST with a JSON-RPC request body. The base64 encoding option tells the RPC how to interpret the transaction bytes.

JavaScript · Node.js
const rpcUrl = process.env.SOLANA_RPC_URL;
const signedTransaction = process.env.SIGNED_TRANSACTION_BASE64;

if (!rpcUrl || !signedTransaction) {
  throw new Error('Set SOLANA_RPC_URL and SIGNED_TRANSACTION_BASE64');
}

const response = await fetch(rpcUrl, {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'sendTransaction',
    params: [signedTransaction, {
      encoding: 'base64',
      preflightCommitment: 'confirmed'
    }]
  })
});

if (!response.ok) {
  throw new Error(`RPC HTTP error: ${response.status} ${response.statusText}`);
}

const result = await response.json();
if (result.error) {
  throw new Error(`RPC error ${result.error.code}: ${result.error.message}`);
}
if (typeof result.result !== 'string') {
  throw new Error('RPC response did not include a transaction signature');
}

console.log(`Submitted transaction: ${result.result}`);

Run it with SOLANA_RPC_URL and SIGNED_TRANSACTION_BASE64 set in your environment. A successful response prints Submitted transaction: <signature>, where the signature comes from the RPC response; no particular signature is assumed here.

The script stops on HTTP errors, JSON-RPC errors, missing configuration, and responses without a signature. Avoid printing the RPC URL or the signed transaction in application logs.

Handle submission failures and check status

An RPC error can indicate a malformed transaction, an invalid signature, simulation failure, or an expired recent blockhash. Check the error message and transaction construction; if the blockhash has expired, obtain a fresh one, rebuild and sign the transaction, then submit the new bytes. Do not assume that retrying the same expired transaction will fix it.

After receiving a signature, use getSignatureStatuses or an appropriate Solana client to check its status. A signature returned by sendTransaction means the RPC accepted the request for submission, not that the cluster confirmed it.

bash
curl --fail-with-body -sS "$SOLANA_RPC_URL" \
  -H 'content-type: application/json' \
  --data '{"jsonrpc":"2.0","id":1,"method":"getSignatureStatuses","params":[["TRANSACTION_SIGNATURE"],{"searchTransactionHistory":true}]}'

Replace TRANSACTION_SIGNATURE with the signature returned by submission. Inspect the response’s value entry: null means no status was found in the queried history, while a status object includes confirmation information and may include an execution error.

Choose RPC or indexed data access

RPC is the direct interface for submitting transactions and making node queries. Indexing and querying are separate tasks: an indexer processes chain data into a queryable store, which can help with application-specific historical or aggregate queries. Sending a signed transaction does not require an indexer.

For additional Solana development material, see OnFinality Learn or use the RPC Assistant to explore RPC-related guidance.