3

Trying to get the full transaction history of a wallet address, but get_signatures_for_address() has a limit of 1000 most recent signatures.

How can I get the entire chain of transactions?

Thanks!

2 Answers 2

2

In order to fetch the next 1000 transactions after the last transaction returned, you'll need to use the before filter, where signature is the last signature on the array returned from get_signatures_for_address().

Here is one way to do it in javascript, where it does three fetches before ending in order to ensure that it doesn't end early due to a failed fetch:

const connection = new Connection("https://api.mainnetbeta.solana.com");
let targetAddress = new Publickey("ExamplePublickey");
let signaturesArray = [];
let pullAttempts = 0;
let isEmpty = false;
while (!isEmpty) {
    try {
        const lastSignature = signaturesArray[signaturesArray.length - 1];
        const requestSignatures = await connection.getSignaturesForAddress(pubkey, {
            before: lastSignature,
            limit: 1000
        });

        if (!(requestSignatures.length > 0)) {
            pullAttempts++;
            if (pullAttempts >= 3) {
                isEmpty = true;
            }
        }
        else {
            const newlyFetchedSignatureArray = requestSignatures.map(data => data.signature);
            signaturesArray = signaturesArray.concat(newlyFetchedSignatureArray);
        }
    }
    catch (e) {
        console.log(e);
    }

If you want to go through manually and/or you're using curl or POST requests, here is the proper formatting for the filter. You'd first do a fetch with no filter, then you would do the following, replacing oldestSignaturesOfLastFetch with the last signaturesat the returned array of signatures. I'd highly recommend you use your own personal RPC:

curl https://api.mainnet-beta.solana.com/ \
  -X POST \
  -H "Content-Type: application/json" \
  -d $'[
    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getSignaturesForAddress",
      "params": ["Vote111111111111111111111111111111111111111",{"before": "oldestSignaturesOfLastFetch"}]
      }
  ]'

Hope this helps, I'd recommend in the future adding what language you're trying to program in, so that answers can be targeted to your language.

1

Use this getSignaturesForAddress template to get signatures (transactions) up to a certain limit (default 100000).

It takes connection, address, and maxLength and returns list of signatures

 * @param connection A connection to a fullnode JSON RPC endpoint
 * @param address Address of the Signatures to fetch
 * @param maxLength Max Number of Signatures to fetch (default 100,000)
 */
async function getSignaturesForAddress(
  connection: Connection,
  address: PublicKey,
  maxLength?: number,
): Promise<ConfirmedSignatureInfo[]> {
  const signatures = [];
  let _signatures = await connection.getSignaturesForAddress(address);
  signatures.push(..._signatures);
  while (true) {
    if (_signatures.length >= 1000 && signatures.length < (maxLength | 100000)) {
      const lastSignature = _signatures[_signatures.length - 1];
      _signatures = await connection.getSignaturesForAddress(address, {
        before: lastSignature.signature,
      });
      signatures.push(..._signatures);
      continue;
    }
    break;
  }
  return signatures;
}

I use this for my Solana Wayback Machine library https://github.com/vicyyn/wayback-engine/blob/main/src/utils.ts

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.