Flipside Docs
  • Welcome to Flipside!
    • Welcome to Flipside
    • Growth Services
    • Data
      • Choose your Flipside plan
        • Free
        • Builder
        • Pro
          • Get Started in Snowflake
          • Incremental Table Pattern
          • Copy Data from Snowflake to AWS
          • Copy Data from Snowflake to GCP
          • Copy Data from Snowflake to Azure
        • Snowflake Data Shares
          • Mounting a Snowflake Data Share
    • Earn
    • Community
  • Data
    • Flipside Data
      • Table Docs by Chain
      • Data Modeling Approach
      • Labels
        • Centralized Exchange Label Type
        • Decentralized Exchange Label Type
        • Operator Label Type
        • Chain Admin Label Type
        • Decentralized Finance Label Type
        • NonFungible Tokens Label Type
        • Games Label Type
        • Bridge Label Type
        • Decentralized Applications Label Type
        • Token Label Type
        • Flotsam Label Type
      • Tags
      • Table Freshness Targets
      • Contribute to Our Data
        • Contract Decoding & ABIs
        • How to Add Your Own Tags
        • Community Curation
          • Getting Started
            • Contribution Workflow
          • Model Standards
            • dbt Tips
          • PR Checklist
    • Data Products
      • Data Studio (SQL Analysts)
        • Get Started
          • Write/fork your first query
        • Flipside AI
        • Studio in Depth
          • Query Editor
            • Query Referencing
            • Pro Tips for Querying
            • Keyboard Shortcuts
            • Hex-to-Integer Function
          • Create a Chart
            • Advanced Visualization
          • Build a Dashboard
            • Markdown Reference
          • Team Accounts
        • Tutorials
          • How to Analyze Web3 Data
          • Video Tutorials
            • Overview of Schemas & Tables
            • Ethereum Tutorials
              • Getting Started with Decoded Ethereum Events
              • Getting Started with Ethereum Balances
              • Block Level and Daily Balances
              • Finding Centralized Exchange Flows
            • Solana Tutorials
              • Solana Schema & Tables: Video Walkthrough
              • Solana Specialty Tables: Video Walkthrough
              • Exploring Transactions in solana.events
            • THORChain Tutorials
              • THORChain Schema & Tables
              • Calculating IL for THORChain
          • More Tools & Resources
        • Get Inspired
      • LiveQuery
        • Get Started
        • LiveQuery in Depth
          • Functions
            • 🤝Partner Functions
            • 🧙‍♂️EVM Functions
              • 💡Seaport: Real-time Orders
              • 💡WETH Pool Balances
              • 💡General EVM Node Queries
            • 🤖API Functions
              • 💡Query TheGraph
              • 💡Query Defi Llama
            • ⚙️Utility Functions
              • 💡Hex Converters
              • 💡JSON RPC Request Builder
              • 💡EVM Logs Decoder
              • 💡Keccak256 Encoder
          • QuickNode Setup Guide
        • Secrets Manager
        • Get Inspired
      • Snowflake
      • API/SDK (Developers)
        • Get Started - Your first API call in < 2 min
        • SDK in Depth
          • JSON RPC methods
          • Run A Query
          • Query Results
          • Pagination
          • Sorting
          • Filtering
          • Query Seconds
          • Caching (maxAgeMinutes)
          • Rate Limits
          • Errors
          • More Examples
          • Archive
            • [ARCHIVED] JS/TS SDK
            • ShroomDK Migration Guide
            • [LEGACY] R
        • Tutorials
          • Have Questions?
        • Get Inspired
    • Insights and Tools
  • Earn
    • Flipside Earn
    • Onchain Rewards
      • Quests
    • Analyst Rewards
      • Top Dashboards
        • Top Dashboard Guidelines
        • Skill Tree
      • Ambassador Program
      • Direct to Analyst Commissions
    • Wallet Management
    • Tax Center
  • Support
    • General Support
    • Open a Ticket
      • That email doesn't look quite right
    • 🌟Product Special Releases
      • 2025
        • 2025-02-06 | EVM Blockchain Standardization
          • Table Change Overview
      • 2024
        • 2024-06-13 | Solana native and wrapped addresses
        • 2024-05-01 | Improvements to Pricing Data
          • Actions for Data Studio Users
          • Actions for API Users
          • Action for Data Share Users
    • 🗒️Release Notes
      • 2025
        • 2025-05-01 | Release Notes
        • 2025-04-17 | Release Notes
        • 2025-04-03 | Release Notes
        • 2025-03-20 | Release Notes
        • 2025-03-06 | Release Notes
        • 2025-02-20 | Release Notes
        • 2025-02-06 | Release Notes
        • 2025-01-23 | Release Notes
      • 2024
        • 2024-12-24 | Release Notes
        • 2024-12-12 | Release Notes
        • 2024-11-27 | Release Notes
        • 2024-11-14 | Release Notes
        • 2024-10-31 | Release Notes
        • 2024-10-03 | Release Notes
        • 2024-10-17 | Release Notes
        • 2024-09-19 | Release Notes
        • 2024-09-05 | Release Notes
        • 2024-08-22 | Release Notes
        • 2024-08-08 | Release Notes
        • 2024-07-25 | Release Notes
        • 2024-07-11 | Release Notes
        • 2024-06-27 | Release Notes
        • 2024-06-14 | Release Notes
        • 2024-05-30 | Release Notes
        • 2024-05-16 | Release Notes
        • 2024-05-02 | Release Notes
        • 2024-04-18 | Release Notes
        • 2024-04-05 | Release Notes
        • 2024-03-18 | Release Notes
        • 2024-03-05 | Release Notes
        • 2024-02-20 | Release Notes
        • 2024-02-05 | Release Notes
    • 📊Studio Change log
  • Flipside Community
    • Get Started
    • Ambassador Program
    • Join Our Discord
    • Join Our Guild
Powered by GitBook
On this page
  • Query a Pool's Balance for a Single Token
  • Query Multiple Pool Balances Simultaneously using Dynamic Inputs

Was this helpful?

  1. Data
  2. Data Products
  3. LiveQuery
  4. LiveQuery in Depth
  5. Functions
  6. EVM Functions

WETH Pool Balances

PreviousSeaport: Real-time OrdersNextGeneral EVM Node Queries

Last updated 1 year ago

Was this helpful?

In this example, we'll use the LiveQuery table function tf_latest_token_balance to retrieve the real-time balance of Uniswap Pools.

If you'd like to follow along in your own Flipside Studio Account please make sure you've added the QuickNode integration to your account. QuickNode .

Let's start with a simple example, retrieve the balance of WETH and USDC on the WETH/USDC pool.

Pool Address: 0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640

WETH Token Address: 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

USDC Token Address: 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48

SELECT 
 *
FROM table(
  ethereum_mainnet.tf_latest_token_balance(
    -- pool address
    '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640',
    -- an array of addresses we want to know the pool's balance of
    [                                              
     '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', -- WETH
     '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'  -- USDC
    ]                                   
  )
)

Note you must wrap the call to the function in TABLE() since this function returns a table structure.

This function will always return a table with the following columns:

Column
Type

status

varchar

blockchain

varchar

network

varchar

wallet_address

varchar

token_address

varchar

symbol

varchar

raw_balance

varchar

balance

float

The function supports a few overloads. An overload means the function can take different combinations of inputs. Here are a few overload examples:

Query a Pool's Balance for a Single Token

SELECT 
 *
FROM table(
  ethereum_mainnet.tf_latest_token_balance(
    '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640', -- pool address
    '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', -- WETH address
  )
)

Query Multiple Pool Balances Simultaneously using Dynamic Inputs

In this example, we'll pull the latest WETH balance for all WETH pools that have done greater than $10 million in volume over the past week.

We will first fetch the pools using Flipside's ethereum.core.ez_dex_swaps table and then use the table function ethereum_mainnet.tf_latest_token_balance() to retrieve the balance for each pool involving WETH.

WITH pools AS (
  SELECT 
    contract_address as pool_address, 
    sum(amount_out_usd) as volume_usd 
  FROM ethereum.core.ez_dex_swaps
  WHERE 
    -- filter to only pools involving `WETH`
    (token_out = lower('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2') OR token_in = lower('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'))
    AND block_timestamp >= GETDATE() - interval '1 week' 
    AND amount_out_usd IS NOT NULL
  -- filter to only pools with greater than $10m in USD volume
  GROUP BY pool_address HAVING volume_usd >= 10000000
)
SELECT
  *
FROM table(ethereum_mainnet.tf_latest_token_balance(
  -- generate an array of pool addresses to pass to the function
  (SELECT array_agg(distinct pool_address) FROM pools),
  -- WETH token address
  '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
))

The above query will return the WETH balance for every pool that has had over $10 million in trading volume over the past week.

🧙‍♂️
💡
instructions here