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

# sponsorTransaction

> Sponsors a Solana transaction via the Dynamic gas sponsorship API

## Function Signature

```typescript theme={"system"}
sponsorTransaction(params: {
  transaction: VersionedTransaction | Transaction;
  traceContext?: TraceContext;
}): Promise<VersionedTransaction | Transaction>
```

## Description

Sends an unsigned Solana transaction to Dynamic's gas sponsorship endpoint (`/solana/sponsorTransaction`), which replaces the fee payer with the sponsor's address. The returned transaction has the sponsor as fee payer and should be passed to [`signTransaction()`](/node/reference/svm/sign-transaction) instead of the original.

Gas sponsorship must be enabled for your environment in the Dynamic dashboard before calling this method.

<Note>
  For most use cases, pass `sponsor: true` to [`signTransaction()`](/node/reference/svm/sign-transaction) instead of calling `sponsorTransaction()` directly. Use this method when you need to inspect or modify the sponsored transaction before signing.
</Note>

## Parameters

### Required Parameters

* **`transaction`** (`VersionedTransaction | Transaction`) - The unsigned Solana transaction. Supports both legacy `Transaction` and `VersionedTransaction`.

### Optional Parameters

* **`traceContext`** (`TraceContext`) - Distributed tracing context for observability.

## Returns

**`Promise<VersionedTransaction | Transaction>`** - The sponsored transaction with the gas sponsor set as fee payer. Returns the same transaction type that was passed in.

## Example

```typescript theme={"system"}
import { DynamicSvmWalletClient } from '@dynamic-labs-wallet/node-svm';
import { Connection, Transaction, SystemProgram, PublicKey } from '@solana/web3.js';

const svmClient = await authenticatedSvmClient();
const connection = new Connection(process.env.SOLANA_RPC_URL ?? 'https://api.mainnet-beta.solana.com');

const { blockhash } = await connection.getLatestBlockhash();

const transaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: new PublicKey(walletMetadata.accountAddress),
    toPubkey: new PublicKey(recipientAddress),
    lamports: 1000000,
  })
);
transaction.recentBlockhash = blockhash;
transaction.feePayer = new PublicKey(walletMetadata.accountAddress);

// Sponsor replaces the fee payer
const sponsoredTx = await svmClient.sponsorTransaction({ transaction });

// Inspect or modify the sponsored transaction, then sign
const signatureBase58 = await svmClient.signTransaction({
  walletMetadata,
  externalServerKeyShares,
  transaction: sponsoredTx,
});
```

## Error Handling

The method throws when sponsorship is unavailable or not enabled:

```typescript theme={"system"}
try {
  const sponsoredTx = await svmClient.sponsorTransaction({ transaction });
} catch (error) {
  if (error.message.includes('400')) {
    console.error('Gas sponsorship is not enabled for this environment');
  } else {
    console.error('Sponsorship failed:', error.message);
  }
}
```

## Related

* [`signTransaction()`](/node/reference/svm/sign-transaction) - Sign a transaction (accepts `sponsor: true` for a one-step flow)
* [SVM Gas Sponsorship guide](/node/wallets/server-wallets/gas-sponsorship-svm) - Full guide on SVM gas sponsorship approaches
