Skip to content

Commit

Permalink
Add Polygon RPC endpoints to the default provider (#3689).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jul 28, 2023
1 parent 8f0a509 commit 23704a9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src.ts/providers/default-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,23 @@ export function getDefaultProvider(network: string | Networkish | WebSocketLike,
return new WebSocketProvider(network);
}

// Get the network name, if possible
let name: null | string = null;
// Get the network and name, if possible
let staticNetwork: null | Network = null;
try {
name = Network.from(network).name;
staticNetwork = Network.from(network);
} catch (error) { }


const providers: Array<AbstractProvider> = [ ];

if (options.publicPolygon !== "-" && staticNetwork) {
if (staticNetwork.name === "matic") {
providers.push(new JsonRpcProvider("https:/\/polygon-rpc.com/", staticNetwork, { staticNetwork }));
} else if (staticNetwork.name === "matic-mumbai") {
providers.push(new JsonRpcProvider("https:/\/rpc-mumbai.matic.today/", staticNetwork, { staticNetwork }));
}
}

if (options.alchemy !== "-") {
try {
providers.push(new AlchemyProvider(network, options.alchemy));
Expand Down Expand Up @@ -112,10 +120,11 @@ export function getDefaultProvider(network: string | Networkish | WebSocketLike,
// We use the floor because public third-party providers can be unreliable,
// so a low number of providers with a large quorum will fail too often
let quorum = Math.floor(providers.length / 2);
if (quorum > 2) { quorum = 2; }

// Testnets don't need as strong a security gaurantee and speed is
// more useful during testing
if (name && Testnets.indexOf(name) !== -1) { quorum = 1; }
if (staticNetwork && Testnets.indexOf(staticNetwork.name) !== -1) { quorum = 1; }

// Provided override qorum takes priority
if (options && options.quorum) { quorum = options.quorum; }
Expand Down

0 comments on commit 23704a9

Please sign in to comment.