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
  • Latest Block
  • Transactions for a Block
  • Logs for a Contract in a Range
  • Balances for an Address

Was this helpful?

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

General EVM Node Queries

Make any RPC call to an EVM Node using LiveQuery

PreviousWETH Pool BalancesNextAPI Functions

Last updated 1 year ago

Was this helpful?

In the following examples, we will use the available EVM primitives to make calls directly to an EVM blockchain node. We will use Ethereum Mainnet here, but the same queries will work on any LiveQuery supported chain and network because they use generic EVM RPC methods.

We will start small by getting the latest block for Ethereum Mainnet.

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 .

Additionally, please see QuickNode for API credit usage per method. You are unlikely to run into credit issues using these functions, unless you are programmatically accessing the data frequently.

Latest Block

Using the udf_rpc function, we can easily make a call to our ethereum_mainnet node. This method does not require parameters, so we will just pass a null variant as our parameters. This will return in hexadecimal format, so we will need to apply utils.udf_hex_to_int to make it human-readable.

select 
ethereum_mainnet.udf_rpc('eth_blockNumber', [])::STRING AS latest_block_hex,
utils.udf_hex_to_int(latest_block_hex)::int as latest_block_int;

Transactions for a Block

In this example, we will pull the transaction details for a specific block. There are lots of available RPC methods, but here we will use . In order to return the details of the transactions within the block, we will also need to pass the transaction detail flag parameter as true alongside our hex block number.

select 
ethereum_mainnet.udf_rpc('eth_getBlockByNumber', 
    [utils.udf_int_to_hex(17000000), --hex block
    true] -- true for tx details
);

This returns a large JSON Object, filled with arrays. This block contains 102 transactions, so we'd expect 102 items in our transactions array. We could also flatten this our to look at the details for each transaction. We won't do that here, but if you wanted to, you'd need to use lateral flatten. Lets just look at the block details and count the transactions using array_size().

select 
ethereum_mainnet.udf_rpc('eth_getBlockByNumber', [utils.udf_int_to_hex(17000000), true]) as response,
utils.udf_hex_to_int(response:number::string) as block_number,
to_timestamp_ntz(utils.udf_hex_to_int(response:timestamp::string)) as block_timestamp,
array_size(response:transactions) as block_tx_count;

Logs for a Contract in a Range

WITH base AS (
    SELECT 
        '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' AS contract_address,
        17000000 AS start_block_int,
        start_block_int + 100 AS end_block_int,
        utils.udf_int_to_hex(start_block_int) AS start_block_hex,
        utils.udf_int_to_hex(end_block_int) AS end_block_hex
),
raw_logs AS (
    SELECT 
        ethereum_mainnet.udf_rpc_eth_get_logs(OBJECT_CONSTRUCT('address', contract_address, 'fromBlock', start_block_hex, 'toBlock', end_block_hex)) AS eth_logs
    FROM 
        base
)
SELECT 
    value:address::string AS address,
    value:blockNumber::string AS blockNumber,
    value:data::string AS data,
    value:logIndex::string AS logIndex,
    value:topics AS topics,
    value:transactionHash AS transactionHash
FROM 
    raw_logs, 
    LATERAL FLATTEN (input => eth_logs);

Balances for an Address

LiveQuery provides a number of ways to pull balances for an address. In this example, we will use udf_rpc_eth_get_balance and udf_get_token_balance. Lets find the top 10 trades on Uniswapv3 this week, and look at the ETH balance and the token balance the wallet swapped for.

WITH traders AS (
    SELECT 
        tx_hash,
        origin_from_address AS trader, 
        token_in AS token_address, 
        symbol_in,
        amount_in_usd AS swap_amount
    FROM 
        ethereum.core.ez_dex_swaps
    WHERE 
        block_timestamp >= current_date - 7
        AND platform = 'uniswap-v3'
        AND amount_in_usd IS NOT NULL 
    ORDER BY 
        amount_in_usd DESC 
    LIMIT 10
)
SELECT 
    t.*,
    utils.udf_hex_to_int(ethereum_mainnet.udf_rpc_eth_get_balance(trader, 'latest')::string) / pow(10,18) AS eth_balance,
    ethereum_mainnet.udf_get_token_balance(trader, token_address) / pow(10, decimals) AS token_balance
FROM 
    traders t 
JOIN 
    ethereum.core.dim_contracts
ON 
    token_address = address;

We could also look at their balance on block after the swap but giving the functions that block number in hex, like so.

WITH traders AS (
    SELECT 
        tx_hash,
        block_number + 1 AS block_number,
        utils.udf_int_to_hex(block_number + 1) AS block_hex,
        origin_from_address AS trader, 
        token_in AS token_address, 
        symbol_in,
        amount_in_usd AS swap_amount
    FROM 
        ethereum.core.ez_dex_swaps
    WHERE 
        block_timestamp >= current_date - 7
        AND platform = 'uniswap-v3'
        AND amount_in_usd IS NOT NULL 
    ORDER BY 
        amount_in_usd DESC 
    LIMIT 10
)
SELECT 
    t.*,
    utils.udf_hex_to_int(ethereum_mainnet.udf_rpc_eth_get_balance(trader, block_hex)::string) / pow(10,18) AS eth_balance,
    ethereum_mainnet.udf_get_token_balance(trader, token_address, block_number) / pow(10, decimals) AS token_balance
FROM 
    traders t 
JOIN 
    ethereum.core.dim_contracts
ON 
    token_address = address;

Here we will use udf_rpc_eth_get_logs to get the emitted event logs for a contract. We will use the USDC contract starting at block 17 million for 100 blocks. We'll have to flatten the result and pull out the relevant columns. This method uses which does have limitations on large ranges. The toBlock parameter can also be latest, if you are interested in real-time logs.

🧙‍♂️
💡
instructions here
eth_blockNumber
eth_getBlockByNumber
eth_getLogs