3

I have an app that shows a user's previous transactions. Right now, after a new transaction is made in the app, when signature is confirmed, I'll run:

const rawTransaction = await connection.getParsedTransaction(signature, {});

And add this to the list of list of previous transactions.

Likewise, if a transaction is made for another app, I'll need to run connection.getSignaturesForAddress() and connection.getParsedTransactions() to pull the latest transactions in my app.

But is there a better way? Specifically can I receive a message telling me about the new transaction (rather than polling for the transaction)?

1 Answer 1

2

You can subscribe to program logs that mention the user's pubkey.

Using @solana/web3.js, you might do this:

const subscriptionId = connection.onLogs(
  walletAddress,
  ({signature}) => {
    console.log(signature);
  },
);

See the onLogs() documentation for more options.

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.