2

Hey looking for an alternative to getSIgnaturForAddress which is not limited by 1000 signatures (from newest-old) i wanted to know if there is a way to fetch the entire tx hashes/signature from the time the contract got developed.

0

2 Answers 2

5

AFAIK there's no such function. getSignaturesForAddress returns the transactions in order, newest first. It also takes an optional before parameter, which can be used to fetch the 1000 transactions before a given signature. So the best thing to do is to write a loop/recursion, which passes the last transaction signature as before if you fetch all 1000 transactions.

There's a good example of this in the Solana Pay codebase: https://github.com/solana-labs/solana-pay/blob/master/core/src/findReference.ts#L25 This function is getting the oldest signature for a given address, but it's the same idea.

2

There is no native function at the moment, but you can do something like this:

function getAllTxForAcc(myAcc, connection){
    const batchSize = 1000;
    const res = [];
    let fetched = await connection.getConfirmedSignaturesForAddress2(myAcc, { limit: batchSize });

    // We know we've ran out of sigs when the fetch 
    //returns less sigs than we asked for
    while(fetched.length === batchSize) {
        fetched = await connection.getConfirmedSignaturesForAddress2(
            myKey, { 
                limit: batchSize, 
                before : fetched[fetched.length-1].signature 
            });
        // This can be cleaned up to actually create an array of 
        // sigs rather than array of array of sigs. Left 
        // as an exercise to the reader ;)
        res.push(fetched);
    } 
    return res;    
}
2
  • 1
    I don't think this will work because you're never passing a before parameter to getConfirmedSignaturesForAddress2. If there are >1000 transactions then the fetch will always return the latest 1000 transactions and the loop will never terminate.
    – Callum M
    Jul 19, 2022 at 12:44
  • 1
    You're correct, I've adjusted my answer Jul 19, 2022 at 12:47

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