2

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!

2 Answers 2

2

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);
2
  • Thanks! Updated your code so would be helpful to others: ``` 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; } ```
    – Solomon
    Commented Aug 15, 2022 at 8:30
  • looks ugly, will post separately
    – Solomon
    Commented Aug 15, 2022 at 8:32
1

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.