42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
|
"use strict";
|
||
|
import { Logger } from "@ethersproject/logger";
|
||
|
import { version } from "./_version";
|
||
|
const logger = new Logger(version);
|
||
|
import { UrlJsonRpcProvider } from "./url-json-rpc-provider";
|
||
|
const defaultProjectId = "84842078b09946638c03157f83405213";
|
||
|
export class InfuraProvider extends UrlJsonRpcProvider {
|
||
|
get projectId() { return this.apiKey; }
|
||
|
static getApiKey(apiKey) {
|
||
|
if (apiKey == null) {
|
||
|
return defaultProjectId;
|
||
|
}
|
||
|
return apiKey;
|
||
|
}
|
||
|
static getUrl(network, apiKey) {
|
||
|
let host = null;
|
||
|
switch (network.name) {
|
||
|
case "homestead":
|
||
|
host = "mainnet.infura.io";
|
||
|
break;
|
||
|
case "ropsten":
|
||
|
host = "ropsten.infura.io";
|
||
|
break;
|
||
|
case "rinkeby":
|
||
|
host = "rinkeby.infura.io";
|
||
|
break;
|
||
|
case "kovan":
|
||
|
host = "kovan.infura.io";
|
||
|
break;
|
||
|
case "goerli":
|
||
|
host = "goerli.infura.io";
|
||
|
break;
|
||
|
default:
|
||
|
logger.throwError("unsupported network", Logger.errors.INVALID_ARGUMENT, {
|
||
|
argument: "network",
|
||
|
value: network
|
||
|
});
|
||
|
}
|
||
|
return "https:/" + "/" + host + "/v3/" + apiKey;
|
||
|
}
|
||
|
}
|