This page provides a comprehensive explanation of how to establish a multi-chain indexer to track bridge transfers from Polygon to Ethereum via the Polygon Plasma Bridge. Generally, Polygon offers two types of bridges for asset transfers: the Proof of Stake (PoS) Bridge and the Plasma Bridge. Plasma Bridge supports the transfer of Polygon's native token, `MATIC`, and certain Ethereum tokens such as `ETH`, ERC-20, and ERC-721. It employs the Ethereum Plasma scaling solution to enhance security.

This guide serves as your starting point for efficiently indexing bridge transactions originating from Polygon to Ethereum, empowering users to navigate their cross-chain transactions. Since this bridge extends its functionality to various blockchain networks, developers aiming to create dApps that seamlessly span multiple chains require the capability to simultaneously index multiple blockchains. SubQuery has proactively addressed this need by introducing a groundbreaking solution known as Multi-Chain Indexing.

Example

The Plasma Bridge sample project gathers data related to bridge transactions. Key resources:

Use-Cases

Once you initiate the project, you'll have the choice to launch the queries. Within this context, the following entities can be extracted:

- `DepositOnPolygon`: Signifies deposits made on the Polygon side of the bridge.

- `DepositOnEthereum`: Denotes withdrawals (Ethereum deposits).

- `BridgeTransaction`: Links Polygon deposits to Ethereum withdrawals.

- `User`: Represents user information, encompassing wallet addresses and overall deposit amounts.

Now, let's examine the following query:

{
  query {
    bridgeTransactions {
      nodes {
        id
        depositOnEthereum {
          id
          user {
            id
          }
          token
          amount
          tx
        }
        depositOnPolygon {
          id
          user {
            id
          }
          rootToken
          amount
          tx
        }
      }
    }
  }
}
```
The query will return this:

{
  "data": {
    "query": {
      "bridgeTransactions": {
        "nodes": [
          {
            "id": "529040001",
            "depositOnEthereum": {
              "id": "529040001",
              "user": {
                "id": "0xc163034e49f0ee158de7dd0aa37e665d560de40f"
              },
              "token": "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
              "amount": "3113988835221724970000",
              "tx": "0x8a082796ee2d846e3e064c34e08ae4510051896612e793f8e5b7a5314fcd1eb9"
            },
            "depositOnPolygon": {
              "id": "529040001",
              "user": {
                "id": "0xc163034e49f0ee158de7dd0aa37e665d560de40f"
              },
              "token": "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
              "amount": "3113988835221724970000",
              "tx": "0x0b8a99dfea351f3f2dc7d8e114b2408df528660bfb9008d097c951fe87fa7a01"
            }
          }
        ]
      }
    }
  }
}

This data represents a specific bridge transaction involving the movement of assets between Polygon and Ethereum, with detailed information on the involved parties, tokens, amounts, and transaction hashes. As seen from the information presented, the sole distinguishing factor between objects related to different chains is the transaction hash.

Considering that this project spans multiple blockchains, we have the capability to query the project's metadata. This can be accomplished using the following query:

{
  _metadatas {
    totalCount
    nodes {
      chain
      lastProcessedHeight
    }
  }
}

The query will return this:

{
  "data": {
    "_metadatas": {
      "totalCount": 3,
      "nodes": [
        {
          "chain": "137",
          "lastProcessedHeight": 45222964
        },
        {
          "chain": "1",
          "lastProcessedHeight": 14312934
        }
      ]
    }
  }
}

Furthermore, when you combine multi-chain capabilities with aggregations, it opens up significant possibilities for cross-chain analysis without a need to exit the GraphQL interface to gain insights into specific subject matters.

About Polygon and Plasma Bridge

The Polygon network is a layer-2 scaling solution and framework built on top of the Ethereum blockchain. It is designed to address some of the scalability and performance issues of the Ethereum network. 

There are two bridges within the Polygon network: the Proof-of-Stake (PoS) Bridge, which serves as the official Matic Bridge, and the Plasma Bridge. Both of these bridges enable the transfer of tokens between Ethereum and Polygon, yet they differ in their security methodologies. 

The PoS Bridge is the more widely adopted option, especially for transferring ETH and most ERC tokens. It relies on the PoS consensus algorithm to safeguard its network. While deposits on the PoS Bridge are promptly secured, withdrawals may require some time for confirmation.

Plasma Bridge's withdrawal process may extend to as much as seven days. The Plasma Bridge, on the other hand, is better suited for developers seeking enhanced security measures. It employs the Ethereum Plasma scaling solution and accommodates the transfer of MATIC, ETH, ERC-20, and ERC-721 tokens.

Website | Discord | YouTube | Twitter | Telegram

About SubQuery

SubQuery is a leading blockchain data indexer that provides developers with fast, flexible, universal, and decentralised APIs for web3 projects. We empower developers from over 110+ ecosystems including Ethereum, Polygon, Polkadot, Cosmos, Algorand, NEAR, and Avalanche with rich indexed data to allow them to build intuitive and immersive decentralised applications. This blockchain developer toolkit enables developers to focus on their core use case and front-end without wasting time building a custom backend for data processing activities. In the near future, the SubQuery Network will replicate this scalable and reliable solution in a completely decentralised manner.

​​Linktree | Website | Discord | Telegram | Twitter | Matrix | LinkedIn | YouTube

Share this post