Skip to main content

Fetch and display recent transactions

Read real on-chain activity by fetching and exploring the latest transactions for any address on Solana.
Fetch and display recent transactions background
Challenge

Fetch and display recent transactions

The Scenario

Yesterday you read your wallet’s balance from Solana: an account’s balance. But a database isn’t just balances. Every time someone sends SOL, creates a token, or interacts with a program, that action is recorded as a transaction. And just like balances, transaction history is public. Anyone can look up what happened to any address.

In web2 terms, if Day 8 was GET /users/:id/balance, today is GET /users/:id/transactions. Same pattern, richer data.

The Challenge

Using the same project from Day 8, fetch the 5 most recent transaction signatures for a public address on devnet. Display each transaction’s signature, the slot it was confirmed in, and the timestamp.

What You’ll Need

  • Your Day 8 project folder with @solana/kit already installed
  • A terminal
  • A code editor

Steps

In your Day 8 project folder, create a new file called fetch-transactions.mjs:

import { createSolanaRpc, devnet, address } from "@solana/kit";

const rpc = createSolanaRpc(devnet("https://api.devnet.solana.com"));

// Same address from yesterday. Programs have lots of transaction activity.
const targetAddress = address(
  "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
);

// Fetch the 5 most recent transaction signatures for this address
const signatures = await rpc
  .getSignaturesForAddress(targetAddress, { limit: 5 })
  .send();

console.log(
  `\nLast 5 transactions for ${targetAddress}:\n`
);

for (const tx of signatures) {
  const time = tx.blockTime
    ? new Date(Number(tx.blockTime) * 1000).toLocaleString()
    : "unknown";

  console.log(`Signature : ${tx.signature}`);
  console.log(`Slot      : ${tx.slot}`);
  console.log(`Time      : ${time}`);
  console.log(`Status    : ${tx.err ? "Failed" : "Success"}`);
  console.log("---");
}

Run It

node fetch-transactions.mjs

You should see 5 transactions printed to your terminal, each with a signature, slot number, timestamp, and status.

What Just Happened

You called getSignaturesForAddress, one of Solana’s RPC methods for reading transaction history. It returns a list of transaction signatures (unique identifiers for each transaction), ordered from newest to oldest.

A few things to notice:

Transaction signatures are long base-58 strings. They work like transaction IDs. You can paste any signature into Solana Explorer to see the full details of that transaction: who signed it, what instructions it contained, which accounts it touched.

The slot is a sequence number. Solana processes transactions in batches, and each batch gets assigned a slot number. Think of it like an auto-incrementing ID on a database row. Higher slot numbers mean more recent activity. Solana assigns new slot numbers roughly every 400 milliseconds, so the network moves fast.

The blockTime is a Unix timestamp (seconds since January 1, 1970), which is the same format you’d get from Date.now() / 1000 in JavaScript. The code converts it to a human-readable date. Some older transactions may not have a blockTime, which is why the code handles that case.

You queried the Token-2022 program address again. Since other accounts interact with it constantly, it has a steady stream of transaction activity, which makes it a good target for this exercise. Try swapping in a different address from Solana Explorer and see what comes back.

Resources

Submission

Share a screenshot or paste of your terminal output showing the 5 transactions with their signatures, slots, timestamps, and statuses.

Submit your project