#crawler #solana #transaction #crawl #pubkey #filter #account

solana-transaction-crawler

A library to make it easier to crawl Solana transactions

8 releases

0.1.0 Mar 21, 2023
0.0.7 Nov 17, 2022
0.0.6 Sep 26, 2022
0.0.4 Aug 3, 2022
0.0.2 Jul 24, 2022

#11 in #pubkey

Download history 28/week @ 2024-07-29 10/week @ 2024-08-05 12/week @ 2024-08-12 9/week @ 2024-08-19 22/week @ 2024-08-26 37/week @ 2024-09-02 34/week @ 2024-09-09 20/week @ 2024-09-16 33/week @ 2024-09-23 37/week @ 2024-09-30 32/week @ 2024-10-07 8/week @ 2024-10-14 22/week @ 2024-10-21 28/week @ 2024-10-28 37/week @ 2024-11-04 43/week @ 2024-11-11

130 downloads per month

Apache-2.0

36KB
609 lines

Solana Transaction Crawler

Minimum Example

use anyhow::Result;
use solana_client::rpc_client::RpcClient;
use solana_transaction_crawler::{
    crawler::{Crawler, IxAccount},
    filters::{IxNumberAccounts, SuccessfulTxFilter, TxHasProgramId},
};
use solana_program::pubkey;

#[tokio::main]
async fn main() -> Result<()> {
    // Set up Solana RPC client.
    let client = RpcClient::new("https://rpc.ankr.com/solana");

    // The pubkey of the account you want to crawl for transactions. In this example we use the DeGods CMV1 pubkey.
    let candy_machine_id = pubkey!("9MynErYQ5Qi6obp4YwwdoDmXkZ1hYVtPUqYmJJ3rZ9Kn");

    // Create the Crawler object.
    let mut crawler = Crawler::new(client, candy_machine_id);

    // Define filters.

    // We only want to crawl transactions that have the program id of the Candy Machine V1 program.
    let has_program_id = TxHasProgramId::new("cndyAnrLdpjq1Ssp1z8xxDsB8dxe7u4HL5Nxi2K5WXZ");

    // This filter gives us only successful transactions, filtering out any with errors.
    let successful_tx = SuccessfulTxFilter;

    // We know the mintNFT instruction has exactly 14 accounts and is the only instruction on that program with that number of accounts.
    let ix_num_accounts = IxNumberAccounts::EqualTo(14);

    // Specify accounts we want to retrieve from the transaction.
    // 'Unparsed' means we have to specify the actual index of the account in the instruction.
    // The mint account is the sixth account in the instruction.
    let mint_account = IxAccount::unparsed("mint", 5);

    // Add filters to Crawler
    crawler
        .add_tx_filter(has_program_id)
        .add_tx_filter(successful_tx)
        .add_ix_filter(ix_num_accounts)
        .add_account_index(mint_account);

    // Run the Crawler.
    let crawled_accounts = crawler.run().await?;

    // We labeled our account "mint" so we look it up by the label.
    let mint_addresses = &crawled_accounts["mint"];
    println!("Items found: {:?}", mint_addresses.len());

    Ok(())
}

Dependencies

~72MB
~1.5M SLoC