Given a PublicKey, how can I view all transactions associated with said PublicKey using web3js?
2 Answers
One solution would be to call getSignaturesForAddress
(https://solana-labs.github.io/solana-web3.js/classes/Connection.html#getSignaturesForAddress). This returns an array of 1000 signatures backwards in time from the provided/most recent confirmed block so if you have more than 1000 transactions in the history for your pubkey you'll need to call this in a loop. It takes an optional SignaturesForAddressOptions
which contains before
, you'll want to pass in the oldest signature from the last response.
Once you have all of your signatures, you can use getTransactions
or getParsedTransactions
(https://solana-labs.github.io/solana-web3.js/classes/Connection.html#getParsedTransactions) to get the transactions associated with your signatures.
-
is the getParsedTransactions meant to provide the from and to address as well? So far no luck Commented Aug 3, 2022 at 18:34
-
yes, getParsedTransactions should provide both to & from addresses.– AkeCommented Dec 28, 2023 at 2:08
there are two rpc endpoints involved here:
https://docs.solana.com/developing/clients/jsonrpc-api#getsignaturesforaddress
https://docs.solana.com/developing/clients/jsonrpc-api#gettransaction
PublicKey
-- some programs/sites don't include it correctly n the transaction and thus you won't be able to get every single event that ever took place.