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

# Sponsor SVM Transactions

> Have Dynamic pay the SOL fee on Solana transactions using gas sponsorship

## Overview

`DynamicSvmWalletClient::sponsorTransaction` is the lower-level primitive behind sponsored transactions. It takes the serialized message of an unsigned transaction and returns the **sponsor-signed wire envelope** — the sponsor's signature is pre-filled in slot 0, the user signature slots are zeroed, and the original message is appended.

Most apps don't need this directly — use [`sendTransaction(...).sponsor(true)`](/java/svm/send-transaction#gas-sponsorship) for the one-shot sign + sponsor + broadcast flow. Reach for `sponsorTransaction` when you want to:

* Have the user sign the sponsor-prepped envelope on a separate path (client-side wallet, hardware wallet)
* Inspect or audit the sponsor signature before adding the user signature
* Batch sponsorship outside Dynamic's broadcast path

<Note>
  Gas sponsorship must be enabled for your environment in the Dynamic dashboard before calls succeed.
</Note>

## Prerequisites

* [Created an SVM wallet](/java/svm/create-wallet)
* Gas sponsorship enabled in the Dashboard

## Sponsor a Message

```java theme={"system"}
byte[] messageBytes  = /* bytes(transaction.message) */;
byte[] sponsoredWire = client.sponsorTransaction(messageBytes).join();
```

`sponsoredWire` layout:

```
[compact-u16 sigCount][sigCount × 64-byte slots, sponsor pre-filled, user zeroed][sponsored message]
```

The sponsor signature occupies slot 0; every other signature slot is zeroed and waiting for the corresponding signer.

## Filling in the User Signature

If your wallet's account index is `idx` (typically `1` for a single user signer after the sponsor), overwrite that 64-byte slot with the user's Ed25519 signature, then push to RPC:

```java theme={"system"}
import org.web3j.utils.Numeric;

byte[] sigBytes = Numeric.hexStringToByteArray("0x" + userSignatureHex);  // 64 bytes
System.arraycopy(sigBytes, 0, sponsoredWire, /* offset of slot idx */, 64);

// Push to any Solana RPC
solanaRpc.sendRawTransaction(sponsoredWire);
```

To compute the offset of slot `idx`:

```
offset = compactU16Length(sigCount) + idx * 64
```

## Pairing with the MPC Signer

The most common pattern: sponsor first (no MPC needed), then run [`signTransaction`](/java/svm/sign-transaction) over the same `messageBytes` to get the user's Ed25519 signature, then splice it into the sponsored envelope:

```java theme={"system"}
byte[] sponsoredWire = client.sponsorTransaction(messageBytes).join();

String userSigHex = client.signTransaction(SignTransactionOpts.builder()
    .messageBytes(messageBytes)
    .walletProperties(walletProperties)
    .externalServerKeyShares(externalServerKeyShares)
    .build()
).join();

byte[] userSig = Numeric.hexStringToByteArray("0x" + userSigHex);
System.arraycopy(userSig, 0, sponsoredWire, userSigOffset, 64);

// Broadcast sponsoredWire via your preferred Solana RPC client.
```

For the streamlined version of this — sponsor + sign + broadcast in a single SDK call — see [`sendTransaction` with `sponsor=true`](/java/svm/send-transaction#gas-sponsorship).

## Next Steps

* [Send transactions](/java/svm/send-transaction) — sign + sponsor + broadcast in one call
* [Sign transactions](/java/svm/sign-transaction)
* [Sign messages](/java/svm/sign-messages)
* [Delegated access](/java/svm/delegated-access)
