# alchemy_requestPaymasterAndData

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

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

Requests gas coverage for a `UserOperation`.

<Warning title="To be deprecated">
  Please use `alchemy_requestGasAndPaymasterAndData` instead.

  While you can use `alchemy_requestPaymasterAndData` to request a paymaster signature, it's important to note that this function requires gas fields to be part of the `UserOperation` passed as a parameter. These gas fields are influenced by the response of this endpoint, creating a circular dependency.

  To simplify this process, we introduced alchemy_requestGasAndPaymasterAndData. This function both estimates gas and provides signed `paymaster` and `paymasterData` fields, therefore resolving the circular dependency.
</Warning>


Reference: https://www.alchemy.com/docs/wallets/api-reference/gas-manager-admin-api/gas-abstraction-api-endpoints/alchemy-request-paymaster-and-data

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| params[0] | object | Yes | Object containing the sponsorship request parameters. |

## Result

**Response** (object): The response depends on the EntryPoint version used in the request.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "alchemy_requestPaymasterAndData",
  "params": [
    {
      "webhookData": "example webhook data",
      "policyId": "69d524a7-e932-4214-8673-dcdcba31bb42",
      "entryPoint": "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
      "userOperation": {
        "sender": "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd",
        "nonce": "0x2",
        "callData": "0xdeadbeef",
        "callGasLimit": "0x5208",
        "verificationGasLimit": "0x5208",
        "preVerificationGas": "0x5208",
        "maxFeePerGas": "0x1",
        "maxPriorityFeePerGas": "0x1"
      }
    }
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "paymaster": "0x4685d4c74BaC297e23D5C7D1a2bFc1b4581e6704",
    "paymasterData": "0x00000067890abcdef1234567890abcdef1234567890abcdef",
    "paymasterVerificationGasLimit": "0x5208",
    "paymasterPostOpGasLimit": "0x5208"
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://eth-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "alchemy_requestPaymasterAndData",
  "params": [
    {
      "policyId": "string",
      "erc20Context": {
        "tokenAddress": "string",
        "maxTokenAmount": 1,
        "permit": "string"
      },
      "entryPoint": "string",
      "userOperation": {
        "sender": "string",
        "nonce": "string",
        "initCode": "string",
        "callData": "string",
        "callGasLimit": "string",
        "verificationGasLimit": "string",
        "preVerificationGas": "string",
        "maxFeePerGas": "string",
        "maxPriorityFeePerGas": "string",
        "eip7702Auth": {
          "chain_id": "string",
          "address": "string",
          "nonce": "string",
          "y_parity": "string",
          "r": "string",
          "s": "string"
        }
      },
      "webhookData": "string"
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'alchemy_requestPaymasterAndData',
    params: [
      {
        policyId: 'string',
        erc20Context: {tokenAddress: 'string', maxTokenAmount: 1, permit: 'string'},
        entryPoint: 'string',
        userOperation: {
          sender: 'string',
          nonce: 'string',
          initCode: 'string',
          callData: 'string',
          callGasLimit: 'string',
          verificationGasLimit: 'string',
          preVerificationGas: 'string',
          maxFeePerGas: 'string',
          maxPriorityFeePerGas: 'string',
          eip7702Auth: {
            chain_id: 'string',
            address: 'string',
            nonce: 'string',
            y_parity: 'string',
            r: 'string',
            s: 'string'
          }
        },
        webhookData: 'string'
      }
    ]
  })
};

fetch('https://eth-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://eth-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "alchemy_requestPaymasterAndData",
    "params": [
        {
            "policyId": "string",
            "erc20Context": {
                "tokenAddress": "string",
                "maxTokenAmount": 1,
                "permit": "string"
            },
            "entryPoint": "string",
            "userOperation": {
                "sender": "string",
                "nonce": "string",
                "initCode": "string",
                "callData": "string",
                "callGasLimit": "string",
                "verificationGasLimit": "string",
                "preVerificationGas": "string",
                "maxFeePerGas": "string",
                "maxPriorityFeePerGas": "string",
                "eip7702Auth": {
                    "chain_id": "string",
                    "address": "string",
                    "nonce": "string",
                    "y_parity": "string",
                    "r": "string",
                    "s": "string"
                }
            },
            "webhookData": "string"
        }
    ]
}
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://eth-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"alchemy_requestPaymasterAndData\",\n  \"params\": [\n    {\n      \"policyId\": \"string\",\n      \"erc20Context\": {\n        \"tokenAddress\": \"string\",\n        \"maxTokenAmount\": 1,\n        \"permit\": \"string\"\n      },\n      \"entryPoint\": \"string\",\n      \"userOperation\": {\n        \"sender\": \"string\",\n        \"nonce\": \"string\",\n        \"initCode\": \"string\",\n        \"callData\": \"string\",\n        \"callGasLimit\": \"string\",\n        \"verificationGasLimit\": \"string\",\n        \"preVerificationGas\": \"string\",\n        \"maxFeePerGas\": \"string\",\n        \"maxPriorityFeePerGas\": \"string\",\n        \"eip7702Auth\": {\n          \"chain_id\": \"string\",\n          \"address\": \"string\",\n          \"nonce\": \"string\",\n          \"y_parity\": \"string\",\n          \"r\": \"string\",\n          \"s\": \"string\"\n        }\n      },\n      \"webhookData\": \"string\"\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://eth-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"alchemy_requestPaymasterAndData\",\n  \"params\": [\n    {\n      \"policyId\": \"string\",\n      \"erc20Context\": {\n        \"tokenAddress\": \"string\",\n        \"maxTokenAmount\": 1,\n        \"permit\": \"string\"\n      },\n      \"entryPoint\": \"string\",\n      \"userOperation\": {\n        \"sender\": \"string\",\n        \"nonce\": \"string\",\n        \"initCode\": \"string\",\n        \"callData\": \"string\",\n        \"callGasLimit\": \"string\",\n        \"verificationGasLimit\": \"string\",\n        \"preVerificationGas\": \"string\",\n        \"maxFeePerGas\": \"string\",\n        \"maxPriorityFeePerGas\": \"string\",\n        \"eip7702Auth\": {\n          \"chain_id\": \"string\",\n          \"address\": \"string\",\n          \"nonce\": \"string\",\n          \"y_parity\": \"string\",\n          \"r\": \"string\",\n          \"s\": \"string\"\n        }\n      },\n      \"webhookData\": \"string\"\n    }\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://eth-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_requestPaymasterAndData\",\n  \"params\": [\n    {\n      \"policyId\": \"string\",\n      \"erc20Context\": {\n        \"tokenAddress\": \"string\",\n        \"maxTokenAmount\": 1,\n        \"permit\": \"string\"\n      },\n      \"entryPoint\": \"string\",\n      \"userOperation\": {\n        \"sender\": \"string\",\n        \"nonce\": \"string\",\n        \"initCode\": \"string\",\n        \"callData\": \"string\",\n        \"callGasLimit\": \"string\",\n        \"verificationGasLimit\": \"string\",\n        \"preVerificationGas\": \"string\",\n        \"maxFeePerGas\": \"string\",\n        \"maxPriorityFeePerGas\": \"string\",\n        \"eip7702Auth\": {\n          \"chain_id\": \"string\",\n          \"address\": \"string\",\n          \"nonce\": \"string\",\n          \"y_parity\": \"string\",\n          \"r\": \"string\",\n          \"s\": \"string\"\n        }\n      },\n      \"webhookData\": \"string\"\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: alchemy_requestPaymasterAndData
description: |
  Requests gas coverage for a `UserOperation`.

  <Warning title="To be deprecated">
    Please use `alchemy_requestGasAndPaymasterAndData` instead.

    While you can use `alchemy_requestPaymasterAndData` to request a paymaster signature, it's important to note that this function requires gas fields to be part of the `UserOperation` passed as a parameter. These gas fields are influenced by the response of this endpoint, creating a circular dependency.

    To simplify this process, we introduced alchemy_requestGasAndPaymasterAndData. This function both estimates gas and provides signed `paymaster` and `paymasterData` fields, therefore resolving the circular dependency.
  </Warning>
params:
  - name: params[0]
    required: true
    description: Object containing the sponsorship request parameters.
    schema:
      type: object
      required:
        - policyId
        - entryPoint
        - userOperation
      properties:
        policyId:
          description: The Gas Manager policy ID or list of Gas Manager policy IDs.
          oneOf:
            - type: string
              title: policyId
              format: uuid
            - type: array
              title: policyId Array
              items:
                type: string
                format: uuid
        erc20Context:
          description: Erc20 context, required to enable users to pay gas with ERC-20 tokens.
          title: Context for Erc20 paymaster
          type: object
          properties:
            tokenAddress:
              description: Erc20 contract address
              title: hex encoded address
              type: string
              pattern: ^0x[0-9a-fA-F]{40}$
            maxTokenAmount:
              description: Maximum allowed amount of value in raw token amount
              title: positive decimal number
              type: number
              minimum: 0
            permit:
              description: A 7597 typed permit
              title: hex encoded bytes
              type: string
              pattern: ^0x[0-9a-f]*$
        entryPoint:
          type: string
          pattern: ^0[xX][0-9a-fA-F]*$
          description: The EntryPoint address the request should be sent through. This MUST be one of the EntryPoints returned by the `supportedEntryPoints` RPC call and match the version of the userOperation in the `userOperation` field.
        userOperation:
          title: User Operation, either v0.6 or v0.7 (missing signature and paymasterData)
          description: Partial UserOperation object, missing `paymasterAndData` and `signature` fields. This can be either a v0.6 or v0.7 userOperation, but **MUST** match the version of the EntryPoint at the address in the `entryPoint` field.
          oneOf:
            - title: User Operation v0.6
              type: object
              properties:
                sender:
                  description: The account making the operation
                  title: hex encoded address
                  type: string
                  pattern: ^0x[0-9a-fA-F]{40}$
                nonce:
                  description: Anti-replay parameter; used as salt for first-time account creation
                  title: hex encoded unsigned integer
                  type: string
                  pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                initCode:
                  description: The initCode of the account (needed if the account is not yet on-chain and needs creation)
                  title: hex encoded bytes
                  type: string
                  pattern: ^0x[0-9a-f]*$
                callData:
                  description: Encoded data for the primary function call or operation
                  title: hex encoded bytes
                  type: string
                  pattern: ^0x[0-9a-f]*$
                callGasLimit:
                  description: Gas allocated for the main execution call
                  title: hex encoded 64 bit unsigned integer
                  type: string
                  pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                verificationGasLimit:
                  description: Gas allocated for verification
                  title: hex encoded 64 bit unsigned integer
                  type: string
                  pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                preVerificationGas:
                  description: Gas for pre-verification execution and calldata
                  title: hex encoded 64 bit unsigned integer
                  type: string
                  pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                maxFeePerGas:
                  description: Maximum fee per gas (EIP-1559)
                  title: hex encoded 64 bit unsigned integer
                  type: string
                  pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                maxPriorityFeePerGas:
                  description: Max priority fee per gas (EIP-1559)
                  title: hex encoded 64 bit unsigned integer
                  type: string
                  pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                eip7702Auth:
                  description: The authorization tuple that an EOA account delegates to in EIP-7702
                  title: Eip 7702 Auth
                  type: object
                  properties:
                    chain_id:
                      description: The chain Id of the authorization
                      title: hex encoded 64 bit unsigned integer
                      type: string
                      pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                    address:
                      description: The address of the authorization
                      title: hex encoded address
                      type: string
                      pattern: ^0x[0-9a-fA-F]{40}$
                    nonce:
                      description: The nonce for the authorization
                      title: hex encoded 64 bit unsigned integer
                      type: string
                      pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                    y_parity:
                      description: Y parity of signed authorizzation tuple
                      title: hex encoded unsigned integer
                      type: string
                      pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                    r:
                      description: R of signed authorizzation tuple
                      title: hex encoded 256 bit unsigned integer
                      type: string
                      pattern: ^0x([1-9a-f]+[0-9a-f]{0,31})|0$
                    s:
                      description: S of signed authorizzation tuple
                      title: hex encoded 256 bit unsigned integer
                      type: string
                      pattern: ^0x([1-9a-f]+[0-9a-f]{0,31})|0$
            - title: User Operation v0.7
              type: object
              properties:
                sender:
                  description: Account initiating operation
                  title: hex encoded address
                  type: string
                  pattern: ^0x[0-9a-fA-F]{40}$
                nonce:
                  description: Account nonce or creation salt
                  title: hex encoded unsigned integer
                  type: string
                  pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                callData:
                  description: Data for operation call
                  title: hex encoded bytes
                  type: string
                  pattern: ^0x[0-9a-f]*$
                callGasLimit:
                  description: Gas allocated for call
                  title: hex encoded 64 bit unsigned integer
                  type: string
                  pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                verificationGasLimit:
                  description: Gas allocated for verification
                  title: hex encoded 64 bit unsigned integer
                  type: string
                  pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                maxFeePerGas:
                  description: Max fee per gas (EIP-1559)
                  title: hex encoded 64 bit unsigned integer
                  type: string
                  pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                maxPriorityFeePerGas:
                  description: Priority fee per gas (EIP-1559)
                  title: hex encoded 64 bit unsigned integer
                  type: string
                  pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                paymaster:
                  description: Paymaster contract address
                  title: hex encoded address
                  type: string
                  pattern: ^0x[0-9a-fA-F]{40}$
                paymasterVerificationGasLimit:
                  description: The gas limit for paymaster verification.
                  title: hex encoded 64 bit unsigned integer
                  type: string
                  pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                factory:
                  description: The account factory address (needed if and only if the account is not yet on-chain and needs to be created)
                  title: hex encoded address
                  type: string
                  pattern: ^0x[0-9a-fA-F]{40}$
                factoryData:
                  description: Data for the account factory (only if the account factory exists)
                  title: hex encoded bytes
                  type: string
                  pattern: ^0x[0-9a-f]*$
                preVerificationGas:
                  description: The amount of gas to pay for to compensate the bundler for pre-verification execution and calldata
                  title: hex encoded 64 bit unsigned integer
                  type: string
                  pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                paymasterPostOpGasLimit:
                  description: The amount of gas to allocate for the paymaster post-op code (only if a paymaster exists)
                  title: hex encoded 64 bit unsigned integer
                  type: string
                  pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                eip7702Auth:
                  description: The authorization tuple that an EOA account delegates to in EIP-7702
                  title: Eip 7702 Auth
                  type: object
                  properties:
                    chain_id:
                      description: The chain Id of the authorization
                      title: hex encoded 64 bit unsigned integer
                      type: string
                      pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                    address:
                      description: The address of the authorization
                      title: hex encoded address
                      type: string
                      pattern: ^0x[0-9a-fA-F]{40}$
                    nonce:
                      description: The nonce for the authorization
                      title: hex encoded 64 bit unsigned integer
                      type: string
                      pattern: ^0x([1-9a-f]+[0-9a-f]{0,15})|0$
                    y_parity:
                      description: Y parity of signed authorizzation tuple
                      title: hex encoded unsigned integer
                      type: string
                      pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
                    r:
                      description: R of signed authorizzation tuple
                      title: hex encoded 256 bit unsigned integer
                      type: string
                      pattern: ^0x([1-9a-f]+[0-9a-f]{0,31})|0$
                    s:
                      description: S of signed authorizzation tuple
                      title: hex encoded 256 bit unsigned integer
                      type: string
                      pattern: ^0x([1-9a-f]+[0-9a-f]{0,31})|0$
        webhookData:
          type: string
          description: Additional data you can include in the request, such as proof of humanity, if you have enabled custom rules in your Gas Manager policy.
result:
  name: Response
  description: The response depends on the EntryPoint version used in the request.
  schema:
    oneOf:
      - title: Entrypoint v0.6 Response
        type: object
        required:
          - paymasterAndData
        properties:
          paymasterAndData:
            type: string
            description: The 0x-prefixed hex string for the user to put into the UO's paymasterAndData field. Contains gas manager `address`, `sigTimeRange`, and secp256k1 `signature`.
      - title: Entrypoint v0.7 Response
        type: object
        required:
          - paymaster
          - paymasterData
        properties:
          paymaster:
            type: string
            description: The paymaster address used in the operation.
          paymasterData:
            type: string
            description: The data for the paymaster in the operation.
          paymasterVerificationGasLimit:
            type: string
            description: The gas limit for paymaster verification.
          paymasterPostOpGasLimit:
            type: string
            description: The gas limit for paymaster post-operation.
examples:
  - name: alchemy_requestPaymasterAndData example
    params:
      - name: params
        value:
          webhookData: example webhook data
          policyId: 69d524a7-e932-4214-8673-dcdcba31bb42
          entryPoint: '0x0000000071727De22E5E9d8BAf0edAc6f37da032'
          userOperation:
            sender: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd'
            nonce: '0x2'
            callData: '0xdeadbeef'
            callGasLimit: '0x5208'
            verificationGasLimit: '0x5208'
            preVerificationGas: '0x5208'
            maxFeePerGas: '0x1'
            maxPriorityFeePerGas: '0x1'
    result:
      name: alchemy_requestPaymasterAndData response
      value:
        paymaster: '0x4685d4c74BaC297e23D5C7D1a2bFc1b4581e6704'
        paymasterData: '0x00000067890abcdef1234567890abcdef1234567890abcdef'
        paymasterVerificationGasLimit: '0x5208'
        paymasterPostOpGasLimit: '0x5208'
```
