2022-12-06 06:19:14 +03:00
|
|
|
/**
|
2023-01-28 09:53:29 +03:00
|
|
|
* [[link-quicknode]] provides a third-party service for connecting to
|
|
|
|
* various blockchains over JSON-RPC.
|
2022-12-06 06:19:14 +03:00
|
|
|
*
|
2023-01-28 09:53:29 +03:00
|
|
|
* **Supported Networks**
|
|
|
|
*
|
|
|
|
* - Ethereum Mainnet (``mainnet``)
|
|
|
|
* - Goerli Testnet (``goerli``)
|
|
|
|
* - Arbitrum (``arbitrum``)
|
|
|
|
* - Arbitrum Goerli Testnet (``arbitrum-goerli``)
|
|
|
|
* - Optimism (``optimism``)
|
|
|
|
* - Optimism Goerli Testnet (``optimism-goerli``)
|
|
|
|
* - Polygon (``matic``)
|
2023-02-23 14:31:09 +03:00
|
|
|
* - Polygon Mumbai Testnet (``matic-mumbai``)
|
2023-01-28 09:53:29 +03:00
|
|
|
*
|
|
|
|
* @_subsection: api/providers/thirdparty:QuickNode [providers-quicknode]
|
2022-12-06 06:19:14 +03:00
|
|
|
*/
|
|
|
|
import { defineProperties, FetchRequest, assertArgument } from "../utils/index.js";
|
|
|
|
import { showThrottleMessage } from "./community.js";
|
|
|
|
import { Network } from "./network.js";
|
|
|
|
import { JsonRpcProvider } from "./provider-jsonrpc.js";
|
|
|
|
const defaultToken = "919b412a057b5e9c9b6dce193c5a60242d6efadb";
|
|
|
|
function getHost(name) {
|
|
|
|
switch (name) {
|
|
|
|
case "mainnet":
|
|
|
|
return "ethers.quiknode.pro";
|
|
|
|
case "goerli":
|
|
|
|
return "ethers.ethereum-goerli.quiknode.pro";
|
|
|
|
//case "sepolia":
|
|
|
|
// return "sepolia.infura.io";
|
|
|
|
case "arbitrum":
|
|
|
|
return "ethers.arbitrum-mainnet.quiknode.pro";
|
|
|
|
case "arbitrum-goerli":
|
|
|
|
return "ethers.arbitrum-goerli.quiknode.pro";
|
|
|
|
case "matic":
|
|
|
|
return "ethers.matic.quiknode.pro";
|
2023-02-23 14:31:09 +03:00
|
|
|
case "matic-mumbai":
|
2022-12-06 06:19:14 +03:00
|
|
|
return "ethers.matic-testnet.quiknode.pro";
|
|
|
|
case "optimism":
|
|
|
|
return "ethers.optimism.quiknode.pro";
|
|
|
|
case "optimism-goerli":
|
|
|
|
return "ethers.optimism-goerli.quiknode.pro";
|
|
|
|
}
|
|
|
|
assertArgument(false, "unsupported network", "network", name);
|
|
|
|
}
|
|
|
|
/**
|
2023-01-28 09:53:29 +03:00
|
|
|
* The **QuickNodeProvider** connects to the [[link-quicknode]]
|
|
|
|
* JSON-RPC end-points.
|
|
|
|
*
|
|
|
|
* By default, a highly-throttled API token 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-quicknode).
|
2022-12-06 06:19:14 +03:00
|
|
|
*/
|
|
|
|
export class QuickNodeProvider extends JsonRpcProvider {
|
2023-01-28 09:53:29 +03:00
|
|
|
/**
|
|
|
|
* The API token.
|
|
|
|
*/
|
2022-12-06 06:19:14 +03:00
|
|
|
token;
|
2023-01-28 09:53:29 +03:00
|
|
|
/**
|
|
|
|
* Creates a new **QuickNodeProvider**.
|
|
|
|
*/
|
2022-12-06 06:19:14 +03:00
|
|
|
constructor(_network, token) {
|
|
|
|
if (_network == null) {
|
|
|
|
_network = "mainnet";
|
|
|
|
}
|
|
|
|
const network = Network.from(_network);
|
|
|
|
if (token == null) {
|
|
|
|
token = defaultToken;
|
|
|
|
}
|
|
|
|
const request = QuickNodeProvider.getRequest(network, token);
|
|
|
|
super(request, network, { staticNetwork: network });
|
|
|
|
defineProperties(this, { token });
|
|
|
|
}
|
|
|
|
_getProvider(chainId) {
|
|
|
|
try {
|
|
|
|
return new QuickNodeProvider(chainId, this.token);
|
|
|
|
}
|
|
|
|
catch (error) { }
|
|
|
|
return super._getProvider(chainId);
|
|
|
|
}
|
|
|
|
isCommunityResource() {
|
|
|
|
return (this.token === defaultToken);
|
|
|
|
}
|
2023-01-28 09:53:29 +03:00
|
|
|
/**
|
|
|
|
* Returns a new request prepared for %%network%% and the
|
|
|
|
* %%token%%.
|
|
|
|
*/
|
2022-12-06 06:19:14 +03:00
|
|
|
static getRequest(network, token) {
|
|
|
|
if (token == null) {
|
|
|
|
token = defaultToken;
|
|
|
|
}
|
|
|
|
const request = new FetchRequest(`https:/\/${getHost(network.name)}/${token}`);
|
|
|
|
request.allowGzip = true;
|
|
|
|
//if (projectSecret) { request.setCredentials("", projectSecret); }
|
|
|
|
if (token === defaultToken) {
|
|
|
|
request.retryFunc = async (request, response, attempt) => {
|
|
|
|
showThrottleMessage("QuickNodeProvider");
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//# sourceMappingURL=provider-quicknode.js.map
|