Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /** * [[link-ankr]] provides a third-party service for connecting to * various blockchains over JSON-RPC. * * **Supported Networks** * * - Ethereum Mainnet (``mainnet``) * - Goerli Testnet (``goerli``) * - Sepolia Testnet (``sepolia``) * - Arbitrum (``arbitrum``) * - 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``) * * @_subsection: api/providers/thirdparty:Ankr [providers-ankr] */ import { defineProperties, FetchRequest, assertArgument } from "../utils/index.js"; import { AbstractProvider } from "./abstract-provider.js"; import { showThrottleMessage } from "./community.js"; import { Network } from "./network.js"; import { JsonRpcProvider } from "./provider-jsonrpc.js"; import type { CommunityResourcable } from "./community.js"; import type { Networkish } from "./network.js"; import type { JsonRpcError, JsonRpcPayload } from "./provider-jsonrpc.js"; const defaultApiKey = "9f7d929b018cdffb338517efa06f58359e86ff1ffd350bc889738523659e7972"; function getHost(name: string): string { switch (name) { case "mainnet": return "rpc.ankr.com/eth"; case "goerli": return "rpc.ankr.com/eth_goerli"; case "sepolia": return "rpc.ankr.com/eth_sepolia"; case "arbitrum": return "rpc.ankr.com/arbitrum"; 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"; } assertArgument(false, "unsupported network", "network", name); } /** * The **AnkrProvider** connects to the [[link-ankr]] * JSON-RPC end-points. * * 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). */ export class AnkrProvider extends JsonRpcProvider implements CommunityResourcable { /** * The API key for the Ankr connection. */ readonly apiKey!: string; /** * Create a new **AnkrProvider**. * * By default connecting to ``mainnet`` with a highly throttled * API key. */ constructor(_network?: Networkish, apiKey?: null | string) { if (_network == null) { _network = "mainnet"; } const network = 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); defineProperties<AnkrProvider>(this, { apiKey }); } _getProvider(chainId: number): AbstractProvider { try { return new AnkrProvider(chainId, this.apiKey); } catch (error) { } return super._getProvider(chainId); } /** * Returns a prepared request for connecting to %%network%% with * %%apiKey%%. */ static getRequest(network: Network, apiKey?: null | string): FetchRequest { if (apiKey == null) { apiKey = defaultApiKey; } const request = new FetchRequest(`https:/\/${ getHost(network.name) }/${ apiKey }`); request.allowGzip = true; if (apiKey === defaultApiKey) { request.retryFunc = async (request, response, attempt) => { showThrottleMessage("AnkrProvider"); return true; }; } return request; } getRpcError(payload: JsonRpcPayload, error: JsonRpcError): 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); } isCommunityResource(): boolean { return (this.apiKey === defaultApiKey); } } |