Start using this API in your app today. Get started for free
This tutorial uses the getTransactionReceipt endpoint.
The transaction hash is a unique identifier that is assigned to every transaction on the blockchain network. In this article, we will explain how you can use Alchemy's getTransactionReceipt API to check the status of a transaction using its transaction hash.
In case you haven't already, install node and npm on your local machine.
Make sure that node is at least v14 or higher by typing the following in your terminal:
node -vIn case you haven't already, sign up for a free Alchemy account.

Alchemy's account dashboard where developers can create a new app on the Ethereum blockchain.
Next, navigate to the Alchemy Dashboard and create a new app.
Make sure you set the chain to Ethereum and the network to Mainnet. Once the app is created, click on your app's View Key button on the dashboard.
Take note of the HTTP URL.
The URL will be in this form: https://eth-mainnet.g.alchemy.com/v2/xxxxxxxxx
You will need this later.
Let's now create an empty repository and install all node dependencies.
Run the following commands in order to create your node project.
mkdir transaction-status-checker && cd transaction-status-checker
npm init -y
npm install --save viem
touch main.jsThis will create a repository named transaction-status-checker that holds all your files and dependencies.
Next, open this repo in your favorite code editor.
We will write all our code in the main.js file.
To check the status of the transaction using its transaction hash, we will use the getTransactionReceipt method.
- This method accepts a transaction hash and returns the transaction receipt, which is an object that contains the details about the transaction. The returned object has a property called
status. - If the value of the
statusproperty is1, it means that the transaction was successful, on the other hand, a value of0signifies that the transaction failed. - If no object (transaction receipt) is returned from the
getTransactionReceiptmethod, it means either the transaction is pending or the hash provided is an invalid/unknown transaction hash.
Add the following code to the main.js file:
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
// Replace with your Alchemy API Key
const apiKey = "demo";
const client = createPublicClient({
chain: mainnet,
transport: http(`https://eth-mainnet.g.alchemy.com/v2/${apiKey}`)
})
// Transaction hash for the transaction whose status we want to check
const txHash = "0xd488331be3a2f9cdd0f2b351f2b13f5151630aaafd2c2b246f7f3cd7fd0b1dfc";
// Getting the status of the transaction using getTransactionReceipt and logging accordingly
const checkTransactionStatus = async () => {
try {
const receipt = await client.getTransactionReceipt({ hash: txHash });
if (!receipt) {
console.log("Pending or Unknown Transaction");
} else if (receipt.status === 'success') {
console.log("Transaction was successful!");
} else {
console.log("Transaction failed!");
}
} catch (error) {
console.log("Pending or Unknown Transaction");
}
};
checkTransactionStatus();Here's an explanation of what the code is doing:
- Imports either Viem or Ethers.js library to interact with Ethereum.
- Configures the client/provider with the Alchemy API key and Ethereum mainnet.
- Defines the transaction hash for the transaction whose status we want to check.
- Calls the
getTransactionReceiptmethod, passing in the transaction hash as an argument. - This returns the transaction receipt for the transaction, which contains the status of the transaction.
- It then logs the status of the transaction to the console according to the value of the
statusproperty. If the receipt isnull, it means that the transaction is either pending or unknown. For Viem, the status is 'success' or 'reverted', while for Ethers.js the status is1for success and0for failure.
Run the script using:
node main.jsIf all goes well, you should see an output with the status of the transaction:
Transaction was successful!In conclusion, checking the status of a transaction using its hash is a simple process. By following the steps outlined in this article, you can easily track the status of your transaction.