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

64 lines
2.5 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 __());
};
})();
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var errors = __importStar(require("@ethersproject/errors"));
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;
}
AlchemyProvider.getApiKey = function (apiKey) {
if (apiKey == null) {
return defaultApiKey;
}
return apiKey;
};
AlchemyProvider.getUrl = function (network, apiKey) {
var host = null;
switch (network.name) {
case "homestead":
host = "eth-mainnet.alchemyapi.io/jsonrpc/";
break;
case "ropsten":
host = "eth-ropsten.alchemyapi.io/jsonrpc/";
break;
case "rinkeby":
host = "eth-rinkeby.alchemyapi.io/jsonrpc/";
break;
case "kovan":
host = "eth-kovan.alchemyapi.io/jsonrpc/";
break;
default:
errors.throwArgumentError("unsupported network", "network", arguments[0]);
}
return ("https:/" + "/" + host + apiKey);
};
return AlchemyProvider;
}(url_json_rpc_provider_1.UrlJsonRpcProvider));
exports.AlchemyProvider = AlchemyProvider;