Skip to content

Instantly share code, notes, and snippets.

@mertimus
Created August 16, 2022 17:51
Show Gist options
  • Save mertimus/3cf3026c28f78acb70803415bbec048d to your computer and use it in GitHub Desktop.
Save mertimus/3cf3026c28f78acb70803415bbec048d to your computer and use it in GitHub Desktop.

Revisions

  1. mertimus created this gist Aug 16, 2022.
    27 changes: 27 additions & 0 deletions getAllTxns.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    const axios = require('axios');

    const apiURL = 'https://api.helius.xyz/v0/addresses/';
    const address = '8cRrU1NzNpjL3k2BwjW3VixAcX6VFc29KHr4KZg8cs2Y';
    const resource = '/transactions';
    const options = '?api-key=d63a869e-bb73-4792-ae33-a06f4c72f226&before=';
    let lastTxn = '';
    const allTxns = [];

    const getAllTxns = async () => {
    while(true) {
    console.log("fetching transactions...")
    const { data } = await axios.get(apiURL + address + resource + options + lastTxn)

    if(!data.length) {
    console.log("got all transactions")
    break
    }

    lastTxn = data[data.length - 1].signature
    allTxns.push(...data);
    }

    console.log("Total transactions: ", allTxns.length)
    }

    getAllTxns()