2022-09-05 16:57:11 -04:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
exports.AnkrProvider = void 0;
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* [[link-ankr]] provides a third-party service for connecting to
|
|
|
|
* various blockchains over JSON-RPC.
|
|
|
|
*
|
|
|
|
* **Supported Networks**
|
|
|
|
*
|
|
|
|
* - Ethereum Mainnet (``mainnet``)
|
|
|
|
* - Goerli Testnet (``goerli``)
|
2024-01-15 23:07:48 -05:00
|
|
|
* - Sepolia Testnet (``sepolia``)
|
2023-01-28 01:53:29 -05:00
|
|
|
* - Arbitrum (``arbitrum``)
|
2024-01-15 23:07:48 -05:00
|
|
|
* - Base (``base``)
|
|
|
|
* - Base Goerlia Testnet (``base-goerli``)
|
|
|
|
* - Base Sepolia Testnet (``base-sepolia``)
|
|
|
|
* - BNB (``bnb``)
|
|
|
|
* - BNB Testnet (``bnbt``)
|
|
|
|
* - Optimism (``optimism``)
|
|
|
|
* - Optimism Goerli Testnet (``optimism-goerli``)
|
|
|
|
* - Optimism Sepolia Testnet (``optimism-sepolia``)
|
|
|
|
* - Polygon (``matic``)
|
|
|
|
* - Polygon Mumbai Testnet (``matic-mumbai``)
|
2023-01-28 01:53:29 -05:00
|
|
|
*
|
|
|
|
* @_subsection: api/providers/thirdparty:Ankr [providers-ankr]
|
|
|
|
*/
|
2022-09-15 22:58:45 -04:00
|
|
|
const index_js_1 = require("../utils/index.js");
|
2022-09-05 16:57:11 -04:00
|
|
|
const community_js_1 = require("./community.js");
|
|
|
|
const network_js_1 = require("./network.js");
|
|
|
|
const provider_jsonrpc_js_1 = require("./provider-jsonrpc.js");
|
|
|
|
const defaultApiKey = "9f7d929b018cdffb338517efa06f58359e86ff1ffd350bc889738523659e7972";
|
|
|
|
function getHost(name) {
|
|
|
|
switch (name) {
|
2022-09-29 22:57:27 -04:00
|
|
|
case "mainnet":
|
2022-09-05 16:57:11 -04:00
|
|
|
return "rpc.ankr.com/eth";
|
|
|
|
case "goerli":
|
|
|
|
return "rpc.ankr.com/eth_goerli";
|
2024-01-15 23:07:48 -05:00
|
|
|
case "sepolia":
|
|
|
|
return "rpc.ankr.com/eth_sepolia";
|
2022-09-05 16:57:11 -04:00
|
|
|
case "arbitrum":
|
|
|
|
return "rpc.ankr.com/arbitrum";
|
2024-01-15 23:07:48 -05:00
|
|
|
case "base":
|
|
|
|
return "rpc.ankr.com/base";
|
|
|
|
case "base-goerli":
|
|
|
|
return "rpc.ankr.com/base_goerli";
|
|
|
|
case "base-sepolia":
|
|
|
|
return "rpc.ankr.com/base_sepolia";
|
|
|
|
case "bnb":
|
|
|
|
return "rpc.ankr.com/bsc";
|
|
|
|
case "bnbt":
|
|
|
|
return "rpc.ankr.com/bsc_testnet_chapel";
|
|
|
|
case "matic":
|
|
|
|
return "rpc.ankr.com/polygon";
|
|
|
|
case "matic-mumbai":
|
|
|
|
return "rpc.ankr.com/polygon_mumbai";
|
|
|
|
case "optimism":
|
|
|
|
return "rpc.ankr.com/optimism";
|
|
|
|
case "optimism-goerli":
|
|
|
|
return "rpc.ankr.com/optimism_testnet";
|
|
|
|
case "optimism-sepolia":
|
|
|
|
return "rpc.ankr.com/optimism_sepolia";
|
2022-09-05 16:57:11 -04:00
|
|
|
}
|
2022-11-09 02:57:02 -05:00
|
|
|
(0, index_js_1.assertArgument)(false, "unsupported network", "network", name);
|
2022-09-05 16:57:11 -04:00
|
|
|
}
|
2022-11-30 15:44:23 -05:00
|
|
|
/**
|
2023-01-28 01:53:29 -05:00
|
|
|
* The **AnkrProvider** connects to the [[link-ankr]]
|
|
|
|
* JSON-RPC end-points.
|
2022-11-30 15:44:23 -05:00
|
|
|
*
|
2023-01-28 01:53:29 -05:00
|
|
|
* By default, a highly-throttled API key is used, which is
|
|
|
|
* appropriate for quick prototypes and simple scripts. To
|
|
|
|
* gain access to an increased rate-limit, it is highly
|
|
|
|
* recommended to [sign up here](link-ankr-signup).
|
2022-11-30 15:44:23 -05:00
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
class AnkrProvider extends provider_jsonrpc_js_1.JsonRpcProvider {
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* The API key for the Ankr connection.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
apiKey;
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* Create a new **AnkrProvider**.
|
|
|
|
*
|
|
|
|
* By default connecting to ``mainnet`` with a highly throttled
|
|
|
|
* API key.
|
|
|
|
*/
|
2022-11-30 15:44:23 -05:00
|
|
|
constructor(_network, apiKey) {
|
|
|
|
if (_network == null) {
|
|
|
|
_network = "mainnet";
|
|
|
|
}
|
2022-09-05 16:57:11 -04:00
|
|
|
const network = network_js_1.Network.from(_network);
|
|
|
|
if (apiKey == null) {
|
|
|
|
apiKey = defaultApiKey;
|
|
|
|
}
|
|
|
|
// Ankr does not support filterId, so we force polling
|
|
|
|
const options = { polling: true, staticNetwork: network };
|
|
|
|
const request = AnkrProvider.getRequest(network, apiKey);
|
|
|
|
super(request, network, options);
|
2022-09-15 22:58:45 -04:00
|
|
|
(0, index_js_1.defineProperties)(this, { apiKey });
|
2022-09-05 16:57:11 -04:00
|
|
|
}
|
|
|
|
_getProvider(chainId) {
|
|
|
|
try {
|
|
|
|
return new AnkrProvider(chainId, this.apiKey);
|
|
|
|
}
|
|
|
|
catch (error) { }
|
|
|
|
return super._getProvider(chainId);
|
|
|
|
}
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* Returns a prepared request for connecting to %%network%% with
|
|
|
|
* %%apiKey%%.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
static getRequest(network, apiKey) {
|
|
|
|
if (apiKey == null) {
|
|
|
|
apiKey = defaultApiKey;
|
|
|
|
}
|
2022-09-15 22:58:45 -04:00
|
|
|
const request = new index_js_1.FetchRequest(`https:/\/${getHost(network.name)}/${apiKey}`);
|
2022-09-05 16:57:11 -04:00
|
|
|
request.allowGzip = true;
|
|
|
|
if (apiKey === defaultApiKey) {
|
|
|
|
request.retryFunc = async (request, response, attempt) => {
|
|
|
|
(0, community_js_1.showThrottleMessage)("AnkrProvider");
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return request;
|
|
|
|
}
|
2022-12-30 16:35:04 -05:00
|
|
|
getRpcError(payload, error) {
|
|
|
|
if (payload.method === "eth_sendRawTransaction") {
|
|
|
|
if (error && error.error && error.error.message === "INTERNAL_ERROR: could not replace existing tx") {
|
|
|
|
error.error.message = "replacement transaction underpriced";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.getRpcError(payload, error);
|
|
|
|
}
|
2022-09-05 16:57:11 -04:00
|
|
|
isCommunityResource() {
|
|
|
|
return (this.apiKey === defaultApiKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.AnkrProvider = AnkrProvider;
|
|
|
|
//# sourceMappingURL=provider-ankr.js.map
|