Nansen Query Documentation
  • Introduction
  • Overview
    • 📍Getting Started
    • 📍Benefits of Curation
  • Data
    • 🗃️Data Sources
    • 🗃️Data Catalog
      • 🗃️Raw Events
      • 🗃️Aggregates
        • Entity Stats
        • Address Stats
        • Token Usage Stats
        • Transaction Stats
        • Address & Their Relationships
      • 🗃️Dex Trades
        • 🗃️Dex Trader P&L
        • 🗃️Dex Trader Use Cases
        • 🗃️Advanced Topics
        • 🗃️Trader P&L FAQ
      • 🗃️Decoded Contracts
      • 🗃️NFTs
      • 🗃️Governance
      • 🗃️Solana
        • 🗃️Solana Aggregates
    • 🗃️Repeated / Nested Fields
    • 🗃️Adding New Projects
    • 🗃️Data Marketplace
  • Web App
    • 🖥️Overview
    • 🖥️Getting Started: Web App
    • 🖥️My Queries
    • 🖥️Query Editor
    • 🖥️Visualizations
    • 🖥️Dashboards
    • 🖥️Dashboard Editor
    • 🖥️Refresh Schedules
    • ⚙️Custom Query APIs
      • ⚙️API Keys
      • ⚙️Execute A Query
      • ⚙️Get Query Results
  • Database Access
    • 📂Database Overview
    • 📂Getting Started: Database
    • 📂Sample Queries
      • 📂Wallet Examples
      • 📂Token Examples
      • 📂Trader P&L
      • 📂Project Examples
      • 📂Solana Queries
      • 📂Blockchain Examples
    • 📂Sample Python Code
      • 📂Wallet Examples
      • 📂Token Examples
    • 📂Cost Optimization
    • 📂Database FAQs
  • Other
    • ⁉️General FAQs
    • 🏷️Wallet Labels
Powered by GitBook
On this page
  1. Database Access
  2. Sample Python Code

Wallet Examples

After completing the authentication process and loading the required packages, you can directly access BigQuery from the Co-lab IDE. Below are some examples:

Sample Code To Track All Token Movement for a Wallet

# Example 1: SQL query moved to colab

result_1 = client.query("""

SELECT
  token_address,
  from_address,
  to_address,
  value,
  DATE(block_timestamp) as date
FROM
  `bigquery-public-data.crypto_ethereum.token_transfers`
WHERE
  from_address = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' or to_address = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
order by 
  DATE(block_timestamp) ASC  

""").result()

Note you have to specify a wallet address.

The result can then be loaded into a pandas dataframe for additional processing.

# Example 1: Moving the query data to a pandas.DataFrame

df_1 = result_1.to_dataframe()

df_1.head()

In this example, we aggregate the token transfers to find the median value of token transfers

# Example 1: Analysing the median number of token transfers over time, by token, and sorting in descending order

df_pivot = pandas.pivot_table(data=df_1, values = ['value'],index=['date'], columns=['token_address'], aggfunc='count')
df_pivot.index = pandas.to_datetime(df_pivot.index)

pandas.DataFrame(df_pivot.median(axis=0).sort_values(ascending=False),columns=['median_num_token_transfers'])
PreviousSample Python CodeNextToken Examples

Last updated 2 years ago

📂
📂
Sample Data From Example 1
Sample Results From the Above Analysis