Is there a js api that can retrieve recent transactions of a Wallet? Couldn't find such thing on web3.js.
Would be cool if someone could share a workaround!
You can use connection.getSignatureForAddresses to get confirmed signatures for transactions involving an address.
Then use the connection.getTransactions to get the transactions for the given signatures.
const address = new PublicKey("...");
const connection = new Connection("...");
async function getTransactionsForAddress(address) {
const signatures = await connection.getSignaturesForAddress(address);
const transactions = awiat connection.getTransactions(signatures);
console.log({transactions});
return transactions;
};
getTransactionsForAddress(address);
thanks to C.OG:
export const getTransactionsForAddress = async(address: string)=> {
let connection = await getConnection();
const signatures = await connection.getSignaturesForAddress(new solana.PublicKey(address));
let temp: any[] = []; // just a temp array to get the signatures
signatures.map((x) => temp.push(x.signature));
const transactions = await connection.getTransactions(temp);
return transactions;
}
can def be improved, but gets the job done