Skip to main content

Python library for scraping blockchain data from Bitquery

Project description

Scrape Solana Blockchain Data

This python library scrapes blockchain from https://bitquery.io/ from their GraphQL endpoints.

This requires you to supply your own Bitquery API token.

Copyright (c) 2022 Friktion Labs

Functionalities

  • Queries Bitquery for blockchain data
  • Batches queries to get around compute limits

Setup

  1. pip3 install solana-data-scraper
  2. Create an account at https://bitquery.io/
  3. Retrieve API Key
  4. In command line, export BITQUERY_API_KEY=XXXXXXX

Example

import os
from solquery.Query import Query

# Get API key associated with user's environment
API_KEY = os.environ.get("BITQUERY_API_KEY")
print(f"Bitquery API Key used: {API_KEY}")

# Create query object with API key
query = Query(API_KEY)

# Query to get random transfers
QUERY = """
query MyQuery {
  solana(network: solana) {
    instructions: instructions(
      success: {is: true}
      options: {limit: 10}
      time: {after: "2022-04-29T00:00:00"}
      programId: {is: "So1endDq2YkqhipRh3WViPa8hdiSpxWy6z3Z6tMCpAo"}
    ) {
      program {
        id
        name
        parsedName
      }
      action {
        name
        type
      }
      data {
        base58
      }
      external
      transaction {
        signature
        success
        transactionIndex
        feePayer
      }
      accountsCount
    }
  }
}
"""
result = query.run(QUERY, to_df=True)
print(f"Results: {result}")

# Query to get random transfers
QUERY = """
    query MyQuery {
      solana(network: solana) {
        transfers(
          time: {between: ["%s", "%s"]}
          options: {limit: 25000}
          success: {is: true}
          receiverAddress: {is: "DdZR6zRFiUt4S5mg7AV1uKB2z1f1WzcNYCaTEEWPAuby"}
        ) {
          amount
          transaction {
            signer
            signature
          }
          block {
            timestamp {
              iso8601
            }
          }
          currency {
            address
            decimals
          }
        }
      }
    }
"""

# This example takes a long time to run
result = query.run_batch(
    QUERY, "2022-04-28T00:00:00", "2022-05-01T00:00:00", batch_freq="6H"
)
print(f"Results: {result}")
print(result.shape)
result.to_csv("./example.csv", index=False)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

solana-data-scraper-0.0.8.tar.gz (235.8 kB view details)

Uploaded Source

Built Distribution

solana_data_scraper-0.0.8-py3-none-any.whl (235.6 kB view details)

Uploaded Python 3

File details

Details for the file solana-data-scraper-0.0.8.tar.gz.

File metadata

  • Download URL: solana-data-scraper-0.0.8.tar.gz
  • Upload date:
  • Size: 235.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.10 Darwin/21.1.0

File hashes

Hashes for solana-data-scraper-0.0.8.tar.gz
Algorithm Hash digest
SHA256 22268020d7d5ed10712b9f00209d080a5f39ed64c6d69d692d48cf73a9dfc7a5
MD5 7b1c962b265f512c169fd80866fcdba3
BLAKE2b-256 2df70179ed390e3d4e5ec036f7f3c87426cb146fc37b47220e50a80da2d21555

See more details on using hashes here.

File details

Details for the file solana_data_scraper-0.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for solana_data_scraper-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d0a3a063560bf45251993bca7d609c54e21c7dfd9a310e78114ef561ba60806b
MD5 365c8bc9ce2601443ec431f47d1eddb2
BLAKE2b-256 cb2624f7855d97da0effd8cae8df4b5055c55d5d4742bd8e6806dd6294d025d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page