2020-07-14 02:12:59 -04:00
|
|
|
_section: Provider API Keys @<api-keys>
|
|
|
|
|
|
|
|
//( **TL; DR** – sign up for your own API keys with the links below to improve your application performance )//
|
|
|
|
|
|
|
|
When using a [[Provider]] backed by an API service (such as [[link-alchemy]],
|
|
|
|
[[link-etherscan]] or [[link-infura]]), the service requires an API key,
|
|
|
|
which allows each service to track individual projects and their usage and
|
|
|
|
permissions.
|
|
|
|
|
|
|
|
The ethers library offers default API keys for each service, so that each
|
|
|
|
[[Provider]] works out-of-the-box.
|
|
|
|
|
2020-11-22 23:03:50 -05:00
|
|
|
These API keys are provided as a community resource by the backend services
|
2020-07-14 02:12:59 -04:00
|
|
|
for low-traffic projects and for early prototyping.
|
|
|
|
|
|
|
|
Since these API keys are shared by all users (that have not acquired their
|
2020-10-03 13:30:15 -03:00
|
|
|
own API key), they are aggressively throttled which means retries occur more
|
2020-07-14 02:12:59 -04:00
|
|
|
frequently and the responses are slower.
|
|
|
|
|
|
|
|
It is **highly recommended** that you sign up for a free API key from each service for their
|
|
|
|
free tier, which (depending on the service) includes many advantages:
|
|
|
|
|
|
|
|
- a much **higher request rate** and concurrent request limit
|
|
|
|
- **faster** responses with fewer retries and timeouts
|
|
|
|
- useful **metric tracking** for performance tuning and to analyze your customer behaviour
|
|
|
|
- more **advanced APIs**, such as archive data or advanced log queries
|
|
|
|
|
2022-03-19 02:48:17 -04:00
|
|
|
_subsection: Etherscan @NOTE<(see the [[EtherscanProvider]])> @<api-keys--etherscan>
|
2020-07-14 02:12:59 -04:00
|
|
|
|
|
|
|
Etherscan is an Ethereum block explorer, which is possibly the most useful
|
|
|
|
developer tool for building and debugging Ethereum applications.
|
|
|
|
|
|
|
|
They offer an extensive collection of API endpoints which provide all the
|
|
|
|
operations required to interact with the Ethereum Blockchain.
|
|
|
|
|
|
|
|
[Sign up for a free API key on Etherscan](link-etherscan-signup)
|
|
|
|
|
|
|
|
**Benefits:**
|
|
|
|
|
|
|
|
- higher rate limit (since you are not using the [shared rate limit](link-etherscan-ratelimit))
|
|
|
|
- customer usage metrics
|
|
|
|
|
2022-03-19 02:48:17 -04:00
|
|
|
_definition: **Networks:**
|
|
|
|
``homestead``, ``ropsten``, ``rinkeby``, ``goerli`` and ``kovan``.
|
|
|
|
|
|
|
|
|
|
|
|
_subsection: INFURA @NOTE<(see the [[InfuraProvider]])> @<api-keys--infura>
|
2020-07-14 02:12:59 -04:00
|
|
|
|
|
|
|
The INFURA service has been around for quite some time and is very robust
|
2020-11-22 23:03:50 -05:00
|
|
|
and reliable and highly recommended.
|
2020-07-14 02:12:59 -04:00
|
|
|
|
|
|
|
They offer a standard JSON-RPC interface and a WebSocket interface, which makes
|
2022-02-03 15:34:40 -05:00
|
|
|
interaction with standard tools versatile, simple and straightforward.
|
2020-07-14 02:12:59 -04:00
|
|
|
|
|
|
|
[Sign up for a free Project ID on INFURA](link-infura-signup)
|
|
|
|
|
|
|
|
**Benefits:**
|
|
|
|
|
|
|
|
- higher rate limit
|
|
|
|
- customer usage metrics
|
|
|
|
- access to archive data (requires paid upgrade)
|
|
|
|
|
2022-03-19 02:48:17 -04:00
|
|
|
_definition: **Networks:**
|
|
|
|
``homestead``, ``ropsten``, ``rinkeby``, ``goerli``, ``kovan``, ``matic``,
|
|
|
|
``maticmum``, ``optimism``, ``optimism-kovan``, ``arbitrum`` and
|
|
|
|
``arbitrum-rinkeby``.
|
|
|
|
|
|
|
|
|
|
|
|
_subsection: Alchemy @NOTE<(see the [[AlchemyProvider]])> @<api-keys--alchemy>
|
2020-07-14 02:12:59 -04:00
|
|
|
|
|
|
|
The Alchemy service has been around a few years and is also very robust
|
|
|
|
and reliable.
|
|
|
|
|
|
|
|
They offer a standard JSON-RPC interface and a WebSocket interface, as well
|
|
|
|
as a collection of advanced APIs for interacting with tokens and to assist
|
|
|
|
with debugging.
|
|
|
|
|
|
|
|
[Sign up for a free API key on Alchemy](link-alchemy-signup)
|
|
|
|
|
|
|
|
**Benefits:**
|
|
|
|
|
|
|
|
- higher rate limit
|
|
|
|
- customer usage metrics
|
|
|
|
- access to advanced token balance and metadata APIs
|
|
|
|
- access to advanced debugging trace and revert reason APIs
|
|
|
|
|
2022-03-19 02:48:17 -04:00
|
|
|
_definition: **Networks:**
|
|
|
|
``homestead``, ``ropsten``, ``rinkeby``, ``goerli``, ``kovan``, ``matic``,
|
|
|
|
``maticmum``, ``optimism``, ``optimism-kovan``, ``arbitrum`` and
|
|
|
|
``arbitrum-rinkeby``.
|
|
|
|
|
2020-11-22 23:03:50 -05:00
|
|
|
|
2022-03-19 02:48:17 -04:00
|
|
|
_subsection: Pocket Gateway @NOTE<(see the [[PocketProvider]])> @<api-keys--pocket-gateway>
|
|
|
|
|
|
|
|
They offer a standard JSON-RPC interface using either a load-balanced
|
|
|
|
network or non-load-balanced fleet.
|
2020-11-22 23:03:50 -05:00
|
|
|
|
|
|
|
[Sign up for a free API key on Pocket](link-pocket-signup)
|
|
|
|
|
|
|
|
**Benefits:**
|
|
|
|
|
|
|
|
- customer usage metrics
|
|
|
|
- decentralized Access to Blockchain Infrastructure
|
|
|
|
- Stake as opposed to paying a monthly fee
|
|
|
|
- Highly redundant global set of nodes incentivized by cryptoeconomic incentives
|
|
|
|
|
2022-03-19 02:48:17 -04:00
|
|
|
_definition: **Networks:**
|
|
|
|
``homestead``
|
|
|
|
|
|
|
|
|
|
|
|
_subsection: Ankr @NOTE<(see the [[AnkrProvider]])> @<api-keys--ankr>
|
|
|
|
|
|
|
|
They offer a standard JSON-RPC interface and have fairly high capacity without
|
|
|
|
the need for an API key early on in the development cycle.
|
|
|
|
|
|
|
|
[See their free tier features on Ankr](link-ankr-public)
|
|
|
|
|
|
|
|
**Benefits:**
|
|
|
|
|
|
|
|
- higher rate limit
|
|
|
|
- customer usage metrics
|
|
|
|
- access to archive data (requires paid upgrade)
|
|
|
|
|
|
|
|
_definition: **Networks:**
|
|
|
|
``homestead``, ``matic`` and ``arbitrum``
|
|
|
|
|
2020-07-14 02:12:59 -04:00
|
|
|
|
|
|
|
_subsection: Creating a Default Provider @<api-keys--getDefaultProvider>
|
|
|
|
|
|
|
|
The [default provider](providers-getDefaultProvider) connects to multiple
|
|
|
|
backends and verifies their results internally, making it simple to have
|
|
|
|
a high level of trust in third-party services.
|
|
|
|
|
|
|
|
A second optional parameter allows API keys to be specified to each
|
|
|
|
Provider created internally and any API key omitted will fallback onto
|
|
|
|
using the default API key for that service.
|
|
|
|
|
|
|
|
It is **highly recommended** that you provide an API for each service, to
|
|
|
|
maximize your applications performance.
|
|
|
|
|
2022-03-19 02:48:17 -04:00
|
|
|
If the API key ``"-"`` is used, the corresponding Provider will be omitted.
|
|
|
|
|
2020-07-14 02:12:59 -04:00
|
|
|
_code: Passing API Keys into getDefaultProvider @lang<script>
|
|
|
|
|
|
|
|
// Use the mainnet
|
|
|
|
const network = "homestead";
|
|
|
|
|
|
|
|
// Specify your own API keys
|
|
|
|
// Each is optional, and if you omit it the default
|
|
|
|
// API key for that service will be used.
|
|
|
|
const provider = ethers.getDefaultProvider(network, {
|
|
|
|
etherscan: YOUR_ETHERSCAN_API_KEY,
|
|
|
|
infura: YOUR_INFURA_PROJECT_ID,
|
2020-11-22 23:03:50 -05:00
|
|
|
// Or if using a project secret:
|
|
|
|
// infura: {
|
|
|
|
// projectId: YOUR_INFURA_PROJECT_ID,
|
|
|
|
// projectSecret: YOUR_INFURA_PROJECT_SECRET,
|
|
|
|
// },
|
|
|
|
alchemy: YOUR_ALCHEMY_API_KEY,
|
|
|
|
pocket: YOUR_POCKET_APPLICATION_KEY
|
|
|
|
// Or if using an application secret key:
|
|
|
|
// pocket: {
|
|
|
|
// applicationId: ,
|
|
|
|
// applicationSecretKey:
|
2022-03-19 02:48:17 -04:00
|
|
|
// },
|
|
|
|
ankr: YOUR_ANKR_API_KEY
|
2020-07-14 02:12:59 -04:00
|
|
|
});
|