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 --location --request POST 'https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "alchemy_simulateAssetChanges",
"id": 1,
"params": [
{
"from": "0x07Eee3bfdfA311f6f06D419C8cCcA08a6EfDD162",
"to": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
"value": "0x0",
"data": "0x38ed173900000000000000000000000000000000000000000000000000000000000f4240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000007eee3bfdfa311f6f06d419c8ccca08a6efdd162000000000000000000000000000000000000000000000000000000006b49d2000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f984"
}
]
}'
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"changes": [
{
"assetType": "ERC20",
"changeType": "TRANSFER",
"from": "0x07eee3bfdfa311f6f06d419c8ccca08a6efdd162",
"to": "0xebfb684dd2b01e698ca6c14f10e4f289934a54d6",
"rawAmount": "1000000",
"contractAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"tokenId": null,
"decimals": 6,
"symbol": "USDC",
"name": "USD Coin",
"logo": "https://static.alchemyapi.io/images/assets/3408.png",
"amount": "1"
},
{
"assetType": "ERC20",
"changeType": "TRANSFER",
"from": "0xebfb684dd2b01e698ca6c14f10e4f289934a54d6",
"to": "0x07eee3bfdfa311f6f06d419c8ccca08a6efdd162",
"rawAmount": "186275962091465171",
"contractAddress": "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",
"tokenId": null,
"decimals": 18,
"symbol": "UNI",
"name": "Uniswap",
"logo": "https://static.alchemyapi.io/images/assets/7083.png",
"amount": "0.186275962091465171"
}
],
"error": null
}
}
👉 Addresses
User address -
0x07eee3bfdfa311f6f06d419c8ccca08a6efdd162
USDC contract -0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
USDC / UNI pool -0xEBFb684dD2b01E698ca6c14F10e4f289934a54D6
Uniswap RouterV2 -0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
UNI contract -0x1f9840a85d5af5bf1d1762f925bdaddc4201f984
-
User (
from
) sends 1 USDC (contractAddress
) to the Uniswap USDC / UNI pool (to
).{ "assetType": "ERC20", "changeType": "TRANSFER", "from": "0x07eee3bfdfa311f6f06d419c8ccca08a6efdd162", "to": "0xebfb684dd2b01e698ca6c14f10e4f289934a54d6", "contractAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "symbol": "USDC", "amount": "1" ... },
-
The USDC / UNI pool (
from
) sends 0.186 UNI (contractAddress
) to the user (to
).{ "assetType": "ERC20", "changeType": "TRANSFER", "from": "0xebfb684dd2b01e698ca6c14f10e4f289934a54d6", "to": "0x07eee3bfdfa311f6f06d419c8ccca08a6efdd162", "contractAddress": "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984", "symbol": "UNI", "amount": "0.186275962091465171" ... }
-
1 USDC was swapped for 0.186 UNI 🎉
Updated over 1 year ago