Skip to main content
Version: 2.2

How to get a transaction by transaction hash

Step 1: Setup Moralis

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

Step 2: Get a transaction by transaction hash

In order to get a transaction by hash, Moralis provides you a getTransaction endpoint to do so.

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

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

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

const runApp = async () => {
await Moralis.start({
apiKey: "YOUR_API_KEY",
// ...and any other configuration
});

const transactionHash =
"0xaae93882e8a9fe9ff30151853db20e4cd161940757a01744465ab83b751c5875";

const chain = EvmChain.ETHEREUM;

const response = await Moralis.EvmApi.transaction.getTransaction({
transactionHash,
chain,
});

console.log(response.toJSON());
};

runApp();

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:

{
"hash": "0xaae93882e8a9fe9ff30151853db20e4cd161940757a01744465ab83b751c5875",
"nonce": "6637",
"transaction_index": "203",
"from_address": "0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5",
"to_address": "0x388c818ca8b9251b393131c08a736a67ccb19297",
"value": "62754610757602656",
"gas": "30000",
"gas_price": "10350264493",
"input": "0x",
"receipt_cumulative_gas_used": "19314887",
"receipt_gas_used": "22111",
"receipt_contract_address": null,
"receipt_root": null,
"receipt_status": "1",
"block_timestamp": "2022-11-07T08:36:11.000Z",
"block_number": "15916991",
"block_hash": "0xd517ab9abb4beed9efb6b74ecbabc141d8550abe11aedb715ce9d133dcb32c9b",
"transfer_index": [15916991, 203],
"logs": [
{
"log_index": "299",
"transaction_hash": "0xaae93882e8a9fe9ff30151853db20e4cd161940757a01744465ab83b751c5875",
"transaction_index": "203",
"transaction_value": "62754610757602656",
"address": "0x388c818ca8b9251b393131c08a736a67ccb19297",
"data": "0x00000000000000000000000000000000000000000000000000def2fc6a398d60",
"topic0": "0x27f12abfe35860a9a927b465bb3d4a9c23c8428174b83f278fe45ed7b4da2662",
"topic1": null,
"topic2": null,
"topic3": null,
"block_timestamp": "2022-11-07T08:36:11.000Z",
"block_number": "15916991",
"block_hash": "0xd517ab9abb4beed9efb6b74ecbabc141d8550abe11aedb715ce9d133dcb32c9b",
"transfer_index": [15916991, 203, 299]
}
]
}

Congratulations 🥳 you just got the transaction content of a transaction by its transaction hash with only a few lines of code using the Moralis Transaction API!

Youtube Video

API Reference

If you want to know more details on the endpoint and optional parameters, check out:

Support

If you face any trouble following the tutorial, feel free to reach out to our community engineers in our Discord or Forum to get 24/7 developer support.