# eth_estimateUserOperationGas

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

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

Estimates the gas values for a `UserOperation`.

<Note>
  This endpoint requires a dummy signature in the `userOp`. Check our [FAQs](/docs/reference/bundler-faqs#what-is-a-dummy-signature) to learn what a dummy signature is.
</Note>


Reference: https://www.alchemy.com/docs/wallets/api-reference/bundler-api/bundler-api-endpoints/eth-estimate-user-operation-gas

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| UserOperation | object | Yes | Contains gas limits and prices (optional). This can be a v0.6, v0.7, or v0.8 userOperation but must match the version of the `EntryPoint` at the address of the second parameter. |
| entryPoint | string | Yes | The address to which the request should be sent. This must be one of the `EntryPoint` returned by the `supportedEntryPoints` method and should match the version of the `userOp` in the first parameter. |
| stateOverrideSet | object | No | Allows changes to the state of a contract before executing the call. For example, you can modify variable values (like balances or approvals) for that call without changing the contract itself on the blockchain.  In more technical terms, the state override set is an optional parameter that allows executing the call against a modified chain state. It is an address-to-state mapping, where each entry specifies some state to be overridden prior to executing the call.  |

## Result

**Gas estimation** (object): Gas values estimated for the userOperation.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "eth_estimateUserOperationGas",
  "params": [
    {
      "sender": "0x...",
      "nonce": "0x...",
      "callData": "0x..."
    },
    "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "preVerificationGas": "0x1",
    "verificationGasLimit": "0x1",
    "callGasLimit": "0x1",
    "paymasterVerificationGasLimit": "0x1"
  },
  "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": "eth_estimateUserOperationGas",
  "params": [
    {
      "sender": "string",
      "nonce": "string",
      "initCode": "string",
      "callData": "string",
      "callGasLimit": "string",
      "verificationGasLimit": "string",
      "preVerificationGas": "string",
      "maxFeePerGas": "string",
      "maxPriorityFeePerGas": "string",
      "signature": "string",
      "paymasterAndData": "string",
      "eip7702Auth": {
        "chain_id": "string",
        "address": "string",
        "nonce": "string",
        "y_parity": "string",
        "r": "string",
        "s": "string"
      }
    },
    "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
    {
      "balance": "string",
      "nonce": "string",
      "code": "string",
      "state": {
        "property1": "string"
      },
      "stateDiff": {
        "property1": "string"
      }
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'eth_estimateUserOperationGas',
    params: [
      {
        sender: 'string',
        nonce: 'string',
        initCode: 'string',
        callData: 'string',
        callGasLimit: 'string',
        verificationGasLimit: 'string',
        preVerificationGas: 'string',
        maxFeePerGas: 'string',
        maxPriorityFeePerGas: 'string',
        signature: 'string',
        paymasterAndData: 'string',
        eip7702Auth: {
          chain_id: 'string',
          address: 'string',
          nonce: 'string',
          y_parity: 'string',
          r: 'string',
          s: 'string'
        }
      },
      '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
      {
        balance: 'string',
        nonce: 'string',
        code: 'string',
        state: {property1: 'string'},
        stateDiff: {property1: '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": "eth_estimateUserOperationGas",
    "params": [
        {
            "sender": "string",
            "nonce": "string",
            "initCode": "string",
            "callData": "string",
            "callGasLimit": "string",
            "verificationGasLimit": "string",
            "preVerificationGas": "string",
            "maxFeePerGas": "string",
            "maxPriorityFeePerGas": "string",
            "signature": "string",
            "paymasterAndData": "string",
            "eip7702Auth": {
                "chain_id": "string",
                "address": "string",
                "nonce": "string",
                "y_parity": "string",
                "r": "string",
                "s": "string"
            }
        },
        "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
        {
            "balance": "string",
            "nonce": "string",
            "code": "string",
            "state": { "property1": "string" },
            "stateDiff": { "property1": "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\": \"eth_estimateUserOperationGas\",\n  \"params\": [\n    {\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      \"signature\": \"string\",\n      \"paymasterAndData\": \"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    \"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789\",\n    {\n      \"balance\": \"string\",\n      \"nonce\": \"string\",\n      \"code\": \"string\",\n      \"state\": {\n        \"property1\": \"string\"\n      },\n      \"stateDiff\": {\n        \"property1\": \"string\"\n      }\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\": \"eth_estimateUserOperationGas\",\n  \"params\": [\n    {\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      \"signature\": \"string\",\n      \"paymasterAndData\": \"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    \"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789\",\n    {\n      \"balance\": \"string\",\n      \"nonce\": \"string\",\n      \"code\": \"string\",\n      \"state\": {\n        \"property1\": \"string\"\n      },\n      \"stateDiff\": {\n        \"property1\": \"string\"\n      }\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\": \"eth_estimateUserOperationGas\",\n  \"params\": [\n    {\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      \"signature\": \"string\",\n      \"paymasterAndData\": \"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    \"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789\",\n    {\n      \"balance\": \"string\",\n      \"nonce\": \"string\",\n      \"code\": \"string\",\n      \"state\": {\n        \"property1\": \"string\"\n      },\n      \"stateDiff\": {\n        \"property1\": \"string\"\n      }\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: eth_estimateUserOperationGas
description: |
  Estimates the gas values for a `UserOperation`.

  <Note>
    This endpoint requires a dummy signature in the `userOp`. Check our [FAQs](/docs/reference/bundler-faqs#what-is-a-dummy-signature) to learn what a dummy signature is.
  </Note>
params:
  - name: UserOperation
    required: true
    description: Contains gas limits and prices (optional). This can be a v0.6, v0.7, or v0.8 userOperation but must match the version of the `EntryPoint` at the address of the second parameter.
    schema:
      oneOf:
        - type: object
          title: User Operation v0.6
          properties:
            sender:
              title: hex encoded address
              type: string
              pattern: ^0x[0-9a-fA-F]{40}$
              description: The account making the operation
            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$
            signature:
              description: Data passed during verification
              title: hex encoded bytes (any case)
              type: string
              pattern: ^0x[0-9a-fA-F]*$
            paymasterAndData:
              description: Paymaster address and extra data
              title: hex encoded bytes
              type: string
              pattern: ^0x[0-9a-f]*$
            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:
                  title: hex encoded address
                  type: string
                  pattern: ^0x[0-9a-fA-F]{40}$
                  description: The address of the authorization
                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$
        - type: object
          title: User Operation v0.7 / v0.8
          properties:
            sender:
              title: hex encoded address
              type: string
              pattern: ^0x[0-9a-fA-F]{40}$
              description: Account initiating operation
            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:
              title: hex encoded address
              type: string
              pattern: ^0x[0-9a-fA-F]{40}$
              description: Paymaster contract address
            paymasterData:
              description: Data for paymaster
              title: hex encoded bytes
              type: string
              pattern: ^0x[0-9a-f]*$
            paymasterVerificationGasLimit:
              type: string
              description: The gas limit for paymaster verification.
            factory:
              title: hex encoded address
              type: string
              pattern: ^0x[0-9a-fA-F]{40}$
              description: The account factory address (needed if and only if the account is not yet on-chain and needs to be created)
            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$
            signature:
              description: Data passed into the account along with the nonce during the verification step
              title: hex encoded bytes (any case)
              type: string
              pattern: ^0x[0-9a-fA-F]*$
            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:
                  title: hex encoded address
                  type: string
                  pattern: ^0x[0-9a-fA-F]{40}$
                  description: The address of the authorization
                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$
  - name: entryPoint
    required: true
    description: The address to which the request should be sent. This must be one of the `EntryPoint` returned by the `supportedEntryPoints` method and should match the version of the `userOp` in the first parameter.
    schema:
      title: hex encoded address
      type: string
      pattern: ^0x[0-9a-fA-F]{40}$
  - name: stateOverrideSet
    required: false
    description: |
      Allows changes to the state of a contract before executing the call. For example, you can modify variable values (like balances or approvals) for that call without changing the contract itself on the blockchain. 

      In more technical terms, the state override set is an optional parameter that allows executing the call against a modified chain state. It is an address-to-state mapping, where each entry specifies some state to be overridden prior to executing the call.
    schema:
      type: object
      properties:
        balance:
          type: string
          description: Fake balance to set for the account before executing the call (<= 32 bytes)
        nonce:
          type: string
          description: Fake nonce to set for the account before executing the call (<= 8 bytes).
        code:
          type: string
          description: Fake EVM bytecode to inject into the account before executing the call.
        state:
          type: object
          description: Fake key-value mapping to override all slots in the account storage before executing the call.
        stateDiff:
          type: object
          description: Fake key-value mapping to override individual slots in the account storage before executing the call.
result:
  name: Gas estimation
  description: Gas values estimated for the userOperation.
  schema:
    type: object
    required:
      - entrypointV06Response
      - entrypointV07Response
    properties:
      entrypointV06Response:
        type: object
        title: Entrypoint v0.6 Response
        properties:
          preVerificationGas:
            description: Gas overhead of this userOperation.
            title: hex encoded 256 bit unsigned integer
            type: string
            pattern: ^0x([1-9a-f]+[0-9a-f]{0,31})|0$
          verificationGasLimit:
            description: Actual gas used by the validation of this userOperation.
            title: hex encoded 256 bit unsigned integer
            type: string
            pattern: ^0x([1-9a-f]+[0-9a-f]{0,31})|0$
          callGasLimit:
            description: Value used by inner account execution.
            title: hex encoded 256 bit unsigned integer
            type: string
            pattern: ^0x([1-9a-f]+[0-9a-f]{0,31})|0$
      entrypointV07Response:
        type: object
        title: Entrypoint v0.7 / v0.8 Response
        properties:
          preVerificationGas:
            description: Gas overhead of this userOperation.
            title: hex encoded 256 bit unsigned integer
            type: string
            pattern: ^0x([1-9a-f]+[0-9a-f]{0,31})|0$
          verificationGasLimit:
            description: Actual gas used by the validation of this userOperation.
            title: hex encoded 256 bit unsigned integer
            type: string
            pattern: ^0x([1-9a-f]+[0-9a-f]{0,31})|0$
          callGasLimit:
            description: Value used by inner account execution.
            title: hex encoded 256 bit unsigned integer
            type: string
            pattern: ^0x([1-9a-f]+[0-9a-f]{0,31})|0$
          paymasterVerificationGasLimit:
            description: Value used by the paymaster during verification.
            title: hex encoded 256 bit unsigned integer
            type: string
            pattern: ^0x([1-9a-f]+[0-9a-f]{0,31})|0$
examples:
  - name: eth_estimateUserOperationGas example
    params:
      - name: UserOperation
        value:
          sender: 0x...
          nonce: 0x...
          callData: 0x...
      - name: Entrypoint address
        value: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789'
    result:
      name: Gas estimation
      value:
        preVerificationGas: '0x1'
        verificationGasLimit: '0x1'
        callGasLimit: '0x1'
        paymasterVerificationGasLimit: '0x1'
```
