Asset Changes - Explained

Dive into the Asset Changes API with this detailed example of simulating a transaction to swap 1 USDC for UNI using Uniswap V2.

The beauty of simulation is that we can use any from address!

Let’s simulate a transaction using the Asset Changes API and explain the results.

We will swap 1 USDC for UNI using Uniswap V2 as our example.

curl
1curl --location --request POST 'https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY' \
2--header 'Content-Type: application/json' \
3--data-raw '{
4 "jsonrpc": "2.0",
5 "method": "alchemy_simulateAssetChanges",
6 "id": 1,
7 "params": [
8 {
9 "from": "0x07Eee3bfdfA311f6f06D419C8cCcA08a6EfDD162",
10 "to": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
11 "value": "0x0",
12 "data": "0x38ed173900000000000000000000000000000000000000000000000000000000000f4240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000007eee3bfdfa311f6f06d419c8ccca08a6efdd162000000000000000000000000000000000000000000000000000000006b49d2000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f984"
13 }
14 ]
15}'
Response
1{
2 "jsonrpc": "2.0",
3 "id": 1,
4 "result": {
5 "changes": [
6 {
7 "assetType": "ERC20",
8 "changeType": "TRANSFER",
9 "from": "0x07eee3bfdfa311f6f06d419c8ccca08a6efdd162",
10 "to": "0xebfb684dd2b01e698ca6c14f10e4f289934a54d6",
11 "rawAmount": "1000000",
12 "contractAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
13 "tokenId": null,
14 "decimals": 6,
15 "symbol": "USDC",
16 "name": "USD Coin",
17 "logo": "https://static.alchemyapi.io/images/assets/3408.png",
18 "amount": "1"
19 },
20 {
21 "assetType": "ERC20",
22 "changeType": "TRANSFER",
23 "from": "0xebfb684dd2b01e698ca6c14f10e4f289934a54d6",
24 "to": "0x07eee3bfdfa311f6f06d419c8ccca08a6efdd162",
25 "rawAmount": "186275962091465171",
26 "contractAddress": "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",
27 "tokenId": null,
28 "decimals": 18,
29 "symbol": "UNI",
30 "name": "Uniswap",
31 "logo": "https://static.alchemyapi.io/images/assets/7083.png",
32 "amount": "0.186275962091465171"
33 }
34 ],
35 "error": null
36 }
37}

User address - 0x07eee3bfdfa311f6f06d419c8ccca08a6efdd162 USDC contract - 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 USDC / UNI pool - 0xEBFb684dD2b01E698ca6c14F10e4f289934a54D6 Uniswap RouterV2 - 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D UNI contract - 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984

  1. User (from) sends 1 USDC (contractAddress) to the Uniswap USDC / UNI pool (to).

    json
    1{
    2 "assetType": "ERC20",
    3 "changeType": "TRANSFER",
    4 "from": "0x07eee3bfdfa311f6f06d419c8ccca08a6efdd162",
    5 "to": "0xebfb684dd2b01e698ca6c14f10e4f289934a54d6",
    6 "contractAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    7 "symbol": "USDC",
    8 "amount": "1"
    9 ...
    10},
  2. The USDC / UNI pool (from) sends 0.186 UNI (contractAddress) to the user (to).

    json
    1{
    2 "assetType": "ERC20",
    3 "changeType": "TRANSFER",
    4 "from": "0xebfb684dd2b01e698ca6c14f10e4f289934a54d6",
    5 "to": "0x07eee3bfdfa311f6f06d419c8ccca08a6efdd162",
    6 "contractAddress": "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",
    7 "symbol": "UNI",
    8 "amount": "0.186275962091465171"
    9 ...
    10}
  3. 1 USDC was swapped for 0.186 UNI 🎉