Provider 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 Alchemy, Etherscan or 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.

These API keys are provided as a community resource by the backend services for low-traffic projects and for early prototyping.

Since these API keys are shared by all users (that have not acquired their own API key), they are aggressively throttled which means retries occur more 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:

Etherscan(see the EtherscanProvider)

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

Benefits:

Networks:

homestead, goerli, sepolia, matic. maticmum, arbitrum, arbitrum-goerli, optimism and optimism-goerli.

INFURA(see the InfuraProvider)

The INFURA service has been around for quite some time and is very robust and reliable and highly recommended.

They offer a standard JSON-RPC interface and a WebSocket interface, which makes interaction with standard tools versatile, simple and straightforward.

Sign up for a free Project ID on INFURA

Benefits:

Networks:

homestead, goerli, sepolia, matic. maticmum, arbitrum, arbitrum-goerli, optimism and optimism-goerli.

Alchemy(see the AlchemyProvider)

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

Benefits:

Networks:

homestead, goerli, matic. maticmum, arbitrum, arbitrum-goerli, optimism and optimism-goerli.

Pocket Gateway(see the PocketProvider)

They offer a standard JSON-RPC interface using either a load-balanced network or non-load-balanced fleet.

Sign up for a free API key on Pocket

Benefits:

Networks:

homestead

Ankr(see the AnkrProvider)

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

Benefits:

Networks:

homestead, matic and arbitrum

Creating a Default Provider

The default provider 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.

If the API key "-" is used, the corresponding Provider will be omitted.

Passing API Keys into getDefaultProvider
// 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, // 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: // }, ankr: YOUR_ANKR_API_KEY });