⚡ LiveQuery 🤝 Avalanche Subnets 🔺

    RPC Endpoint

    Here is the general syntax for using LiveQuery's udf_api function:

    live.udf_api(
      [method,]
      url,
      [headers,]
      [data,]
      [secret_name]
    )
    

    For the sake of accessing the RPC endpoints of Avalanche subnets, we should provide information for the method, the URL, and the data.

    Method

    Here, we will use the POST method to access the RPC endpoint.

    URL

    It should be the RPC URL of our desired subnets. This URL can be found within the webpage of each subnet in Avalanche Subnet Explorer.

    Here is a list of RPC URLs for some of the most popular Avalanche subnets:

    • DFK: https://subnets.avax.network/defi-kingdoms/dfk-chain/rpc
    • Dexalot: https://subnets.avax.network/dexalot/mainnet/rpc
    • Beam: https://subnets.avax.network/beam/mainnet/rpc
    • MELD: https://subnets.avax.network/meld/mainnet/rpc
    • Shrapnel: https://subnets.avax.network/shrapnel/mainnet/rpc

    Data

    Here, the data is a JSON object which we can get using another LiveQuery's utility function called udf_json_rpc_call.

    Here is the general syntax for using LiveQuery's udf_json_rpc_call function:

    utils.udf_json_rpc_call(
      method,
      params
      [,id]
    )
    

    Method

    There are multiple RPC methods available that could be used to get the data from the RPC URL. These methods can be found in QuickNode's Documentation. Here is a list of some of these functions that are used in this dashboard:

    • eth_blockNumber
    • eth_getBalance
    • eth_getLogs

    Parameters

    Each method might or might not have a set of parameters that should be passed along for the function to be able to return data. In case the function needs no parameters, you can pass an empty bracket [], and in cases where there are some parameters involved, you can add them inside [].

    Returned Data

    In most cases, the outcome of these functions will be in hexadecimal, so we can use Flipside's Hex Converter Functions to convert the output from hex into our desired format.

    Flipside's LiveQuery is a tool that allows you to query any external API directly within a Flipside SQL query. You can find more info on Flipside's LiveQuery documentation.

    Recently, the Avalanche's subnets RPC endpoint and its Metrics API were made available to query using LiveQuery. This will allow analysts to directly dive into the analysis of Avalanche subnets directly within Flipside's data studio.

    This dashboard aims to provide a helpdesk on how to use these tools to extract statistical data from Avalanche subnets.

    To use the RPC endpoints, there is no need to configure the Node provider when using the LiveQuery. Since these are external APIs, you need to use LiveQuery's user-defined functions (UDF) to extract the data. The two main functions are udf_api and udf_json_rpc_call.

    Metrics API

    Querying data using Avalanche's Metrics API is more straightforward and analysts are able to get their desired data over a certain period. For this matter, only the udf_api function and some hex converters are required.

    In its simplest form, you only need to get the URL where the JSON data is stored:

    select
      live.udf_api(
        'https://metrics.avax.network/v1/cumulative/tx_count/53935'
      )
    

    However, since the data is being clustered into a single array with a JSON format, we need to flatten it in order to be able to access each data point separately:

    with
      metrics_api as (
        select
          live.udf_api(
            'https://metrics.avax.network/v1/tx_count/53935'
          ):data:results as response
      )
    select
      to_timestamp(value:timestamp)::date as date,
      value:value as response_value
    from
      metrics_api,
      table(flatten(input => response)) flattened_response
    order by
      date desc
    
    db_img