Cover Image for Arbitrum API - Tokens, NFTs, DEX, Balances & More​

Arbitrum API - Tokens, NFTs, DEX, Balances & More​

Arbitrum
Blockchain
NFTs
Tokens
DEX Trades

Introduction

Over the past year, there's been a big push to make Ethereum work better. Some people are doing this by changing the core of Ethereum, and others are using a special kind of solution called "Layer 2" or "L2." Some of the popular L2 solutions are Optimism, Arbitrum, Polygon, and more.

In this article, we're going to learn how to get data from Arbitrum, which is one of the most popular L2 solutions for Ethereum. We'll use Bitquery's GraphQL API to do this. Bitquery gives us data about things like transactions, token transfers, DEX trades, and more, all from Arbitrum.

What is Arbitrum?

Arbitrum or Arbitrum One came onto the scene in 2021. It's the L2 solution for Ethereum, which allows faster and cheaper transactions for the users. On Ethereum, it can be slow and costly to do things. But with Arbitrum, it's way faster and cheaper.

Arbitrum uses an architecture called "optimistic rollup". This makes it possible to use a network that can handle way more transactions per second (TPS) than Ethereum's main network while borrowing security from the Ethereum mainnet. Ethereum usually does about 15-25 TPS, but Arbitrum can do around 40,000 TPS – that's super fast!

The best part for developers is that Arbitrum works with pretty much all the tools you use for Ethereum development. So, if you've built something using Ethereum's language, Solidity, you can move it to Arbitrum without changing much.

To see live Arbitrum updates, you can check out our Arbitrum explorer.

Let’s write some queries to get data from Arbitrum. If you have issue with any of the queries, you refer to our Arbitrum docs which should resolve those issues. We also have extensive list example queries for Arbitrum in the documentaiton.

Arbitrum Balances API

With the Balances API, we can fetch the balance of any token, like ERC20 or native token (ETH), for any address or list of addresses.

How to Check Ethereum Balance of an Address on Arbitrum

Even though Arbitrum is Layer 2, the native currency for Arbitrum is Ethereum (ETH). Native currency is the token that is used to pay off the network fees.

Let's query ETH balance of Binance Hot Wallet (0xB38e8c17e38363aF6EbdCb3dAE12e0243582891D).

Open Ethereum balance query in the IDE.

{
  EVM(dataset: combined, network: arbitrum) {
    BalanceUpdates(
      where: {BalanceUpdate: {Address: {is: "0xB38e8c17e38363aF6EbdCb3dAE12e0243582891D"}}, Currency: {Native: true}}
    ) {
      Currency {
        SmartContract
        Name
        Symbol
        Fungible
      }
      balance: sum(of: BalanceUpdate_Amount)
    }
  }
}

By adding Currency filter and setting Native to true, we can get the Ethereum Balance of an address.

Checking Token Balances on Arbitrum

From the above query, if we remove the Currency filter, we will get balances for all the tokens that address holds.

Open query for getting token balances for all tokens held by the address in the IDE.

{
  EVM(dataset: combined, network: arbitrum) {
    BalanceUpdates(
        where: {
            BalanceUpdate: {
                Address: {
                    is: "0xB38e8c17e38363aF6EbdCb3dAE12e0243582891D"
                }
            }
        }
    ) {
      Currency {
        SmartContract
        Name
        Symbol
        Fungible
      }
      balance: sum(of: BalanceUpdate_Amount)
    }
  }
}

Checking USDT Balance on Arbitrum

If you want USDT balance for the Address, then you can add the Currency filter along with the address of the token smart contract. USDT token address on Arbitrum is 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9.

Open USDT balance query in the IDE.

{
  EVM(dataset: combined, network: arbitrum) {
    BalanceUpdates(
        where: {
            BalanceUpdate: {
                Address: {
                    is: "0xB38e8c17e38363aF6EbdCb3dAE12e0243582891D"
                }
            }, 
            Currency: {
                SmartContract: {
                    is: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"
                }
            }
        }
    ) {
      Currency {
        SmartContract
        Name
        Symbol
        Fungible
      }
      balance: sum(of: BalanceUpdate_Amount)
    }
  }
}

Arbitrum DEX API

Bitquery provides DEX trading data from DEX's on Arbitrum like 1inch, Uniswap, etc. Let's see some examples of how to query Arbitrum data using Bitquery APIs. Let's query data from different Arbitrum DEX.

Top Traded Tokens on Arbitrum

Top traded tokens will be tokens with the most number of trades, so we are going to get the number of trades for each token (count) and arrange the results in descending order of the count.

Open the top traded tokens query in the IDE.

{
  EVM(dataset: combined, network: arbitrum) {
    DEXTrades(
      limit: {count: 10}
      orderBy: {descendingByField: "count"}
      where: {Block: {Date: {since: "2023-08-01"}}}
    ) {
      count
      Trade {
        Buy {
          Currency {
            Name
            Symbol
            SmartContract
          }
        }
      }
    }
  }
}

Recent Uniswap Trades on Arbitrum

If you want the latest trades from a particular DEX, you can set the name of the DEX from which you want the trades. We will get the latest trades from Uniswap V3, whose name is uniswap_v3 in our API.

Open latest Uniswap trades query in the IDE.

{
  EVM(dataset: combined, network: arbitrum) {
    DEXTrades(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
      where: {Block: {Date: {after: "2023-09-11"}}, Trade: {Dex: {ProtocolName: {is: "uniswap_v3"}}}}
    ) {
      Block {
        Time
      }
      Trade {
        Buy {
          Amount
          Buyer
          Currency {
            Name
            SmartContract
          }
          Price
        }
        Dex {
          ProtocolName
          SmartContract
          ProtocolVersion
          Pair {
            Name
            SmartContract
          }
        }
        Sell {
          Amount
          Buyer
          Currency {
            Name
            SmartContract
          }
          Price
        }
      }
    }
  }
}

You can also query from Uniswap V2 ( uniswap_v2 ), PancakeSwap (pancake_swap_v3), Balancer V2 (balancer_v2), Curve (curve_v1) and many more.

Also Read: How to Track liquidity for token pairs on Uniswap

Recent Trades for a Specific Token on Arbitrum

You can also get the latest trades for a particular token. In this query, we will query latest trades for UNI token, 0xFa7F8980b0f1E64A2062791cc3b0871572f1F7f0.

This query gives us all the details about trades that involve UNI tokens, like the traded amount, the side of the trade, like buy or sell, and much more.

Open latest trades for the specified token query in the IDE.

{
  EVM(dataset: combined, network: arbitrum) {
    DEXTradeByTokens(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
      where: {Trade: {Currency: {SmartContract: {is: "0xFa7F8980b0f1E64A2062791cc3b0871572f1F7f0"}}}}
    ) {
      Block {
        Time
      }
      Trade {
        Amount
        Buyer
        Currency {
          Name
          SmartContract
        }
        Dex {
          ProtocolName
          SmartContract
        }
        Price
        Seller
        Side {
          Type
        }
      }
    }
  }
}

OHLC Data for Arbitrum DEX Trades

OHLC (Open, High, Low, Close) data gives us those price points for a token in a given timeframe. You can see this in a candlestick chart.

In this query, we will get OHLC data for WETH-UsDC trading pair for hourly timeframe. To get data for different intervals, you can change interval value of Time field.

Open OHLC Arbitrum DEX trades query in the IDE.

{
  EVM(dataset: combined, network: arbitrum) {
    DEXTradeByTokens(
        limit: {count: 10}
        orderBy: {descendingByField: "Block_Time"}
        where: {
            Trade: {
                Side: {
                    Currency: {
                        SmartContract: {
                            is: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831"
                        }
                    }
                }, 
                Currency: {
                    SmartContract: {
                        is: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1"
                    }
                }
            }
        }
    ) {
      Block {
        Time(interval: {in: minutes, count: 60})
      }
      volume: sum(of: Trade_Amount)
      OHLC: Trade {
        high: Price(maximum: Trade_Price)
        low: Price(minimum: Trade_Price)
        open: Price(minimum: Block_Number)
        close: Price(maximum: Block_Number)
      }
      Trade {
        Currency {
          Name
          SmartContract
        }
        Side {
          Currency {
            Name
            SmartContract
          }
        }
      }
      count
    }
  }
}

Arbitrum Token Transfers API

The Bitquery API also provides data for Token Transfers for Fungible Tokens (ERC20), Non-Fungible Tokens (ERC721), and Native token. If you want the latest USDC transfers, the number of USDC token holders, etc., you can query those using the Bitquery Arbitrum API. Let's explore token transfers by writing queries.

Latest Token Transfers on Arbitrum

With the token transfers API, we can specify the token address for which we need data. In this query, we will get latest Arbitrum token (ARB) transfers from Arbitrum network.

Open latest token transfers query in the IDE.

{
  EVM(dataset: combined, network: arbitrum) {
    Transfers(
        limit: {count: 10}
        orderBy: {descending: Block_Time}
        where: {
            Transfer: {
                Currency: {
                    SmartContract: {
                        is: "0x912CE59144191C1204E64559FE8253a0e49E6548"
                    }
                }
            }, 
            Block: {
                Date: {
                    after: "2023-08-01"
                }
            }
        }
    ) {
      Block {
        Time
      }
      Transfer {
        Amount
        Currency {
          Decimals
          Name
          SmartContract
          Symbol
        }
        Sender
        Receiver
      }
      Transaction {
        Hash
        To
        From
        Value
        Gas
        GasFeeCap
        GasPrice
        GasTipCap
      }
    }
  }
}

Top Arbitrum Token Holders

In this query, we will query top holders of Arbitrum token (0x912CE59144191C1204E64559FE8253a0e49E6548)

Open Arbitrum token holders query in the IDE.

{
  EVM(dataset: combined, network: arbitrum) {
    BalanceUpdates(
      orderBy: {descendingByField: "Balance"}
      limit: {count: 10}
      where: {Currency: {SmartContract: {is: "0x912ce59144191c1204e64559fe8253a0e49e6548"}}}
    ) {
      Balance: sum(of: BalanceUpdate_Amount, selectWhere: {gt: "0"})
      BalanceUpdate {
        Address
      }
    }
  }
}

Recent Token Transfers for a Wallet

The Token Transfers API allows us to get transfers for all tokens from one address. This API has a limitation where you can only incoming or outgoing transfers in one query so we while writing query we will combine queries into one.

Open recent token transfers query in the IDE.

{
  EVM(dataset: combined, network: arbitrum) {
    sent: Transfers(
        limit: {count: 10}
        orderBy: {descending: Block_Time}
        where: {
            Transfer: {
                Sender: {
                    is: "0xB38e8c17e38363aF6EbdCb3dAE12e0243582891D"
                }
            }, 
            Block: {
                Date: {
                    after: "2023-08-01"
                }
            }
        }
    ) {
      Transfer {
        Amount
        Currency {
          Decimals
          Name
          SmartContract
          Symbol
        }
        Sender
        Receiver
      }
      Transaction {
        Hash
        To
        From
        Value
        Gas
        GasFeeCap
        GasPrice
        GasTipCap
      }
    }
    received: Transfers(
        limit: {count: 10}
        orderBy: {descending: Block_Time}
        where: {
            Transfer: {
                Receiver: {
                    is: "0xbf22f0f184bccbea268df387a49ff5238dd23e40"
                }
            }, 
            Block: {
                Date: {
                    after: "2023-08-01"
                }
            }
        }
    ) {
      Transfer {
        Amount
        Currency {
          Decimals
          Name
          SmartContract
          Symbol
        }
        Sender
        Receiver
      }
      Transaction {
        Hash
        To
        From
        Value
        Gas
        GasFeeCap
        GasPrice
        GasTipCap
      }
    }
  }
}

Arbitrum NFT API

As we have learned above, the Transfers API allows us to get NFT (ERC721) Transfers. In this section, we will write some queries to get data related to Arbitrum NFT.

Popular NFTs on Arbitrum

In this query, we will get the top NFTs on Arbitrum based on the number of transfers.

Open query for most popular NFTs on Arbitrum in the IDE.

{
  EVM(dataset: combined, network: arbitrum) {
    Transfers(
        orderBy: {descendingByField: "count"}
        limit: {count: 10}
        where: {
            Block: {Date: {since: "2023-08-01", till: "2023-08-10"}}, 
            Transfer: {Currency: {Fungible: false}}
        }
    ) {
      Transfer {
        Currency {
          Symbol
          SmartContract
          Name
        }
      }
      count
      senders: uniq(of: Transfer_Sender, method: approximate)
      receivers: uniq(of: Transfer_Receiver, method: approximate)
      ids: uniq(of: Transfer_Id, method: approximate)
      ChainId
    }
  }
}

Newly Created NFTs on Arbitrum

There are many NFTs minted daily, let's try to get newly minted NFTs using our Events API.

When an NFT is minted, each smart contract emits Transfer event. Transfer event has 3 field: From, To and Value.

For newly minted NFTs, the From value will be 0x0000000000000000000000000000000000000000.

With all the above details, we can write the query to get newly minted NFTs.

Open newly created NFTs query in the IDE.

{
  EVM(dataset: combined, network: arbitrum) {
    Events(
        where: {
            Log: {
                Signature: {
                    Name: {
                        is: "Transfer"
                    }
                }
            }, 
            Block: {
                Date: {
                    after: "2023-09-11"
                }
            }, 
            Arguments: {
                startsWith: {
                    Value: {
                        Address: {
                            is: "0x0000000000000000000000000000000000000000"
                        }
                    }
                }
            }
        }
        orderBy: {descending: Block_Time}
        limit: {count: 10}
    ) {
      Arguments {
        Name
        Type
        Value {
          ... on EVM_ABI_Integer_Value_Arg {
            integer
          }
          ... on EVM_ABI_String_Value_Arg {
            string
          }
          ... on EVM_ABI_Address_Value_Arg {
            address
          }
          ... on EVM_ABI_BigInt_Value_Arg {
            bigInteger
          }
          ... on EVM_ABI_Bytes_Value_Arg {
            hex
          }
          ... on EVM_ABI_Boolean_Value_Arg {
            bool
          }
        }
      }
      Block {
        Time
      }
      Log {
        Signature {
          Name
          Signature
          SignatureHash
          SignatureType
        }
        Index
        ExitIndex
        EnterIndex
        LogAfterCallIndex
        Pc
      }
      LogHeader {
        Address
        Data
        Index
      }
      Topics {
        Hash
      }
      Transaction {
        From
        To
        Type
      }
    }
  }
}

With this data about newsly minted NFTs, you can analyze NFT minting trends or from which NFT marketplaces these NFTs are getting minted.

Also read: Bitquery NFT Marketplace APIs: How to get NFT Data

Real-Time Arbitrum Data

If you require real-time data, you can easily achieve this by modifying any of the queries mentioned above. Just add the subscription keyword at the beginning of the query and remove the dataset field. This enables you to access data in real-time through WebSockets using Bitquery's Streaming API.

For further information on real-time data access, please refer to our documentation. Additionally, you can explore examples that demonstrate how to fetch real-time data using Python and the WebSocket endpoint.

Conclusion

In this article, we've taken a close look at how to retrieve data from Arbitrum using Bitquery's API, covering essential information such as Balances, Token Transfers, and DEX Trades APIs. These APIs provide a wealth of valuable data that can be harnessed for various purposes.

However, it's important to note that there are additional APIs for Arbitrum, such as Calls (for Smart Contract Calls) and Arguments (for Call/Event Arguments), which we haven't delved into within this article. By leveraging the full spectrum of these APIs, you can satisfy a wide range of data requirements for your Arbitrum-related projects.

If you've reached this point in the article and want a more comprehensive article on the APIs we've discussed here, along with a deep dive into the ones we haven't covered, please don't hesitate to reach out to us on our Telegram channel.

About Bitquery

Bitquery is a set of software tools that parse, index, access, search, and use information across blockchain networks in a unified way. Our products are:

  • Coinpath® APIs provide blockchain money flow analysis for more than 24 blockchains. With Coinpath’s APIs, you can monitor blockchain transactions, investigate crypto crimes such as bitcoin money laundering, and create crypto forensics tools. Read this to get started with Coinpath®.
  • Digital Assets API provides index information related to all major cryptocurrencies, coins, and tokens.
  • DEX API provides real-time deposits and transactions, trades, and other related data on different DEX protocols like Uniswap, Kyber Network, Airswap, Matching Network, etc.

If you have any questions about our products, ask them on our Telegram channel or email us at sales@bitquery.io. Also, subscribe to our newsletter below, we will keep you updated with the latest in the cryptocurrency world.

Subscribe to our newsletter

Subscribe and never miss any updates related to our APIs, new developments & latest news etc. Our newsletter is sent once a week on Monday.