Skip to main content

Don't have an API key yet?

Sign-up to Moralis to get your free API key and start building today.

Get Your Free API Key
Version: 2.2

How to Get Internal Transactions by Hash

Step 1: Set Up Moralis

Read the article Setting Up Moralis: Getting Started and make sure to finish all the steps. Only after that can you go ahead and complete this guide.

Step 2: Get Internal Transactions by Hash

In this tutorial, you will explore how to check internal transaction details by hash ID using the Moralis Web3 API.

To include internal transactions in the API response, you have two options:

  1. Specific Endpoint: You can use a dedicated endpoint called getInternalTransactions. This endpoint is designed specifically to retrieve details of internal transactions. By using this endpoint, you can directly fetch information related to internal transactions without the need for additional query parameters.

  2. Query Parameter Inclusion: Alternatively, you can include a specific query parameter, such as include=internal_transactions, when making requests to relevant endpoints. This instructs the Moralis API to include details of internal transactions in the response along with external transactions.

tip

If you don't have the transaction hash, you can use the getWalletTransactions endpoint to find it. In the provided example response, you can easily find the transaction hash within the hash field. Alternatively, you can use Etherscan. On Etherscan, selecting any transaction will reveal the transaction hash at the top of the page.

Full Example Script

Our script, written in JavaScript, TypeScript, and Python, demonstrates how to find an internal transaction by hash ID on the blockchain using Moralis' getInternalTransactions endpoint.

Here, you'll need two parameters: transactionHash and chain.

Once you've obtained both transactionHash and chain, you can copy the following code:

// Import the Moralis library and EvmChain module
const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");

// Asynchronous function to run the application
const runApp = async () => {
// Initialize Moralis with your API key
await Moralis.start({
apiKey: "YOUR_API_KEY",
// ...and any other configuration
});

// Specify the transaction hash to be looked up
const transactionHash =
"0xae5f9a43f424624376ea7479ce7b0ab25e9eba11f1c4791ec4e68f0206b5e071";

// Set the blockchain (e.g., Ethereum)
const chain = EvmChain.ETHEREUM;

// Use the Moralis API to get internal transactions associated with the specified hash
const response = await Moralis.EvmApi.transaction.getInternalTransactions({
transactionHash,
chain,
});

// Print the response in JSON format
console.log(response.toJSON());
};

// Execute the application function
runApp();

Step-by-Step Explanation: How to Check Internal Transactions with Hash ID

  1. Initialize Moralis: Using your unique API key, initialize Moralis in your preferred programming language - such as JavaScript, TypeScript, or Python. This foundational step establishes the connection with Moralis services.

  2. Specify Wallet Address: Identify the wallet address for which you intend to retrieve internal transactions by hash ID. This address is directly associated with the transactions you aim to explore.

  3. Set Blockchain: Define the blockchain on which the transactions occurred. Specify the appropriate chain parameter, such as "eth" for Ethereum, ensuring accurate retrieval of relevant data.

  4. Extract Transaction by Hash ID: Utilize the getInternalTransactions endpoint to retrieve comprehensive details of the specified transaction. This may encompass vital information such as sender, receiver, amount, and timestamp.

  5. Print or Process Hash IDs: Once the internal transactions are fetched, print the extracted hash IDs or process them based on your specific requirements. This step is crucial for developers who want to integrate this functionality into their applications.

Step 3: Run the Script

To run the script, enter the following command:

node index.js

In your terminal, you should see the following JSON response:

[
{
"transaction_hash": "0xae5f9a43f424624376ea7479ce7b0ab25e9eba11f1c4791ec4e68f0206b5e071",
"block_number": 16768916,
"block_hash": "0xc4d8920e33578f4f0d0341738e5fb1d744b0d6bfdc78fc24ce4d4cb593011959",
"type": "STATICCALL",
"from": "0x7becef300c5873ba138d29e0d5e5bf2db1d5e983",
"to": "0x0000000000000000000000000000000000000001",
"value": "0",
"gas": "36019",
"gas_used": "3000",
"input": "0x5ac2dc77eb0e3a92a62f7fd96f9bd6aaa8a2d4b5755300687d252fe3ed94a842000000000000000000000000000000000000000000000000000000000000001beee44e8fea3feec053e41bb2e1300f960f5fccb46e0592fa81ad2e778725b84c4237c475a8354bfa465d1a72e59fb4ea88943d10d6d35bc24f3a55627fb0c325",
"output": "0x00000000000000000000000003ce74eb2e0e1f4ef6b079fe54112f52bfa34be6"
},
{
"transaction_hash": "0xae5f9a43f424624376ea7479ce7b0ab25e9eba11f1c4791ec4e68f0206b5e071",
"block_number": 16768916,
"block_hash": "0xc4d8920e33578f4f0d0341738e5fb1d744b0d6bfdc78fc24ce4d4cb593011959",
"type": "STATICCALL",
"from": "0x7becef300c5873ba138d29e0d5e5bf2db1d5e983",
"to": "0x0000000000000000000000000000000000000001",
"value": "0",
"gas": "32177",
"gas_used": "3000",
"input": "0x5ac2dc77eb0e3a92a62f7fd96f9bd6aaa8a2d4b5755300687d252fe3ed94a842000000000000000000000000000000000000000000000000000000000000001b6281037b7de24db835d162860a4f7ba9517ff4ded3372f253713d690c3cea2f124e3ad1299ef0f7d4899ac2d9e5f074592f093fbcd6f7d567e7cf25d820b3ade",
"output": "0x000000000000000000000000c9e9d6ce434c4c853ccc65bf705801e2d051ba15"
}
]

Congratulations 🥳! You have successfully retrieved the internal blockchain transaction with hash ID using the Moralis Wallet API.

Get 24/7 Developer Support

Should you encounter any challenges while following this tutorial, our community engineers are here to assist you. Reach out to us on Discord or in our forum to receive 24/7 developer support. Your success is our priority!

API Reference

If you want to explore more details about other blockchain endpoints and optional parameters, refer to our API Reference page.