Ethers.js: Support for matic

Created on 8 May 2021  路  10Comments  路  Source: ethers-io/ethers.js

Currently in "ethers": "5.1.4" getDefaultProvider using getNetwork under the hood doesnt seem to support matic (chainId: 137).

Would be sweet if it did :)

enhancement fixed

Most helpful comment

Given the recent popularity, I will likely add matic (and a few others) to the networks package, but that will only entail the chain ID and network name, so they won鈥檛 be valid for getDefaultProvider, since that requires an established community of third-party services.

If equivalent services like INFURA, Alchemy and Etherscan exist though, I would add support for getDefaultProvider. :)

All 10 comments

You can define custom Networks once in your applications and pass it to getDefaultProvider whenever you need them.

import { Network } from "@ethersproject/networks";

export const matic: Network = {
    name: 'matic',
    chainId: 137,
    _defaultProvider: (providers) => new providers.JsonRpcProvider('rpc-url')
}

// import those networks where ever you want to use it with getDefaultProvider
const provider = ethers.getDefaultProvider(matic);

If you're asking if the rpc URLs can be hardcoded in ethers.js codebase, then actually there are plenty of evm chains who should also be included. And then some RPCs can get outdated, and it gets difficult to maintain them.

It'd be helpful to somehow leverage information available at ethereum-lists/chains, but this can cause some security issues, i.e. if the website source is hijacked then an attacker can cause incorrect information to be displayed in dapps, and they take advantage of it.

Given the recent popularity, I will likely add matic (and a few others) to the networks package, but that will only entail the chain ID and network name, so they won鈥檛 be valid for getDefaultProvider, since that requires an established community of third-party services.

If equivalent services like INFURA, Alchemy and Etherscan exist though, I would add support for getDefaultProvider. :)

kk thx!

Given the recent popularity, I will likely add matic (and a few others) to the networks package, but that will only entail the chain ID and network name, so they won鈥檛 be valid for getDefaultProvider, since that requires an established community of third-party services.

If equivalent services like INFURA, Alchemy and Etherscan exist though, I would add support for getDefaultProvider. :)

Hi @ricmoo, first of all, thanks for developing and maintaining this awesome library :)
I think matic have support on Ankr (which is an Infura-like service) and there is a blockchain explorer on https://polygon-explorer-mainnet.chainstacklabs.com/

Also, Infura had added support to matic/polygon recently: https://blog.infura.io/polygon-now-available/

Matic has support for infura, alchemy, quiknode, chainstack and a lot more, I would like to add support for matic if you can guide towards what steps are required, also, I can look at one of the past PR adding support for any particular EVM chain, process would be pretty similar I guess.

I鈥檝e already added the chain data to the networks.

I need to do a bit more research before adding it to the providers and offering it as part of a default provider option, but if alchemy and INFURA already support it, a lot of that research is already done. :)

It should be quite simple to add and doesn鈥檛 require any signature changes. I just have to get a bit more to get done (and testing) on eip-1559 before the call on Friday. I should be able to get it in next week.

it will also nice to have Matic testnet's (Mumbai) support for getDefaultProvider

I don't see Matic as an option for either INFURA or Alchemy. The default provider only works for the networks it does because some of the large backend services in the space have been so gracious as to offer beefed-up API keys for community use.

I've added the Mumbai chain information to the networks package though (locally) and the change will go out with the next release.

The testnet has been added in 5.3.1.

Further support won't be able to be added until there is wider community-available resources though, so I'll close this for now. Once we have standard (non-paid tier) access to Matic endpoints, I can add getDefaultProvider provider. :)

I've added support for matic (and maticmum) to InfuraProvider and AlchemyProvider in 5.4.2.

The InfuraProvider doesn't have Matic support for the default provider yet, but should be available soon.

Was this page helpful?
0 / 5 - 0 ratings