Polygon (Matic) APIs

Polygon (MATIC) APIs | Transfers, Trades, Tokens & DEX

Last month, we announced the grant from the Polygon team. Soon after, our team started the Polygon integration in our products.

Today we are happy to announce that we have integrated Polygon on all Bitquery products. Additionally, we have parsed 100s of DEXs on Polygon such as QuickSwap, ApeSwap, WaultSwap, etc. Therefore now you can query them using our GraphQl APIs.

In this article, we will talk about how to query the Polygon network using Bitquery APIs and access trading data for DEXs on Polygon.

Polygon is a protocol and framework for building and connecting Ethereum-compatible blockchain networks. It is a 2nd layer solution that is designed to solve blockchain scalability issues. MATIC is the Polygon’s native token that powers the Polygon network.

Users can deposit Ethereum tokens to a Polygon smart contract, interact with them within Polygon, and later withdraw them back to the Ethereum main chain. The MATIC token is used to pay transaction fees and participate in proof-of-stake consensus.

Monthly Transaction Volume

In the following query, we’ll be querying the monthly transaction volume of the Polygon network.

{
  ethereum(network: matic) {
    transactions(options: {asc: "date.month"}, date: {since: "2021–01–01"}) {
      date {
        month
        year
      }
      count: count
      gasValue
    }
  }
}

As you can see in the following visualization, Polygon did more than 200 million transactions in June, at its peak, which is 577% of what Ethereum did in June 2021. In the same month, the Binance Smart chain processed more than 130 million transactions.

If you want the latest Polygon transactions, use this API.

Monthly Transaction Volume on Polygon

Monthly Transfer Count on Polygon

A transfer is when a token gets transferred. One transaction can contain none or multiple transfers. Using the following query, you can check monthly transfers on the Polygon network.

{
  ethereum(network: matic) {
    transfers(options: {asc: "date.month"}, date: {since: "2021-01-01"}) {
      date {
        month
        year
      }
      transfer_count: count
    }
  }
}

Polygon saw more than 140 million transfers in July 2021. In the same month, Ethereum saw 61 million transfers, and BSC saw 328 million transfers.

Monthly Transfers on Polygon

You can use the following GraphQL API to get the latest Polygon transfers.

{
  ethereum(network: matic) {
    transfers(
      options: {desc: "block.height", limit: 10, offset: 0}
      date: {since: "2021-08-11", till: null}
      amount: {gt: 0}
    ) {
      block {
        timestamp {
          time(format: "%Y-%m-%d %H:%M:%S")
        }
        height
      }
      sender {
        address
      }
      receiver {
        address
      }
      currency {
        address
        symbol
      }
      amount
      transaction {
        hash
      }
      external
    }
  }
}

Top Tokens on Polygon based on number of transfers

Let’s also see the top currencies on the Polygon network based on the number of transfers. You can get this data using this GraphQL API.


Top Tokens Traded on Polygon

Smart Contracts on Polygon

Polygon saw a whopping 1.75 billion smart contract calls in July 2021, almost equal to Binance smart chain’s 1.76 billion smart contract call.

On the other hand, Ethereum processed around 132 million smart contract calls in July.

You can use the following query to get smart contract calls a month on month basis.

{
  ethereum(network: bsc) {
    smartContractCalls(options: {asc: "date.date"}, date: {since: null, till: null}) {
      date: date {
        date(format: "%Y-%m")
      }
      count: count
      contracts: count(uniq: smart_contracts)
      callers: count(uniq: senders)
      methods: count(uniq: smart_contract_methods)
    }
  }
}

DEXs on Polygon

Defi is growing on the Polygon network, 100s of DEXs and other DApps are deployed on Polygon. In addition, Aave, Sushiswap, and other famous Dapps are now also integrated with Polygon.

Since its launch, Polygon saw more than 53 million trades, totaling around $24 billion in trade volume, and all these trades came in the last four months.

DEXs like QuickSwap and SushiSwap on Polygon saw more than 6 billion in trade amount in just a few months.

Use this API to get the top Polygon DEXs based on trade volume.

Top Polygon DEXs based on trade volume

Top Tokens Trades on Polygon

As we have seen with other blockchains, stablecoin is also ruling the Polygon network. The top 5 tokens are involved in more than 95% of trades, and USDC is more popular than USDT.

All Latest Trades on Polygon

You can use our DEX APIs to get all the latest trades on Polygon for any DEX we support.

For example, check the following API to get the latest Polygon trade.

{
  ethereum(network: matic) {
    dexTrades(
      options: {desc: ["block.height", "tradeIndex"], limit: 10}
      date: {since: null, till: null}
    ) {
      block {
        timestamp {
          time(format: "%Y-%m-%d %H:%M:%S")
        }
        height
      }
      tradeIndex
      protocol
      exchange {
        fullName
      }
      smartContract {
        address {
          address
        }
      }
      buyAmountInUSD: buyAmount(in: USD)
      buyCurrency {
        address
        symbol
      }
      sellAmountInUSD: sellAmount(in: USD)
      sellCurrency {
        address
        symbol
      }
      transaction {
        hash
      }
    }
  }
}

You can also get trades for specific DEX, check the following example for getting latest trades from QuickSwap.

{
  ethereum(network: matic) {
    dexTrades(
      options: {desc: ["block.height", "tradeIndex"], limit: 10}
      exchangeName: {is: "QuickSwap"}
      date: {since: null, till: null}
    ) {
      block {
        timestamp {
          time(format: "%Y-%m-%d %H:%M:%S")
        }
        height
      }
      tradeIndex
      protocol
      exchange {
        fullName
      }
      smartContract {
        address {
          address
        }
      }
      buyAmountInUSD: buyAmount(in: USD)
      buyCurrency {
        address
        symbol
      }
      sellAmountInUSD: sellAmount(in: USD)
      sellCurrency {
        address
        symbol
      }
      transaction {
        hash
      }
    }
  }
}

Showing Polygon’s DEXs data on TradingView

We provide flexible OHLC data APIs for all the DEXs and all the blockchains we support. Therefore you can easily integrate DEX trading data with the TradingView library to build charts for traders. We have also written tutorials on integrating Bitquery APIs with the TradingView library using React and VueJS .

For example, checkout following query in which we get CHI-WMATIC pair’s OHLC data for a minute timeframe.

{
  ethereum(network: matic) {
    dexTrades(
      options: {limit: 100, asc: "timeInterval.minute"}
      date: {since: "2021-08-11"}
      exchangeName: {is: "QuickSwap"}
      baseCurrency: {is: "0x0000000000004946c0e9f43f4dee607b0ef1fa1c"}
      quoteCurrency: {is: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270"}
    ) {
      timeInterval {
        minute(count: 5)
      }
      baseCurrency {
        symbol
        address
      }
      baseAmount
      quoteCurrency {
        symbol
        address
      }
      quoteAmount
      trades: count
      quotePrice
      maximum_price: quotePrice(calculate: maximum)
      minimum_price: quotePrice(calculate: minimum)
      open_price: minimum(of: block, get: quote_price)
      close_price: maximum(of: block, get: quote_price)
    }
  }
}

Latest Trades for a given token on Polygon

Let’s say you want the latest trades for a given token on the Polygon network; you can use the following query, where we are getting the latest trades for the DINO token.

Just replace the baseCurrency with your token’s address.

{
  ethereum(network: matic) {
    dexTrades(
      options: {desc: ["block.height", "tradeIndex"], limit: 10}
      baseCurrency: {is: "0xaa9654becca45b5bdfa5ac646c939c62b527d394"}
      date: {after: "2021-03-28"}
    ) {
      transaction {
        hash
      }
      exchange {
        name
      }
      tradeIndex
      date {
        date
      }
      block {
        height
      }
      buyAmount
      buyAmountInUsd: buyAmount(in: USD)
      buyCurrency {
        symbol
        address
      }
      sellAmount
      sellAmountInUsd: sellAmount(in: USD)
      sellCurrency {
        symbol
        address
      }
      sellAmountInUsd: sellAmount(in: USD)
      tradeAmount(in: USD)
      transaction {
        gasValue
        gasPrice
        gas
      }
    }
  }
}

Conclusion

In the upcoming days, we will write more tutorials on Polygon and how to get different types of data from the Polygon networks using Bitquery APIs.

If you have any specific queries, please comment below.

Could you do a query for Mint and burn data of liquidity pools?
Thanks

1 Like