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

Token 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 Trades for a Token

# Example 3: SQL query moved to colab

result_3 = client.query("""

SELECT
  token_address,
  DATE(block_timestamp) as date,
  SUM(CAST(value AS FLOAT64)) AS sum_value

FROM
  `bigquery-public-data.crypto_ethereum.token_transfers`
WHERE
  token_address = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' 

GROUP BY 
  date, token_address

ORDER BY 
  date ASC

""").result()

Note that you have to specify a token address.

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

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

df_3 = result_3.to_dataframe()
df_3['date'] = pandas.to_datetime(df_3['date'])

df_3.head()

We can then create visualizations with the following code.

# Example 3: Visualising token transfer gross value for a specific token, in a line chart

rolling_period = 15

fig = plt.figure()

plt.plot(df_3['date'] ,df_3['sum_value'].rolling(rolling_period).sum() ,'r')

plt.legend((['Gross USDC transfer value, in # of tokens, 15-day rolling period']))
plt.show()
PreviousWallet ExamplesNextCost Optimization

Last updated 2 years ago

📂
📂
Sample Results From Above Example
Sample Line Graph using UDSC Transfer Data