0% found this document useful (0 votes)
14 views2 pages

Solana Wallet Transaction Tracer

This document contains JavaScript code for interacting with the Solana blockchain to trace the original wallet from a given target wallet address. It includes functions to fetch transaction history, details, and to recursively trace back to the original wallet based on transaction sources. The main function executes the tracing process and logs the original wallet found.

Uploaded by

arpadk426
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Solana Wallet Transaction Tracer

This document contains JavaScript code for interacting with the Solana blockchain to trace the original wallet from a given target wallet address. It includes functions to fetch transaction history, details, and to recursively trace back to the original wallet based on transaction sources. The main function executes the tracing process and logs the original wallet found.

Uploaded by

arpadk426
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

const { Connection, clusterApiUrl, PublicKey } = require('@solana/web3.

js');

// Create a connection to the Solana cluster


const connection = new Connection(clusterApiUrl('mainnet-beta'), 'confirmed');

// Function to fetch transaction history for a wallet


async function getTransactionHistory(publicKey) {
try {
const signatures = await connection.getConfirmedSignaturesForAddress2(new
PublicKey(publicKey));
return signatures;
} catch (err) {
console.error(`Error fetching transaction history: ${err}`);
return [];
}
}

// Function to fetch transaction details


async function getTransactionDetails(signature) {
try {
const transaction = await connection.getParsedTransaction(signature,
'confirmed');
return transaction;
} catch (err) {
console.error(`Error fetching transaction details: ${err}`);
return null;
}
}

// Function to extract the source wallet from a transaction


function getSourceWallet(transaction) {
try {
const instructions = transaction.transaction.message.instructions;
for (const instr of instructions) {
if (instr.parsed?.type === 'transfer') {
return instr.parsed.info.source;
}
}
return null;
} catch (err) {
console.error(`Error parsing transaction: ${err}`);
return null;
}
}

// Recursive function to trace back to the original wallet


async function traceOriginalWallet(wallet) {
console.log(`Tracing wallet: ${wallet}`);
const signatures = await getTransactionHistory(wallet);

if (signatures.length === 0) {
console.log(`Original wallet found: ${wallet}`);
return wallet; // No prior transactions, this is the original wallet
}

for (const sig of signatures) {


const transaction = await getTransactionDetails(sig.signature);
if (transaction) {
const sourceWallet = getSourceWallet(transaction);
if (sourceWallet) {
return await traceOriginalWallet(sourceWallet);
}
}
}

console.log(`Original wallet determined: ${wallet}`);


return wallet; // If no source wallet is found, assume this is the original
}

// Main function to execute the program


(async () => {
const startingWallet = 'YourTargetWalletAddressHere'; // Replace with your target
wallet address
const originalWallet = await traceOriginalWallet(startingWallet);
console.log('Original Wallet:', originalWallet);
})();

You might also like