ethers.js/packages/providers/lib/alchemy-provider.js

72 lines
3.0 KiB
JavaScript
Raw Normal View History

2019-05-15 01:48:48 +03:00
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
2020-07-05 07:01:57 +03:00
var websocket_provider_1 = require("./websocket-provider");
2019-08-02 09:10:58 +03:00
var logger_1 = require("@ethersproject/logger");
var _version_1 = require("./_version");
var logger = new logger_1.Logger(_version_1.version);
2019-05-15 01:48:48 +03:00
var url_json_rpc_provider_1 = require("./url-json-rpc-provider");
// This key was provided to ethers.js by Alchemy to be used by the
// default provider, but it is recommended that for your own
// production environments, that you acquire your own API key at:
// https://dashboard.alchemyapi.io
var defaultApiKey = "_gg7wSSi0KMBsdKnGVfHDueq6xMB9EkC";
var AlchemyProvider = /** @class */ (function (_super) {
__extends(AlchemyProvider, _super);
function AlchemyProvider() {
return _super !== null && _super.apply(this, arguments) || this;
}
2020-07-05 07:01:57 +03:00
AlchemyProvider.getWebSocketProvider = function (network, apiKey) {
var provider = new AlchemyProvider(network, apiKey);
var url = provider.connection.url.replace(/^http/i, "ws")
.replace(".alchemyapi.", ".ws.alchemyapi.");
return new websocket_provider_1.WebSocketProvider(url, provider.network);
};
2019-05-15 01:48:48 +03:00
AlchemyProvider.getApiKey = function (apiKey) {
if (apiKey == null) {
return defaultApiKey;
}
2019-11-20 12:57:38 +03:00
if (apiKey && typeof (apiKey) !== "string") {
logger.throwArgumentError("invalid apiKey", "apiKey", apiKey);
}
2019-05-15 01:48:48 +03:00
return apiKey;
};
AlchemyProvider.getUrl = function (network, apiKey) {
var host = null;
switch (network.name) {
case "homestead":
2020-07-05 07:01:57 +03:00
host = "eth-mainnet.alchemyapi.io/v2/";
2019-05-15 01:48:48 +03:00
break;
case "ropsten":
2020-07-05 07:01:57 +03:00
host = "eth-ropsten.alchemyapi.io/v2/";
2019-05-15 01:48:48 +03:00
break;
case "rinkeby":
2020-07-05 07:01:57 +03:00
host = "eth-rinkeby.alchemyapi.io/v2/";
2019-05-15 01:48:48 +03:00
break;
2020-05-05 06:01:04 +03:00
case "goerli":
2020-07-05 07:01:57 +03:00
host = "eth-goerli.alchemyapi.io/v2/";
2020-05-05 06:01:04 +03:00
break;
2019-05-15 01:48:48 +03:00
case "kovan":
2020-07-05 07:01:57 +03:00
host = "eth-kovan.alchemyapi.io/v2/";
2019-05-15 01:48:48 +03:00
break;
default:
2019-08-02 09:10:58 +03:00
logger.throwArgumentError("unsupported network", "network", arguments[0]);
2019-05-15 01:48:48 +03:00
}
return ("https:/" + "/" + host + apiKey);
};
return AlchemyProvider;
}(url_json_rpc_provider_1.UrlJsonRpcProvider));
exports.AlchemyProvider = AlchemyProvider;
2020-07-13 15:03:56 +03:00
//# sourceMappingURL=alchemy-provider.js.map