# alchemy_simulateUserOperationAssetChanges

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

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

Simulates userOperations and returns a list of asset changes.

<Note title="Changes in blockchain's state could lead to different outcomes">
  The results provided by this method are based on the blockchain's state at the moment of simulation. Changes in the blockchain state, such as updates to contract variables or balances, can occur between the time of simulation and userOperation execution.

  This could lead to different outcomes than predicted. For instance, if a userOperation's effect is conditional on the current state of a contract, and this state is altered before the transaction is executed, the final result may not match the simulation.

  Please conside this potential variance when using the API.
</Note>


Reference: https://www.alchemy.com/docs/wallets/api-reference/bundler-api/useroperation-simulation-endpoints/alchemy-simulate-user-operation-asset-changes

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| UserOperation | object | Yes | userOperation to simulate. The signature can be a [dummy value](/docs/reference/bundler-faqs#what-is-a-dummy-signature); it doesn't need to be valid. |
| entryPoint | string | Yes | `EntryPoint` to use for the simulation. This MUST be one of the EntryPoints returned by the `supportedEntryPoints` RPC call. |
| blockNumber | string | No | Optional block number in context of which the simulation should be executed. If not specified, the current block number is used. |

## Result

**Simulation Result** (object): Object containing simulated asset changes and any potential errors.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "alchemy_simulateUserOperationAssetChanges",
  "params": [
    {
      "sender": "0xceb161d3e0B6d01bc0e87ECC27fF9f2E2eCDCD81",
      "nonce": "0x3",
      "initCode": "0x",
      "callData": "0xb61d27f600000000000000000000000043f6bfbe9dad44cf0a60570c30c307d949be4cd40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000645c833bfd000000000000000000000000613c64104b98b048b93289ed20aefd80912b3cde0000000000000000000000000000000000000000000000000de123e8a84f9901000000000000000000000000c9371ea30dea5ac745b71e191ba8cde2c4e66df500000000000000000000000000000000000000000000000000000000",
      "callGasLimit": "0x7A1200",
      "verificationGasLimit": "0x927C0",
      "preVerificationGas": "0x15F90",
      "maxFeePerGas": "0x656703D00",
      "maxPriorityFeePerGas": "0x13AB6680",
      "signature": "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c",
      "paymasterAndData": "0x9db7f05b0eb93eb242b5913596dcfaada756af5c"
    },
    "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
    "0x113CF6E"
  ],
  "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_simulateUserOperationAssetChanges",
  "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",
    "0x113CF6E"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'alchemy_simulateUserOperationAssetChanges',
    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',
      '0x113CF6E'
    ]
  })
};

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_simulateUserOperationAssetChanges",
    "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",
        "0x113CF6E"
    ]
}
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_simulateUserOperationAssetChanges\",\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    \"0x113CF6E\"\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_simulateUserOperationAssetChanges\",\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    \"0x113CF6E\"\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_simulateUserOperationAssetChanges\",\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    \"0x113CF6E\"\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: alchemy_simulateUserOperationAssetChanges
description: |
  Simulates userOperations and returns a list of asset changes.

  <Note title="Changes in blockchain's state could lead to different outcomes">
    The results provided by this method are based on the blockchain's state at the moment of simulation. Changes in the blockchain state, such as updates to contract variables or balances, can occur between the time of simulation and userOperation execution.

    This could lead to different outcomes than predicted. For instance, if a userOperation's effect is conditional on the current state of a contract, and this state is altered before the transaction is executed, the final result may not match the simulation.

    Please conside this potential variance when using the API.
  </Note>
params:
  - name: UserOperation
    required: true
    description: userOperation to simulate. The signature can be a [dummy value](/docs/reference/bundler-faqs#what-is-a-dummy-signature); it doesn't need to be valid.
    schema:
      oneOf:
        - type: object
          title: User Operation v0.6
          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$
            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:
                  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$
        - type: object
          title: User Operation v0.7 / v0.8
          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}$
            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:
              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$
            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:
                  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$
  - name: entryPoint
    required: true
    description: '`EntryPoint` to use for the simulation. This MUST be one of the EntryPoints returned by the `supportedEntryPoints` RPC call.'
    schema:
      title: hex encoded address
      type: string
      pattern: ^0x[0-9a-fA-F]{40}$
  - name: blockNumber
    required: false
    description: Optional block number in context of which the simulation should be executed. If not specified, the current block number is used.
    schema:
      title: hex encoded unsigned integer
      type: string
      pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
result:
  name: Simulation Result
  description: Object containing simulated asset changes and any potential errors.
  schema:
    type: object
    properties:
      changes:
        type: array
        items:
          type: object
          required:
            - assetType
            - changeType
            - from
            - to
            - rawAmount
            - amount
            - symbol
            - decimals
            - contractAddress
            - name
            - logo
            - tokenId
          properties:
            assetType:
              type: string
              enum:
                - NATIVE
                - ERC20
                - ERC721
                - ERC1155
                - SPECIAL_NFT
            changeType:
              type: string
              enum:
                - APPROVE
                - TRANSFER
            from:
              title: hex encoded address
              type: string
              pattern: ^0x[0-9a-fA-F]{40}$
              description: address the transaction is sent from
            to:
              title: hex encoded address
              type: string
              pattern: ^0x[0-9a-fA-F]{40}$
              description: address the transaction is directed to
            rawAmount:
              type: string
            amount:
              type: string
            symbol:
              type: string
            decimals:
              type:
                - number
                - 'null'
            contractAddress:
              type:
                - string
                - 'null'
            name:
              type:
                - string
                - 'null'
            logo:
              type:
                - string
                - 'null'
            tokenId:
              type:
                - number
                - 'null'
      error:
        type:
          - object
          - 'null'
        properties:
          message:
            type: string
          revertReason:
            type: string
            nullable: true
            description: The reason why a transaction would revert. Provides details about potential transaction failure before execution.
examples:
  - name: alchemy_simulateUserOperationAssetChanges example
    params:
      - name: UserOperation
        value:
          sender: '0xceb161d3e0B6d01bc0e87ECC27fF9f2E2eCDCD81'
          nonce: '0x3'
          initCode: 0x
          callData: '0xb61d27f600000000000000000000000043f6bfbe9dad44cf0a60570c30c307d949be4cd40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000645c833bfd000000000000000000000000613c64104b98b048b93289ed20aefd80912b3cde0000000000000000000000000000000000000000000000000de123e8a84f9901000000000000000000000000c9371ea30dea5ac745b71e191ba8cde2c4e66df500000000000000000000000000000000000000000000000000000000'
          callGasLimit: '0x7A1200'
          verificationGasLimit: '0x927C0'
          preVerificationGas: '0x15F90'
          maxFeePerGas: '0x656703D00'
          maxPriorityFeePerGas: '0x13AB6680'
          signature: '0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c'
          paymasterAndData: '0x9db7f05b0eb93eb242b5913596dcfaada756af5c'
      - name: entryPoint
        value: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789'
      - name: blockNumber
        value: '0x113CF6E'
```
