Skip to content

Commit 23704a9

Browse files
committedJul 28, 2023
Add Polygon RPC endpoints to the default provider (#3689).
1 parent 8f0a509 commit 23704a9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed
 

‎src.ts/providers/default-provider.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,23 @@ export function getDefaultProvider(network: string | Networkish | WebSocketLike,
3636
return new WebSocketProvider(network);
3737
}
3838

39-
// Get the network name, if possible
40-
let name: null | string = null;
39+
// Get the network and name, if possible
40+
let staticNetwork: null | Network = null;
4141
try {
42-
name = Network.from(network).name;
42+
staticNetwork = Network.from(network);
4343
} catch (error) { }
4444

4545

4646
const providers: Array<AbstractProvider> = [ ];
4747

48+
if (options.publicPolygon !== "-" && staticNetwork) {
49+
if (staticNetwork.name === "matic") {
50+
providers.push(new JsonRpcProvider("https:/\/polygon-rpc.com/", staticNetwork, { staticNetwork }));
51+
} else if (staticNetwork.name === "matic-mumbai") {
52+
providers.push(new JsonRpcProvider("https:/\/rpc-mumbai.matic.today/", staticNetwork, { staticNetwork }));
53+
}
54+
}
55+
4856
if (options.alchemy !== "-") {
4957
try {
5058
providers.push(new AlchemyProvider(network, options.alchemy));
@@ -112,10 +120,11 @@ export function getDefaultProvider(network: string | Networkish | WebSocketLike,
112120
// We use the floor because public third-party providers can be unreliable,
113121
// so a low number of providers with a large quorum will fail too often
114122
let quorum = Math.floor(providers.length / 2);
123+
if (quorum > 2) { quorum = 2; }
115124

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.