Skip to content

Instantly share code, notes, and snippets.

@mgild
Created February 7, 2024 03:51
Show Gist options
  • Save mgild/01bde9c00e0989e21adbc888a5d20b7d to your computer and use it in GitHub Desktop.
Save mgild/01bde9c00e0989e21adbc888a5d20b7d to your computer and use it in GitHub Desktop.
import { Connection, PublicKey } from "@solana/web3.js";
// Assuming you have initialized a connection to a Solana node
const connection = new Connection(
"https://switchboard.rpcpool.com/XXX"
);
// Public key of the program you want to get instructions for
const programId = new PublicKey("FFxRNZyzkQacQnkBD96ksKid4HScE5Bd33gKdyJ4aJyW");
async function loadTransactionLogs(transactionSignature: string) {
try {
// Get transaction details
const transaction = await connection.getTransaction(transactionSignature, {
maxSupportedTransactionVersion: 0,
});
// Check if transaction exists
if (transaction) {
const timestamp = new Date(
Number(transaction.blockTime) * 1000
).toLocaleString("en-US", {
timeZone: "America/New_York",
});
for (const log of transaction.meta!.logMessages!) {
if (log.startsWith("Program log: Received random value:")) {
const logStr = log.replace(
/^Program log: Received random value:/,
""
);
const providedValue = Number(logStr);
if (providedValue >= 100) {
console.log(
`Offending transaction: ${transactionSignature}: Time: ${timestamp}, Slot: ${transaction.slot}, Provided value: ${providedValue}`
);
}
}
}
} else {
console.log("Transaction not found");
}
} catch (error) {
console.error("Error loading transaction logs:", error);
}
}
async function getTransactionSignatures(programId: PublicKey) {
try {
// Get confirmed signatures for transactions involving the given program ID
const signatures = await connection.getConfirmedSignaturesForAddress2(
programId
);
for (let i = 0; i < signatures.length; i++) {
// Load transaction logs for each signature
await loadTransactionLogs(signatures[i].signature);
}
console.log("Transaction signatures associated with the program:");
console.log(signatures);
} catch (error) {
console.error("Error fetching transaction signatures:", error);
}
}
// Call the function to get instructions for the program
(async () => {
getTransactionSignatures(programId);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment