Closed Niraj-Kamdar closed 3 days ago
Hi @Niraj-Kamdar
This is already possible. You can use the FrontierEthProvider which implements the ethers provider interface.
Example:
const provider = new FrontierEthProvider();
const erc20 = Erc20__factory.connect(contractAddress, provider);
const balance = await erc20.balanceOf(address);
Prerequisites
Description
In Substrate Frontier projects, we need the ability to individually inject both the Polkadot API and the Ethers.js API instead of a single
api
object. This enhancement would allow developers to access both Substrate-specific and EVM-specific functionalities within the same mapping handlers, which is essential for indexing data on a Frontier-based chain that supports both Substrate modules and EVM contracts.Details
These details can help to reproduce the environment where the issue is occurring:
Local Environment:
Query Version: 5.1.1
Indexer Version: 5.1.1
Network Details:
Steps to Reproduce
Initialize a SubQuery Project: Create a new SubQuery project targeting a Frontier-based Substrate chain that supports EVM contracts.
Attempt to Use Both APIs: In your mapping handlers (e.g.,
mappingHandlers.ts
), try to use both the Polkadot.js API and the Ethers.js API:Observe the Issue: You'll notice that the
api
object cannot be both a Polkadot.js API and an Ethers.js provider simultaneously. This limitation prevents access to both Substrate and EVM functionalities within the same handler.Expected Behavior
We expect to have both APIs injected separately into the mapping handlers, such as:
polkadotApi
: An instance of the Polkadot.js API for interacting with Substrate modules.ethersApi
: An instance of the Ethers.js provider for interacting with EVM contracts.This separation allows us to:
polkadotApi
, such as storage queries and chain state.ethersApi
, such as calling contract methods and querying balances.Example Usage:
Actual Behavior
Currently, only a single
api
object is injected into the mapping handlers, which is either:This setup forces developers to choose between Substrate and EVM functionalities, which is not practical for Frontier-based chains that support both.
Any Other Information
References from Documentation:
Querying Contracts (EVM Chains):
Example:
Query States (Polkadot Chains):
Example:
Issue Summary:
In Frontier-based Substrate chains, both Substrate modules and EVM contracts are first-class citizens. Developers need access to both the Polkadot.js API and the Ethers.js API within the same mapping handlers to fully leverage the chain's capabilities.
Proposed Solution:
Inject Both APIs Separately: Modify the SubQuery runtime to inject both
polkadotApi
andethersApi
into the context of mapping handlers.Update Type Definitions: Ensure that TypeScript definitions are updated to recognize both APIs, allowing for proper type checking and IntelliSense support.
Backward Compatibility: Maintain backward compatibility by keeping the existing
api
object for projects that target only Substrate or EVM chains.Benefits:
Enhanced Functionality: Enables comprehensive data indexing by accessing both Substrate storage and EVM contract data.
Developer Experience: Simplifies the development process by providing clear and separate APIs for different functionalities.
Ecosystem Growth: Encourages more projects to adopt SubQuery for indexing on Frontier-based chains.
Thank you for considering this feature request. Implementing this enhancement will significantly improve the developer experience and capabilities when working with Frontier-based Substrate projects.