DEV Community

Mohamed Amine El gaouej
Mohamed Amine El gaouej

Posted on

Build a Simple Solana Wallet Activity Tracker with JavaScript

*# Build a Simple Solana Wallet Activity Tracker with JavaScript
*


Solana provides JSON-RPC methods that developers can use to retrieve public blockchain data.

In this tutorial, we'll build a small Node.js script that retrieves recent transaction signatures for a Solana wallet address.

The goal isn't to create a trading bot. It's to understand how wallet-activity tools begin collecting data.

What we're building

Our script will:

  1. Accept a public Solana wallet address.
  2. Connect to a Solana RPC endpoint.
  3. Request recent transaction signatures.
  4. Print transaction identifiers, timestamps, and statuses.

We'll use the standard fetch API available in modern Node.js versions, so no third-party package is required.

Step 1: Create the project

Create a folder and a JavaScript file:

mkdir solana-wallet-tracker
cd solana-wallet-tracker
Enter fullscreen mode Exit fullscreen mode

Create a file named tracker.mjs.

You can execute it with a current version of Node.js that supports global fetch.

Step 2: Connect to Solana RPC

Solana JSON-RPC supports the getSignaturesForAddress method.

The request accepts a wallet address and optional configuration parameters.

Our implementation:

\\javascript
const endpoint =
process.env.SOLANA_RPC_URL ??
"https://api.mainnet-beta.solana.com";

const address = process.argv[2];

if (!address || !/^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(address)) {
console.error("Provide a valid-looking Solana address.");
process.exit(1);
}`

`
async function getRecentSignatures(address) {
const response = await fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "getSignaturesForAddress",
params: [
address,
{ limit: 10 },
],
}),
});

if (!response.ok) {
throw new Error(`RPC HTTP error: \${response.status}`);
}

const data = await response.json();

if (data.error) {
throw new Error(data.error.message);
}

return data.result ?? [];
}

try {
const transactions =
await getRecentSignatures(address);

for (const tx of transactions) {
console.log({
signature: tx.signature,
time: tx.blockTime
? new Date(tx.blockTime * 1000).toISOString()
: "Unavailable",
status: tx.err ? "Failed" : "Success",
});
}
} catch (error) {
console.error("Request failed:", error.message);
process.exitCode = 1;
}
```
`

The regular expression is only a basic format check. For production applications, use proper public-key validation and handle RPC errors and rate limits more thoroughly.

Step 3: Run the tracker

Execute the script with a public wallet address:

`\bash
node tracker.mjs YOUR_PUBLIC_WALLET_ADDRESS
\`

Replace the placeholder with a valid Solana address.

The script will print recent transaction signatures returned by the RPC endpoint.

Public endpoints may enforce rate limits, so use an appropriate RPC provider for sustained workloads.

Step 4: Understand the response

A signature identifies a transaction.

The response can also contain a block time, confirmation information, and an error field.

But this information is not enough to conclude that a wallet bought or sold a token.

To understand a transaction's behavior, you generally need to retrieve additional transaction details and interpret the relevant instructions and balance changes.

Step 5: Extend the tracker

Potential improvements include:

Transaction detail retrieval

Use the getTransaction RPC method to retrieve instructions, account information, and metadata.

Token balance comparisons

Compare pre-transaction and post-transaction token balances to identify changes.

Program classification

Determine which programs were invoked and whether the transaction involved a known swap mechanism.

Persistent storage

Store processed signatures locally to avoid reprocessing the same transactions repeatedly.

Monitoring

For near-real-time observations, consider subscription mechanisms supported by your RPC provider rather than repeatedly polling the complete history.

Step 6: Avoid misleading interpretations

Wallet tracking applications can make transaction data easier to read, but classification mistakes are possible.

For example:

  • An outgoing transfer isn't necessarily a token sale.
  • An incoming token transfer isn't necessarily a purchase.
  • Transaction success doesn't imply profitability.
  • Observing another wallet's trade doesn't guarantee the same execution conditions.

These limitations are worth considering when building interfaces for traders or researchers.

For an additional explanation of the distinction between transfers, swaps, and trading activity, see this guide to reading Solana wallet transactions.

Conclusion

With a small amount of JavaScript, we can retrieve recent Solana transaction signatures and begin building a wallet activity monitor.

The more difficult part isn't fetching the data. It's accurately interpreting it.

A reliable blockchain analytics tool needs to distinguish observed events from assumptions, especially when users may rely on the information for financial decisions.


Disclosure: I contribute to AxiomTrade Pro, an independent educational website. The linked resource is maintained by that project.

Top comments (0)