# alchemy_requestFeePayer

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://solana-mainnet.g.alchemy.com/v2/{apiKey}

Requests fee sponsorship for a Solana transaction and returns the updated `serializedTransaction` with the paymaster fee payer set and signed.

<Note>
  On every sponsored request, any top-level `SystemProgram.createAccount` and Associated Token Program `Create`/`CreateIdempotent` instructions are rewritten so the paymaster funds them directly — no opt-in required. For CPI-driven account creation, opt into rent prefunding with `prefundRent: true`; policies using `prefundRent` must set `maxSpendPerTxnUsd`.
</Note>

<Note>
  CPI rent prefunding is allowlisted. Contact [support@alchemy.com](mailto:support@alchemy.com) for access.
</Note>


Reference: https://www.alchemy.com/docs/wallets/api-reference/gas-manager-admin-api/gas-abstraction-api-endpoints/alchemy-request-fee-payer

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| params[0] | object | Yes | Object containing the policy ID, serialized transaction, and optional rent-prefunding settings. |

## Result

**Sponsored transaction wrapper** (object): Object containing the sponsored transaction plus fee and rent estimates. 

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "alchemy_requestFeePayer",
  "params": [
    {
      "policyId": "69d524a7-e932-4214-8673-dcdcba31bb42",
      "serializedTransaction": "AgICAQMEBQYHCAkKCwwNDg8BCg=="
    }
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "serializedTransaction": "AQIDBAUGBwgJCgsMDQ4PEA==",
    "estimatedFeeLamports": 5000,
    "estimatedRentLamports": 890880,
    "usesDurableNonce": false,
    "lastValidBlockHeight": 567890
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://solana-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "alchemy_requestFeePayer",
  "params": [
    {
      "policyId": "69d524a7-e932-4214-8673-dcdcba31bb42",
      "serializedTransaction": "AgICAQMEBQYHCAkKCwwNDg8BCg=="
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'alchemy_requestFeePayer',
    params: [
      {
        policyId: '69d524a7-e932-4214-8673-dcdcba31bb42',
        serializedTransaction: 'AgICAQMEBQYHCAkKCwwNDg8BCg=='
      }
    ]
  })
};

fetch('https://solana-mainnet.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://solana-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "alchemy_requestFeePayer",
    "params": [
        {
            "policyId": "69d524a7-e932-4214-8673-dcdcba31bb42",
            "serializedTransaction": "AgICAQMEBQYHCAkKCwwNDg8BCg=="
        }
    ]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://solana-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"alchemy_requestFeePayer\",\n  \"params\": [\n    {\n      \"policyId\": \"69d524a7-e932-4214-8673-dcdcba31bb42\",\n      \"serializedTransaction\": \"AgICAQMEBQYHCAkKCwwNDg8BCg==\"\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://solana-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"alchemy_requestFeePayer\",\n  \"params\": [\n    {\n      \"policyId\": \"69d524a7-e932-4214-8673-dcdcba31bb42\",\n      \"serializedTransaction\": \"AgICAQMEBQYHCAkKCwwNDg8BCg==\"\n    }\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://solana-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"alchemy_requestFeePayer\",\n  \"params\": [\n    {\n      \"policyId\": \"69d524a7-e932-4214-8673-dcdcba31bb42\",\n      \"serializedTransaction\": \"AgICAQMEBQYHCAkKCwwNDg8BCg==\"\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: alchemy_requestFeePayer
description: |
  Requests fee sponsorship for a Solana transaction and returns the updated `serializedTransaction` with the paymaster fee payer set and signed.

  <Note>
    On every sponsored request, any top-level `SystemProgram.createAccount` and Associated Token Program `Create`/`CreateIdempotent` instructions are rewritten so the paymaster funds them directly — no opt-in required. For CPI-driven account creation, opt into rent prefunding with `prefundRent: true`; policies using `prefundRent` must set `maxSpendPerTxnUsd`.
  </Note>

  <Note>
    CPI rent prefunding is allowlisted. Contact [support@alchemy.com](mailto:support@alchemy.com) for access.
  </Note>
params:
  - name: params[0]
    required: true
    description: Object containing the policy ID, serialized transaction, and optional rent-prefunding settings.
    schema:
      type: object
      required:
        - policyId
        - serializedTransaction
      properties:
        policyId:
          description: The Gas Manager Policy ID or list of Gas Manager Policy IDs.
          oneOf:
            - title: policyId
              type: string
              format: uuid
            - title: policyIdArray
              type: array
              items:
                type: string
                format: uuid
        serializedTransaction:
          type: string
          pattern: ^[A-Za-z0-9+/]+={0,2}$
          description: |
            The serialized transaction produced by `tx.serialize()`. The service replaces the existing `feePayer` with the sponsoring account and adds the fee-payer signature. For default requests, `payerKey` can be any placeholder address. For requests with `prefundRent: true`, `payerKey` MUST be the user's wallet — the same account the program's CPI will debit for rent — because prefunding targets that position.
        webhookData:
          type: string
          description: Optional metadata forwarded to your policy webhook.
        prefundRent:
          type: boolean
          default: false
          description: |
            Opts into cross-program invocation (CPI) rent prefunding. Use this when the transaction creates accounts through CPI and the user's wallet needs SOL prefunded first. Requires two things: (1) the policy must set `maxSpendPerTxnUsd`, and (2) the transaction's `payerKey` MUST be the user's wallet (the account the CPI debits for rent). Prefunding targets `payerKey` by position, so a placeholder `payerKey` silently misses and the transaction fails on-chain for lack of rent.
result:
  name: Sponsored transaction wrapper
  description: |
    Object containing the sponsored transaction plus fee and rent estimates.
  schema:
    type: object
    required:
      - serializedTransaction
      - estimatedFeeLamports
      - estimatedRentLamports
      - usesDurableNonce
    properties:
      serializedTransaction:
        title: base-64-encoded Solana transaction
        type: string
        description: |
          The transaction after the service sets the `feePayer` field and adds the fee-payer signature.
      estimatedFeeLamports:
        type: integer
        description: Estimated network fee in lamports for the returned transaction.
      estimatedRentLamports:
        type: integer
        description: Estimated rent in lamports covered by sponsorship.
      prefundLamports:
        type: integer
        description: |
          Lamports transferred to the transaction's `payerKey` to cover CPI-driven account creation rent. Omitted when no prefund simulation ran — i.e., `prefundRent` was not requested, or it was requested but the fee payer was replaced rather than injected so there was no user wallet to top up.
      simulationSlot:
        type: integer
        description: |
          Slot used for rent-prefunding simulation. Omitted when no prefund simulation ran. When present, pass it as `minContextSlot` when submitting the transaction to reduce stale-state risk. Simulation is only an estimate: onchain state or CPI behavior can change before execution, so prefunding may still end up too low or higher than what is ultimately consumed.
      usesDurableNonce:
        type: boolean
        description: Whether the returned transaction uses a durable nonce.
      lastValidBlockHeight:
        type: integer
        description: |
          Expiry hint for recent-blockhash transactions. Omitted for durable nonce transactions.
servers:
  - url: https://solana-mainnet.g.alchemy.com/v2
    name: Solana Mainnet
  - url: https://solana-devnet.g.alchemy.com/v2
    name: Solana Devnet
examples:
  - name: Default request
    params:
      - name: params[0]
        value:
          policyId: 69d524a7-e932-4214-8673-dcdcba31bb42
          serializedTransaction: AgICAQMEBQYHCAkKCwwNDg8BCg==
    result:
      name: Sponsored transaction wrapper
      value:
        serializedTransaction: AQIDBAUGBwgJCgsMDQ4PEA==
        estimatedFeeLamports: 5000
        estimatedRentLamports: 890880
        usesDurableNonce: false
        lastValidBlockHeight: 567890
  - name: With CPI rent prefunding
    params:
      - name: params[0]
        value:
          policyId: 69d524a7-e932-4214-8673-dcdcba31bb42
          serializedTransaction: AgICAQMEBQYHCAkKCwwNDg8BCg==
          prefundRent: true
    result:
      name: Sponsored transaction wrapper
      value:
        serializedTransaction: AQIDBAUGBwgJCgsMDQ4PEA==
        estimatedFeeLamports: 5000
        estimatedRentLamports: 890880
        prefundLamports: 890880
        simulationSlot: 456789
        usesDurableNonce: false
        lastValidBlockHeight: 567890
```
