#
API Providers

There are many services which offer a web API for accessing the Ethereum Blockchain. These Providers allow connecting to them, which simplifies development, since you do not need to run your own instance or cluster of Ethereum nodes.

However, this reliance on third-party services can reduce resiliance, security and increase the amount of required trust. To mitigate these issues, it is recommended you use a Default Provider.

##
EtherscanProvider inherits Provider
source

The EtherscanProvider is backed by a combination of the various Etherscan APIs.

new ethers.providers.EtherscanProvider( [ network = "homestead" , [ apiKey ] ] )

Create a new EtherscanProvider connected to network with the optional apiKey.

The network may be specified as string for a common network name, a number for a common chain ID or a [Network Object]provider-(network).

If no apiKey is provided, a shared API key will be used, which may result in reduced performance and throttled requests. It is highly recommended for production, you register with Etherscan for your own API key.

Note: Default API keys

If no apiKey is provided, a shared API key will be used, which may result in reduced performance and throttled requests.

It is highly recommended for production, you register with Etherscan for your own API key.

Supported Networks

- Homestead (Mainnet)
- Ropsten (proof-of-work testnet)
- Rinkeby (proof-of-authority testnet)
- Görli (clique testnet)
- Kovan (proof-of-authority testnet)

Etherscan Examples
// Connect to mainnet (homestead) provider = new EtherscanProvider(); // Connect to rinkeby testnet (these are equivalent) provider = new EtherscanProvider("rinkeby"); provider = new EtherscanProvider(4); const network = ethers.providers.getNetwork("rinkeby"); // { // chainId: 4, // ensAddress: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e', // name: 'rinkeby' // } provider = new EtherscanProvider(network); // Connect to mainnet (homestead) with an API key provider = new EtherscanProvider(null, apiKey); provider = new EtherscanProvider("homestead", apiKey);
provider.getHistory( address ) ⇒ Array< History >
source

@TODO... Explain

##
InfuraProvider inherits UrlJsonRpcProvider
source

The InfuraProvider is backed by the popular INFURA Ethereum service.

new ethers.providers.InfuraProvider( [ network = "homestead" , [ apiKey ] ] )

Create a new InfuraProvider connected to network with the optional apiKey.

The network may be specified as string for a common network name, a number for a common chain ID or a [Network Object]provider-(network).

The apiKey can be a string Project ID or an object with the properties `projectId` and `projectSecret` to specify a Project Secret which can be used on non-public sources (like on a server) to further secure your API access and quotas.

Note: Default API keys

If no apiKey is provided, a shared API key will be used, which may result in reduced performance and throttled requests.

It is highly recommended for production, you register with INFURA for your own API key.

Supported Networks

- Homestead (Mainnet)
- Ropsten (proof-of-work testnet)
- Rinkeby (proof-of-authority testnet)
- Görli (clique testnet)
- Kovan (proof-of-authority testnet)

INFURA Examples
// Connect to mainnet (homestead) provider = new InfuraProvider(); // Connect to the ropsten testnet // (see EtherscanProvider above for other network examples) provider = new InfuraProvider("ropsten"); // Connect to mainnet with a Project ID (these are equivalent) provider = new InfuraProvider(null, projectId); provider = new InfuraProvider("homestead", projectId); // Connect to mainnet with a Project ID and Project Secret provider = new InfuraProvider("homestead", { projectId: projectId, projectSecret: projectSecret });

##
AlchemyProvider inherits UrlJsonRpcProvider
source

The AlchemyProvider is backed by Alchemy.

new ethers.providers.AlchemyProvider( [ network = "homestead" , [ apiKey ] ] )

Create a new AlchemyProvider connected to network with the optional apiKey.

The network may be specified as string for a common network name, a number for a common chain ID or a Network Object.

Note: Default API keys

If no apiKey is provided, a shared API key will be used, which may result in reduced performance and throttled requests.

It is highly recommended for production, you register with Alchemy for your own API key.

Supported Networks

- Homestead (Mainnet)
- Ropsten (proof-of-work testnet)
- Rinkeby (proof-of-authority testnet)
- Görli (clique testnet)
- Kovan (proof-of-authority testnet)

Alchemy Examples
// Connect to mainnet (homestead) provider = new AlchemyProvider(); // Connect to the ropsten testnet // (see EtherscanProvider above for other network examples) provider = new AlchemyProvider("ropsten"); // Connect to mainnet with an API key (these are equivalent) provider = new AlchemyProvider(null, apiKey); provider = new AlchemyProvider("homestead", apiKey);

##
CloudflareProvider inherits UrlJsonRpcProvider
source

The CloudflareProvider is backed by the Cloudflare Ethereum Gateway.

new ethers.providers.CloudflareProvider( )

Create a new CloudflareProvider connected to mainnet (i.e. "homestead").

Supported Networks

- Homestead (Mainnet)

Cloudflare Examples
// Connect to mainnet (homestead) provider = new CloudflareProvider();
The content of this site is licensed under the Creative Commons License. Last modified on June 12, 2020, 7:17pm.