Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for matic #1546

Closed
gitpusha opened this issue May 8, 2021 · 17 comments
Closed

Support for matic #1546

gitpusha opened this issue May 8, 2021 · 17 comments
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@gitpusha
Copy link

gitpusha commented May 8, 2021

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 :)

@zemse
Copy link
Collaborator

zemse commented May 8, 2021

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.

@ricmoo
Copy link
Member

ricmoo commented May 12, 2021

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’t 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. :)

@gitpusha
Copy link
Author

kk thx!

@htadashi
Copy link

htadashi commented May 16, 2021

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’t 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/

@ricmoo ricmoo added investigate Under investigation and may be a bug. on-deck This Enhancement or Bug is currently being worked on. labels May 30, 2021
@hack3r-0m
Copy link

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.

@ricmoo
Copy link
Member

ricmoo commented Jun 2, 2021

I’ve 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’t 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.

@hack3r-0m
Copy link

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

@ricmoo
Copy link
Member

ricmoo commented Jun 10, 2021

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.

@ricmoo
Copy link
Member

ricmoo commented Jun 11, 2021

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. :)

@ricmoo ricmoo closed this as completed Jun 11, 2021
@ricmoo ricmoo added enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published. and removed investigate Under investigation and may be a bug. on-deck This Enhancement or Bug is currently being worked on. labels Jun 11, 2021
@ricmoo
Copy link
Member

ricmoo commented Jul 23, 2021

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.

AddressXception added a commit to PizzaDAO/pizza-smartcontract that referenced this issue Jul 31, 2021
when ethers added official support, they chose maticmum as the name.

see here: ethers-io/ethers.js#1546 (comment)
AddressXception added a commit to PizzaDAO/pizza-smartcontract that referenced this issue Oct 25, 2021
* add box mainnet logic contract

* update environment variables

* update dependencies

* factor out VRF interfaces

* Add Seed Storage contract and test stub

* add order oracle

* add pizza interfaces

* add initial deployment script

* add initial pizza contract (WIP)

* Update Deployment scripts

remove env vars that are not actually used.  Add a mint pizza sequence diagram.  update docs, etc

* Add fulfillment event

update fallback function

* npm upgrade

* dont run the bonding curve tests all the time

they take a while

* moar tool updates

* clean up seed storage deployment

add a deployment to mumbai

* update gitignore and packages

* rename mumbai to maticmum

when ethers added official support, they chose maticmum as the name.

see here: ethers-io/ethers.js#1546 (comment)

* add deployment for polygon random consumer

* pizza storage set random consumer

* update docs

* Remove purchase logic, use box token id

remove the logic to purchase a pizza.  it now just redirects to the box contract (for api consistency).  Also use the box id as the token id for the pizza for now.

* missed interface upgrade

* clean up the order api consumer deployment

add the job as a string and use assembly to load it into bytes32. note this is dangerous.

* check the chainlink callback is a contract

use openzep's _msgSender() in some places

* remove references to kovan

update packages

* fix test

* reanme

* update pizza deployment

* Fix the IPFS hash resolution

The IPFS hashes are too big when coming in from the chainlink oracle to fit in bytes32 so they get converted from base58 into a uint and the multihash bytes are stripped off, then recombined when reading out the hash when calling tokenURI.

* PR self review

* add a couple tests and scripts

* add missing interface members

add missing function parameters add a few missing checks. change the data type of the address to a uint

* add toggle for sale

* add authorized requesstor to order api consumer

* update deployed addresses

* use call() when calling order api response contract

* use token id var
AddressXception added a commit to PizzaDAO/pizza-smartcontract that referenced this issue Oct 29, 2021
* add box mainnet logic contract

* update environment variables

* update dependencies

* factor out VRF interfaces

* Add Seed Storage contract and test stub

* add order oracle

* add pizza interfaces

* add initial deployment script

* add initial pizza contract (WIP)

* Update Deployment scripts

remove env vars that are not actually used.  Add a mint pizza sequence diagram.  update docs, etc

* Add fulfillment event

update fallback function

* npm upgrade

* dont run the bonding curve tests all the time

they take a while

* moar tool updates

* clean up seed storage deployment

add a deployment to mumbai

* update gitignore and packages

* rename mumbai to maticmum

when ethers added official support, they chose maticmum as the name.

see here: ethers-io/ethers.js#1546 (comment)

* add deployment for polygon random consumer

* pizza storage set random consumer

* update docs

* Remove purchase logic, use box token id

remove the logic to purchase a pizza.  it now just redirects to the box contract (for api consistency).  Also use the box id as the token id for the pizza for now.

* missed interface upgrade

* clean up the order api consumer deployment

add the job as a string and use assembly to load it into bytes32. note this is dangerous.

* check the chainlink callback is a contract

use openzep's _msgSender() in some places

* remove references to kovan

update packages

* fix test

* reanme

* update pizza deployment

* Fix the IPFS hash resolution

The IPFS hashes are too big when coming in from the chainlink oracle to fit in bytes32 so they get converted from base58 into a uint and the multihash bytes are stripped off, then recombined when reading out the hash when calling tokenURI.

* PR self review

* add a couple tests and scripts

* add missing interface members

add missing function parameters add a few missing checks. change the data type of the address to a uint

* add toggle for sale

* add partially implemented dapp

* Changes to align old and new dapp patterns, some renaming, and tried to align the semantics of the contracts.

* further stub out the dapp

* stub out pricing and token fetch

* add webpack and compile

* couple deployments remove unnecessary methods update dapp

* update docs

Co-authored-by: Julian Bleecker <bleeckerj@gmail.com>
@bitcazador
Copy link

bitcazador commented Dec 14, 2021

@ricmoo I am trying to put this code in common js, but due to my inexperience I'm not able the central part. This is the code I mention

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);

and here is my try,

const ethers  = require('ethers');
const Network = require('@ethersproject/networks');

// 1st try..
Network dic_net= {
    name: 'matic',
    chainId: 137,
    _defaultProvider: (providers) => new providers.JsonRpcProvider('rpc-url')
};

// 2nd try..
dic_net = new Network('matic', 137, (providers) => new providers.JsonRpcProvider('rpc-url') );

const provider = ethers.getDefaultProvider(dic_net);

thank you in advance

@ricmoo
Copy link
Member

ricmoo commented Dec 14, 2021

It looks like you are trying to write JavaScript, in your example, not TypeScript. When using JavaScript directly, you don't use types or interfaces, you just specify the values directly, so Network, which is a type in v6, cannot be newed:

Something more like this is prolly what you are looking for:

const ethers  = require('ethers');

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

const provider = ethers.getDefaultProvider(dic_net);

Make sense?

@OsmanYagc
Copy link

OsmanYagc commented Apr 4, 2022

Hi @ricmoo,

I am trying to deploy a smart contract. My RPC provider is Alchemy and I am working on Polygon and Mumbai. You have said above that you have fixed the problem on "support for matic issue". However when I try to deploy a contract on mumbai or polygon, it gives "getDefaultProvider does not support matic/maticmum" error .

After that, I tried to change the variable I am passing to getDefaultProvider function. Initially it was;

getDefaultProvider(matic, ..);

, and I have made it;

getDefaultProvider( {
name: 'matic',
chainId: 137,
_defaultProvider: (providers) => new providers.JsonRpcProvider('alchemy-rpc-url')
},
....,
);

Then it worked and deployed the contract. However, now, when I try to call a function on my smart contract like setBaseTokenUri, MintTo, or any functionality I added to my smart contract, it gives "transaction underpriced" error and cancel the operation.

When I tried the same contract and functions on rinkeby, everything works perfectly fine.

I do not understand why it is giving "getDefaultProvider" error when "matic" is sent as a paramater to getDefaultProvider and the "transaction underpriced" error after I changed the paramater "matic" passed to getDefaultProvider.

Appreciate your response,

Have a nice day!

**Note: I have used latest version 5.6.2 of ethers.js.

@antonsalii
Copy link

Hi @ricmoo,

unfortunately, I have the same issue as @OsmanYagc

@OsmanYagc
Copy link

Hi @ricmoo,

unfortunately, I have the same issue as @OsmanYagc

Hi,

You can find the solution here;

#2863

@tab00
Copy link

tab00 commented Jan 25, 2023

Once we have standard (non-paid tier) access to Matic endpoints, I can add getDefaultProvider provider. :)

Infura's endpoints for Polygon requires credit card to activate. I've been getting failed call errors ("Project ID does not have access to polygon l2") due to this when using getDefaultProvider.

Can you just use Polygon's official free endpoints?:
RPC Endpoint for Polygon mainnet: https://polygon-rpc.com
RPC Endpoint for Polygon Testnet (Mumbai): https://rpc-mumbai.matic.today

Source:
https://wiki.polygon.technology/docs/develop/network-details/endpoints
https://polygon.technology/blog/polygon-rpc-gateway-will-provide-a-free-high-performance-connection-to-the-polygon-pos-blockchain

@tab00
Copy link

tab00 commented Jan 25, 2023

So how can we force the use of Polygon's official endpoints instead of Infura's whilst still specifying an Infura key for getDefaultProvider?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

9 participants