Transaction simulation
What a transaction would move and approve, the gas it would use, and why it would fail, before it is signed.
The call
Send a transaction you have not signed, and see what it would do.
The answer lists every asset it would move, every approval it would give, the gas it would use, and why it would fail.
It is a call of the RPC’s endpoint, sent as any other JSON-RPC call.
Call blockhash_simulateAssetChanges.
Code that already calls alchemy_simulateAssetChanges keeps working.
Our node runs the transaction on the state of the block you name, or of the newest block, at that block’s own time.
Nothing is sent to the chain, and nothing is signed.
- Method
- Endpoint
- Costs
- 2,500 units
- Plans
- Free and Pay as you go
The request
The parameters are the transaction, and the block where you name one: [transaction] or [transaction, block].
The transaction takes these eight fields, each named as it is written here.
A field of any other name is refused, so a misspelled field is never dropped.
Name gasPrice, or maxFeePerGas and maxPriorityFeePerGas, and not both.
A fee is used only beside gas.
Without gas, the fee is left out, and the sender’s balance is checked for the value it sends alone.
The block is a number in hex, a block hash, or latest, pending, safe, finalized or earliest. Left out, it is latest.
A transaction at a past block runs on our archive, at the same price.
| Field | What it is |
|---|---|
to | The address the transaction is sent to. It is required. |
from | The address that sends it. Left out, it is the zero address. |
value | The wei it sends, in hex. |
data | The calldata, in hex. |
gas | The most gas it may use, in hex. Left out, it may use up to 32,000,000, the most one transaction may use on Robinhood Chain. |
gasPrice | The price a legacy transaction pays for a unit of gas, in hex. |
maxFeePerGas | The most an EIP-1559 transaction pays for a unit of gas, in hex. |
maxPriorityFeePerGas | An EIP-1559 transaction’s tip, in hex. |
The answer
The sample sends 1 USDG from the WETH/USDG pool, a contract, to the WETH contract.
It ran at block 123,501,030.
gasUsed is the gas of the transaction’s run on Robinhood Chain.
A receipt also counts the gas that pays for posting the transaction to Ethereum.
| Field | What it is |
|---|---|
changes | Every asset moved and every approval given, in the order they happened. |
gasUsed | The gas the transaction used, in hex. It is null where it would fail. |
error | Null where it would succeed. Where it would fail, its message and its revert reason. |
blockNumber | The block whose state it ran on, in hex. It is Blockhash’s own field. |
RPC=https://robinhood-mainnet.rpc.blockhash.xyz/v1
KEY="<your key>"
curl $RPC/$KEY \
-H 'content-type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"blockhash_simulateAssetChanges","params":[
{"from":"0x52e65b17fb6e5ba00ed806f37afcd2daa50271ca",
"to":"0x5fc5360d0400a0fd4f2af552add042d716f1d168",
"data":"0xa9059cbb0000000000000000000000000bd7d308f8e1639fab988df18a8011f41eacad7300000000000000000000000000000000000000000000000000000000000f4240"},
"0x75c79e6"]}'
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"changes": [
{
"assetType": "ERC20",
"changeType": "TRANSFER",
"from": "0x52e65b17fb6e5ba00ed806f37afcd2daa50271ca",
"to": "0x0bd7d308f8e1639fab988df18a8011f41eacad73",
"rawAmount": "1000000",
"contractAddress": "0x5fc5360d0400a0fd4f2af552add042d716f1d168",
"tokenId": null,
"decimals": 6,
"symbol": "USDG",
"name": "Global Dollar",
"logo": null,
"amount": "1"
}
],
"gasUsed": "0xbc8a",
"error": null,
"blockNumber": "0x75c79e6"
}
}Each change
Every change has the same twelve fields: assetType, changeType, from, to, rawAmount, contractAddress, tokenId, decimals, symbol, name, logo and amount.
A field that does not apply is null.
rawAmount is the amount in the token’s smallest unit, and amount is the same with its decimals applied. Both are decimal strings.
symbol, name and decimals are what the index holds of the token. Each is null where it holds none.
Where the index does not know a token’s decimals, amount is null and rawAmount stands.
tokenId is a decimal string. Ask the Data API for nfts/<collection>/<tokenId> to read the NFT.
An approval’s decimals is 0, so its amount is the raw allowance.
logo is null.
A contract can log a transfer it did not make.
The answer says what the logs say.
| assetType | changeType | What it is |
|---|---|---|
NATIVE | TRANSFER | ETH, sent with the transaction or moved by a contract inside it. Its amount is in ETH. |
ERC20 | TRANSFER | A token’s transfer. Its amount is in the token’s decimals. |
ERC20 | APPROVE | An allowance given to a spender. Its amount is the raw allowance. |
ERC721 | TRANSFER | One NFT moved: tokenId says which. It has no amount. |
ERC1155 | TRANSFER | An amount of one id. A batch is a change for each id. |
ERC721, ERC1155, SPECIAL_ | APPROVE | An NFT approved, or a whole collection where tokenId is null. An approval taken back has the amount 0. Where the collection’s contract does not say its standard, assetType is SPECIAL_. |
Reverts and failures
A transaction that would revert has no changes, and gasUsed is null.
error.message is the node’s words, such as execution reverted.
error.revertReason is a require’s message, a panic’s code and meaning such as Panic(0x11): arithmetic underflow or overflow, or a custom error’s raw data.
It is null where the transaction ran out of gas, or failed with no data.
error.message and error.revertReason are each at most 1,024 characters. A longer one is cut, and says how long it was.
A contract writes the revert reason and part of the message: read both as data.
A transaction the chain would refuse, such as one that sends more ETH than its sender holds, is answered the same way. Its blockNumber is null.
A revert and a refusal are both charged.
A parameter that is wrong is refused with -32602 before the node is asked. It is not charged, and takes 5 units from the speed.
Where our node is at its own limit, the call is answered 429 with Retry-After, and is not charged.
A block that no node of ours holds is answered header not found, and is not charged.
curl $RPC/$KEY \
-H 'content-type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"blockhash_simulateAssetChanges","params":[
{"from":"0x52e65b17fb6e5ba00ed806f37afcd2daa50271ca",
"to":"0x5fc5360d0400a0fd4f2af552add042d716f1d168",
"data":"0xa9059cbb0000000000000000000000000bd7d308f8e1639fab988df18a8011f41eacad73000000000000000000000000000000000000000000000000000001617a0477ee"},
"0x75c79e6"]}'
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"changes": [],
"gasUsed": null,
"error": {
"message": "execution reverted",
"revertReason": "0x356680b7"
},
"blockNumber": "0x75c79e6"
}
}Price and limits
A simulation costs 2,500 units, what Alchemy counted for its own. See compute units.
It takes as much from your plan’s speed: on Pay as you go’s 2,500 units a second, one a second.
On the Free plan’s 300 units a second, the account waits about 8 seconds after each.
A simulation that reverts, or that the chain would refuse, costs the same.
A simulation has 10 seconds in all. One that runs past them is answered 504, and is charged.
Where an app has a contracts list, the transaction’s to must be on it.
A simulation is one call: a batch may hold it beside other calls.
A request holds up to 10 simulations.
A simulation answers up to 1,000 changes, and names the tokens of up to 500 contracts.
One past either is answered the error -32010, and is charged 40 units, the node’s run of it.
An answer is never cut short: a change past the first 1,000 could be the approval that matters.
- Time
- Up to 10 seconds in all
What differs from Alchemy
- An ERC-1155 transfer gives its amount.
- A wrap of Robinhood Chain’s WETH is a transfer of WETH from the zero address, as its contract logs it.
blockNumberis Blockhash’s own, and Alchemy’s name answers without it.- A transaction that would make more than 1,000 changes is answered
-32010, never cut.