# alchemy_simulateAssetChanges

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

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

Simulates a transaction and returns a list of asset changes.

Reference: https://www.alchemy.com/docs/data/simulation-apis/transaction-simulation-endpoints/alchemy-simulate-asset-changes

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| transaction | object | Yes | Object describing the transaction to simulate. |

## Result

**Simulation result** (object): The asset changes resulting from the transaction simulation.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "alchemy_simulateAssetChanges",
  "params": [
    {
      "from": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
      "to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
      "data": "0xa9059cbb000000000000000000000000fc43f5f9dd45258b3aff31bdbe6561d97e8b71de00000000000000000000000000000000000000000000000000000000000f4240",
      "gas": "0x5208",
      "gasPrice": "0x3b9aca00"
    }
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "changes": [
      {
        "assetType": "ERC20",
        "changeType": "TRANSFER",
        "from": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
        "to": "0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de",
        "rawAmount": "1000000",
        "contractAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
        "decimals": 6,
        "symbol": "USDC",
        "name": "USD Coin",
        "logo": "https://static.alchemyapi.io/images/assets/3408.png",
        "amount": "1",
        "tokenId": null
      }
    ],
    "gasUsed": "0x5208",
    "error": null
  },
  "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_simulateAssetChanges",
  "params": [
    {
      "from": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
      "to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
      "data": "0xa9059cbb000000000000000000000000fc43f5f9dd45258b3aff31bdbe6561d97e8b71de00000000000000000000000000000000000000000000000000000000000f4240",
      "gas": "0x5208",
      "gasPrice": "0x3b9aca00"
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'alchemy_simulateAssetChanges',
    params: [
      {
        from: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
        to: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
        data: '0xa9059cbb000000000000000000000000fc43f5f9dd45258b3aff31bdbe6561d97e8b71de00000000000000000000000000000000000000000000000000000000000f4240',
        gas: '0x5208',
        gasPrice: '0x3b9aca00'
      }
    ]
  })
};

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_simulateAssetChanges",
    "params": [
        {
            "from": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
            "to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
            "data": "0xa9059cbb000000000000000000000000fc43f5f9dd45258b3aff31bdbe6561d97e8b71de00000000000000000000000000000000000000000000000000000000000f4240",
            "gas": "0x5208",
            "gasPrice": "0x3b9aca00"
        }
    ]
}
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_simulateAssetChanges\",\n  \"params\": [\n    {\n      \"from\": \"0xd8da6bf26964af9d7eed9e03e53415d37aa96045\",\n      \"to\": \"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\n      \"data\": \"0xa9059cbb000000000000000000000000fc43f5f9dd45258b3aff31bdbe6561d97e8b71de00000000000000000000000000000000000000000000000000000000000f4240\",\n      \"gas\": \"0x5208\",\n      \"gasPrice\": \"0x3b9aca00\"\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_simulateAssetChanges\",\n  \"params\": [\n    {\n      \"from\": \"0xd8da6bf26964af9d7eed9e03e53415d37aa96045\",\n      \"to\": \"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\n      \"data\": \"0xa9059cbb000000000000000000000000fc43f5f9dd45258b3aff31bdbe6561d97e8b71de00000000000000000000000000000000000000000000000000000000000f4240\",\n      \"gas\": \"0x5208\",\n      \"gasPrice\": \"0x3b9aca00\"\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_simulateAssetChanges\",\n  \"params\": [\n    {\n      \"from\": \"0xd8da6bf26964af9d7eed9e03e53415d37aa96045\",\n      \"to\": \"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\",\n      \"data\": \"0xa9059cbb000000000000000000000000fc43f5f9dd45258b3aff31bdbe6561d97e8b71de00000000000000000000000000000000000000000000000000000000000f4240\",\n      \"gas\": \"0x5208\",\n      \"gasPrice\": \"0x3b9aca00\"\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: alchemy_simulateAssetChanges
description: Simulates a transaction and returns a list of asset changes.
params:
  - name: transaction
    required: true
    description: Object describing the transaction to simulate.
    schema:
      type: object
      required:
        - to
      properties:
        from:
          title: hex encoded address
          type: string
          pattern: ^0x[0-9a-fA-F]{40}$
        to:
          title: hex encoded address
          type: string
          pattern: ^0x[0-9a-fA-F]{40}$
        value:
          title: hex encoded unsigned integer
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        data:
          title: hex encoded bytes (any case)
          type: string
          pattern: ^0x[0-9a-fA-F]*$
        gas:
          title: hex encoded unsigned integer
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        gasPrice:
          title: hex encoded unsigned integer
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        maxFeePerGas:
          title: hex encoded unsigned integer
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
        maxPriorityFeePerGas:
          title: hex encoded unsigned integer
          type: string
          pattern: ^0x([1-9a-f]+[0-9a-f]*|0)$
result:
  name: Simulation result
  description: The asset changes resulting from the transaction simulation.
  schema:
    type: object
    properties:
      changes:
        type: array
        items:
          type: object
          properties:
            assetType:
              type: string
            changeType:
              type: string
            from:
              type: string
            to:
              type: string
            rawAmount:
              type: string
            contractAddress:
              type: string
            tokenId:
              type:
                - string
                - 'null'
            decimals:
              type: integer
            symbol:
              type: string
            name:
              type: string
            logo:
              type: string
            amount:
              type: string
examples:
  - name: Simulate transferring USDC
    params:
      - name: transaction
        value:
          from: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'
          to: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
          data: '0xa9059cbb000000000000000000000000fc43f5f9dd45258b3aff31bdbe6561d97e8b71de00000000000000000000000000000000000000000000000000000000000f4240'
          gas: '0x5208'
          gasPrice: '0x3b9aca00'
    result:
      name: Simulation result
      value:
        changes:
          - assetType: ERC20
            changeType: TRANSFER
            from: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'
            to: '0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de'
            rawAmount: '1000000'
            contractAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
            decimals: 6
            symbol: USDC
            name: USD Coin
            logo: https://static.alchemyapi.io/images/assets/3408.png
            amount: '1'
            tokenId: null
        gasUsed: '0x5208'
        error: null
```
