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

# Sponsor your users' gas

> Pay the transaction fee and account rent for your users' rfq-fill trades from your own wallet, so they need no SOL.

> [!WARNING]
>
> This feature is in private alpha and the details are subject to change!

You can pay the gas for your users' trades from a wallet you control. Your wallet, the sponsor, pays the transaction fee and the account rent. Your user's wallet needs no SOL.

This works only on the `rfq-fill` route, for tokenized stocks against USDC on Solana. See [RFQ orders](https://docs.sunrise.xyz/recipes/rfq-orders.md) for how that route works.

This recipe builds on the [swap recipe](https://docs.sunrise.xyz/recipes/swap.md) and the [RFQ orders recipe](https://docs.sunrise.xyz/recipes/rfq-orders.md). It uses the same `headers`, `wallet`, `account`, and signing code.

## How it works

* Your server sends `feePayerAddress` with `POST /v1/quotes`. The quote's transaction then names the sponsor as its fee payer.
* Your server signs the quote's transaction with the sponsor first. Then your user signs it.
* You send the transaction with both signatures to `POST /v1/execute`.
* The order's rent returns to the sponsor when the order closes.

> [!WARNING]
>
> **Never sign a transaction that your user or your app sends to your server.** The sponsor signs only the `unsignedTransaction` from the quote that your server got itself. A sponsor signature on any other transaction can spend the sponsor's SOL.

## Step 1: Get a quote with a sponsor

On your server, add `feePayerAddress` to the quote request from [RFQ orders](https://docs.sunrise.xyz/recipes/rfq-orders.md#step-2-get-a-quote):

```typescript theme={null}
const SPONSOR_WALLET = "<your-sponsor-wallet>";

const quoteResponse = await fetch("https://api.sunrise.xyz/v1/quotes", {
  method: "POST",
  headers,
  body: JSON.stringify({
    fromToken: USDC_MINT,
    toToken: stock.address,
    fromAmount: "100000000", // 100 USDC
    fromAddress: account.address,
    toAddress: account.address,
    feePayerAddress: SPONSOR_WALLET,
  }),
});

const quoteResult = await quoteResponse.json();

if (!quoteResponse.ok || !quoteResult.success) {
  throw new Error(quoteResult.error?.message ?? "Could not get a quote");
}

const quote = quoteResult.data.quotes.find((q) => q.routeName === "rfq-fill");
```

| Field | What it holds |
| - | - |
| `feePayerAddress` | The Solana wallet that pays the transaction fee and account rent. It needs `fromAddress` in the same request. |

A request with a sponsor gets quotes only from `rfq-fill`. Other routes can't use a separate fee payer, so they're skipped and listed in `unavailableRoutes` with the code `fee_payer_not_supported`. If `rfq-fill` gives no quote, `unavailableRoutes` says why.

A `feePayerAddress` equal to `fromAddress` has no effect. Your user pays their own gas, as on a request without it.

The sponsor wallet needs enough SOL for the transaction fee and the rent of the order's accounts. Sunrise screens the sponsor wallet the same way as your user's wallet, on the quote and on execute.

## Step 2: The sponsor signs

On your server, sign the quote's `unsignedTransaction` with the sponsor. Keep the sponsor's key on your server, not in your app. Check that the sponsor is the transaction's fee payer, the first signer, before you sign.

```typescript theme={null}
import {
  getBase64EncodedWireTransaction,
  getBase64Encoder,
  getTransactionDecoder,
  partiallySignTransaction,
} from "@solana/kit";

// sponsor is a KeyPairSigner for SPONSOR_WALLET, loaded on your server.
// quote is the rfq-fill quote from step 1, never a transaction from your app.
const transaction = getTransactionDecoder().decode(
  getBase64Encoder().encode(quote.unsignedTransaction),
);

const [feePayer] = Object.keys(transaction.signatures);

if (feePayer !== sponsor.address) {
  throw new Error("This quote does not name the sponsor as its fee payer");
}

const sponsored = await partiallySignTransaction([sponsor.keyPair], transaction);
const sponsoredTransaction = getBase64EncodedWireTransaction(sponsored);
```

The sponsor signs the transaction exactly as quoted, with the quote's priority fee. The transaction can't land without the solver's signature, which Sunrise adds only through `POST /v1/execute`. Thus, the sponsor's signature is good only for this order.

## Step 3: Your user signs

Send `sponsoredTransaction` to your app. Ask your user's wallet to sign it, as in [step 3 of RFQ orders](https://docs.sunrise.xyz/recipes/rfq-orders.md#step-3-sign-the-quote). The wallet adds your user's signature next to the sponsor's.

If the wallet changes the transaction when it signs, for example its priority fee, the sponsor's signature no longer matches and the order fails to land. Get a new quote, and sign it with a wallet that signs the transaction unchanged.

## Step 4: Execute

Call `POST /v1/execute` with the transaction that both wallets signed, and track the order as in [RFQ orders](https://docs.sunrise.xyz/recipes/rfq-orders.md#step-4-execute-and-track-the-order-status). Nothing else changes for a sponsored quote.

If the sponsor's signature is missing, execute returns `400 invalid_transaction` and sends nothing. The quote stays usable until `expiresAt`. Sign the quote's `unsignedTransaction` with the sponsor and start again from step 2.

## Sponsor errors

| Code | Status | Why | What to do |
| - | - | - | - |
| `invalid_request` | 400 | `details.fields` names `feePayerAddress`. The address isn't a valid Solana wallet, or the request has no `fromAddress`. | Fix the address, or add `fromAddress`. |
| `invalid_transaction` | 400 | The transaction has no signature from the sponsor. | Sign the quote's `unsignedTransaction` with the sponsor, then have your user sign it. |

See [Errors](https://docs.sunrise.xyz/api-reference/errors.md) for every other code.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.