Simulates the asset changes resulting from a list of transactions simulated in sequence. Returns a list of asset changes for each transaction during simulation.
Don’t have an API key?
Start using this method in your app today.
Description
Simulates the asset changes resulting from a list of transactions simulated in sequence.
Returns a list of asset changes for each transaction during simulation.
Parameters
Name | Type | Description |
---|---|---|
transactions | array | Transactions list of max 3 transactions to simulate. |
blockIdentifier? | string | Optional block identifier to simulate the transaction in. |
transactions
array object parameters
transactions
array object parametersProperty | Type | Description |
---|---|---|
data? | string | The data associated with the transaction. |
from? | string | The address the transaction is sent from. |
gas? | string | The gas provided for the transaction execution, as a hex string. |
gasPrice? | string | The gas price to use as a hex string. |
to | string | The address the transaction is directed to. |
value | string | The value associated with the transaction as a hex string. |
Response
Property | Type | Description |
---|---|---|
Promise<SimulateAssetChangesResponse[]> | array of object | Returns the transactions response. |
SimulateAssetChangesResponse
object parameters
SimulateAssetChangesResponse
object parametersProperty | Type | Description |
---|---|---|
changes | array | An array of asset changes that resulted from the transaction. |
error? | object | Optional error field that is present if an error occurred. The available parameter in this error response is:message : string The error message. |
gasUsed? | string | The amount of gas used by the transaction represented as a hex string. The field is undefined if an error occurred. |
changes
array property parameters
changes
array property parametersProperty | Type | Description |
---|---|---|
amount? | string | The amount as an integer string. This value is calculated by applying the decimals field to the rawAmount field. Only available on TRANSFER changes for NATIVE and ERC20 assets, or ERC721/ERC1155 disapprove changes (field set to '0'). |
assetType | string | The type of asset from the transaction. |
changeType | string | The type of change from the transaction. |
contractAddress? | string | The contract address of the asset. Only applicable to ERC20, ERC721, ERC1155, NFT and SPECIAL_NFT transactions. |
decimals? | number | The number of decimals used by the ERC20 token. Set to 0 for APPROVE changes. Field is undefined if it's not defined in the contract and not available from other sources. |
from | string | The from address. |
logo? | string | URL for the logo of the asset, if available. Only applicable to ERC20 transactions. |
name? | string | The name of the asset transferred, if available. |
rawAmount | string | The raw amount as an integer string. Only available on TRANSFER changes for NATIVE and ERC20 assets, or ERC721/ERC1155 disapprove changes (field set to '0'). |
symbol? | string | The symbol of the asset transferred if available. |
to | string | The to address. |
tokenId | string | The token id of the asset transferred. Only applicable to ERC721, ERC1155 and SPECIAL_NFT NFTs. |
Example Request and Response
Prerequisite: You will need to install the Alchemy SDK before making requests with it.
The commands for installing it using npm or yarn are given below:
npm install alchemy-sdk
yarn add alchemy-sdk
Request
// Imports the Alchemy SDK
const { Alchemy, Network } = require("alchemy-sdk");
// Configures the Alchemy SDK
const config = {
apiKey: "alchemy-replit", // Replace with your API key
network: Network.ETH_MAINNET, // Replace with your network
};
// Creates an Alchemy object instance with the config to use for making requests
const alchemy = new Alchemy(config);
const main = async () => {
// define the transaction hash
const trnxs =
[
{
tr1: "0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b",
tr2: "0xf02c1c8e6114b1dbe8937a39260b5b0a374432bbrrewn67353841eer3432cb45"
}
]
//Call the method to display the transaction based on the transaction hash
const response = await alchemy.transact.simulateAssetChangesBundle(trnxs)
//Logging the response to the console
console.log(response)
}
main();
Response
[ { changes: [], gasUsed: '0xcf08', error: undefined } ]
Code Sandbox
You can test out the simulateAssetChangesBundle
method using the code sandbox below:
Use Cases
Here are some potential use cases for the simulateAssetChangesBundle
method:
-
Testing: Developers can use
simulateAssetChangesBundle
to test their smart contracts before deploying them to a blockchain network. By simulating the changes that would occur, developers can identify potential errors and debug their code. -
Optimizing asset transactions: Businesses that regularly perform asset transactions, such as banks or trading firms, can use
simulateAssetChangesBundle
to optimize their transaction strategies. By simulating different transactions scenarios, these firms can identify the most efficient ways to move assets between accounts.
Related Methods
Here are the methods related to simulateAssestChanges
:
- simulateAssetChangesBundle: Simulates the asset changes resulting from a single transaction.