ethers.js/docs/v5/api-keys/index.html

118 lines
14 KiB
HTML
Raw Permalink Normal View History

2020-09-08 01:12:15 -04:00
<!DOCTYPE html>
<html class="paged">
<head>
<title>Provider API Keys</title>
<link rel="stylesheet" type="text/css" href="/v5/static/style.css">
2021-02-08 15:26:10 -05:00
<meta property="og:title" content="Provider API Keys"/>
<meta property="og:description" content="Documentation for ethers, a complete, tiny and simple Ethereum library."/>
<meta property="og:image" content="/v5/static/social.jpg"/>
2020-09-08 01:12:15 -04:00
</head>
<body>
<div class="sidebar">
<div class="header">
<div class="logo"><a href="/v5/"><div class="image"></div><div class="name">ethers</div><div class="version">v5.0</div></a></div>
2020-11-22 23:07:13 -05:00
<div class="search"><form action="/v5/search/" method="GET"><input name="search" id="search" /></form><span class="search-icon">&#9906;</span></div>
2020-09-08 01:12:15 -04:00
</div>
<div class="toc"><div>
2021-02-08 15:26:10 -05:00
<div class="link title"><a href="/v5/">Documentation</a></div><div class="base show link depth-1"><a href="/v5/getting-started/">Getting Started</a></div><div class="base show link depth-1"><a href="/v5/concepts/">Ethereum Basics</a></div><div class="hide link depth-2"><a href="/v5/concepts/events/">Events</a></div><div class="hide link depth-2"><a href="/v5/concepts/gas/">Gas</a></div><div class="hide link depth-2"><a href="/v5/concepts/security/">Security</a></div><div class="hide link depth-2"><a href="/v5/concepts/best-practices/">Best Practices</a></div><div class="base myself ancestor ancestor show link depth-1"><a href="/v5/api-keys/">Provider API Keys</a></div><div class="link show child depth-2"><a href="#api-keys--etherscan">Etherscan</a></div><div class="link show child depth-2"><a href="#api-keys--infura">INFURA</a></div><div class="link show child depth-2"><a href="#api-keys--alchemy">Alchemy</a></div><div class="link show child depth-2"><a href="#api-keys--pocket-gateway">Pocket Gateway</a></div><div class="link show child depth-2"><a href="#api-keys--getDefaultProvider">Creating a Default Provider</a></div><div class="base show link depth-1"><a href="/v5/api/">Application Programming Interface</a></div><div class="hide link depth-2"><a href="/v5/api/providers/">Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/provider/">Provider</a></div><div class="hide link depth-3"><a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><div class="hide link depth-3"><a href="/v5/api/providers/api-providers/">API Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/other/">Other Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/types/">Types</a></div><div class="hide link depth-2"><a href="/v5/api/signer/">Signers</a></div><div class="hide link depth-2"><a href="/v5/api/contract/">Contract Interaction</a></div><div class="hide link depth-3"><a href="/v5/api/contract/contract/">Contract</a></div><div class="hide link depth-3"><a href="/v5/api/contract/contract-factory/">ContractFactory</a></div><div class="hide link depth-3"><a href="/v5/api/contract/example/">Example: ERC-20 Contract</a></div><div class="hide link depth-2"><a href="/v5/api/utils/">Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/abi/">Application Binary Interface</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/coder/">AbiCoder</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/formats/">ABI Formats</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/fragments/">Fragments</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/interface/">Interface</a></div><div class="hide link depth-3"><a href="/v5/api/utils/address/">Addresses</a></div><div class="hide link depth-3"><a href="/v5/api/utils/bignumber/">BigNumber</a></div><div class="hide link depth-3"><a href="/v5/api/utils/bytes/">Byte Manipulation</a></div><div class="hide link depth-3"><a href="/v5/api/utils/constants/">Constants</a></div><div class="hide link depth-3"><a href="/v5/api/utils/display-logic/">Display Logic and Input</a></div><div class="hide link depth-3"><a href="/v5/api/utils/encoding/">Encoding Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/fixednumber/">FixedNumber</a></div><div class="hide link depth-3"><a href="/v5/api/utils/hashing/">Hashing Algorithms</a></div><div class="hide link depth-3"><a href="/v5/api/utils/hdnode/">HD Wallet</a></div><div class="hide link depth-3"><a href="/v5/api/utils/logger/">Logging</a></div><div class="hide link depth-3"><a href="/v5/api/utils/properties/">Property Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/signing-key/">Signing Key</a></div><div class="hide link depth-3"><a href="/v5/api/utils/strings/">Strings</a></div><div class="hide link depth-3"><a href="/v5/api/utils/transactions/">Transactions</a></div><div class="hide link depth-3"><a href="/v5/api/utils/web/">Web Utilities</a></div><div class="hide l
2020-09-08 01:12:15 -04:00
</div></div>
2020-11-22 23:07:13 -05:00
<div class="footer">
<a href="/v5/single-page/">Single Page</a>
</div>
2020-09-08 01:12:15 -04:00
</div>
<div class="content">
<div class="breadcrumbs"><a href="/v5/">Documentation</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<span class="current">Provider API Keys</span></div>
<a name="api-keys"></a><a name="api-keys"></a><h1 class="show-anchors"><div>Provider API Keys<div class="anchors"><a class="self" href="/v5/api-keys/#api-keys"></a></div></div></h1><p><i>( <b>TL; DR</b> &ndash; sign up for your own API keys with the links below to improve your application performance )</i></p>
<p>When using a <a href="/v5/api/providers/provider/">Provider</a> backed by an API service (such as <a href="https://alchemyapi.io">Alchemy</a>, <a href="https://etherscan.io">Etherscan</a> or <a href="https://infura.io">INFURA</a>), the service requires an API key, which allows each service to track individual projects and their usage and permissions.</p>
<p>The ethers library offers default API keys for each service, so that each <a href="/v5/api/providers/provider/">Provider</a> works out-of-the-box.</p>
2020-11-22 23:07:13 -05:00
<p>These API keys are provided as a community resource by the backend services for low-traffic projects and for early prototyping.</p>
2020-09-08 01:12:15 -04:00
2020-11-22 23:07:13 -05:00
<p>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.</p>
2020-09-08 01:12:15 -04:00
<p>It is <b>highly recommended</b> that you sign up for a free API key from each service for their free tier, which (depending on the service) includes many advantages:</p>
<p><ul><li>a much <b>higher request rate</b> and concurrent request limit </li><li><b>faster</b> responses with fewer retries and timeouts </li><li>useful <b>metric tracking</b> for performance tuning and to analyze your customer behaviour </li><li>more <b>advanced APIs</b>, such as archive data or advanced log queries </li></ul></p>
<a name="api-keys--etherscan"></a><a name="api-keys--api-keys--etherscan"></a><h2 class="show-anchors"><div>Etherscan<div class="anchors"><a class="self" href="/v5/api-keys/#api-keys--etherscan"></a></div></div></h2><p>Etherscan is an Ethereum block explorer, which is possibly the most useful developer tool for building and debugging Ethereum applications.</p>
<p>They offer an extensive collection of API endpoints which provide all the operations required to interact with the Ethereum Blockchain.</p>
<p><a href="https://etherscan.io/apis">Sign up for a free API key on Etherscan</a></p>
<p><b>Benefits:</b></p>
<p><ul><li>higher rate limit (since you are not using the <a href="https://info.etherscan.com/api-return-errors/">shared rate limit</a>) </li><li>customer usage metrics </li></ul></p>
2020-11-22 23:07:13 -05:00
<a name="api-keys--infura"></a><a name="api-keys--api-keys--infura"></a><h2 class="show-anchors"><div>INFURA<div class="anchors"><a class="self" href="/v5/api-keys/#api-keys--infura"></a></div></div></h2><p>The INFURA service has been around for quite some time and is very robust and reliable and highly recommended.</p>
2020-09-08 01:12:15 -04:00
<p>They offer a standard JSON-RPC interface and a WebSocket interface, which makes interaction with standard tools versatile, simple and straight forward.</p>
<p><a href="https://infura.io/register">Sign up for a free Project ID on INFURA</a></p>
<p><b>Benefits:</b></p>
<p><ul><li>higher rate limit </li><li>customer usage metrics </li><li>access to archive data (requires paid upgrade) </li></ul></p>
<a name="api-keys--alchemy"></a><a name="api-keys--api-keys--alchemy"></a><h2 class="show-anchors"><div>Alchemy<div class="anchors"><a class="self" href="/v5/api-keys/#api-keys--alchemy"></a></div></div></h2><p>The Alchemy service has been around a few years and is also very robust and reliable.</p>
<p>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.</p>
2020-11-22 23:07:13 -05:00
<p><a href="https://dashboard.alchemyapi.io/signup?referral=55a35117-028e-4b7c-9e47-e275ad0acc6d">Sign up for a free API key on Alchemy</a></p>
2020-09-08 01:12:15 -04:00
<p><b>Benefits:</b></p>
<p><ul><li>higher rate limit </li><li>customer usage metrics </li><li>access to advanced token balance and metadata APIs </li><li>access to advanced debugging trace and revert reason APIs </li></ul></p>
2020-11-22 23:07:13 -05:00
<a name="api-keys--pocket-gateway"></a><a name="api-keys--api-keys--pocket-gateway"></a><h2 class="show-anchors"><div>Pocket Gateway<div class="anchors"><a class="self" href="/v5/api-keys/#api-keys--pocket-gateway"></a></div></div></h2><p><a href="https://pokt.network/pocket-gateway-ethereum-mainnet/">Sign up for a free API key on Pocket</a></p>
<p><b>Benefits:</b></p>
<p><ul><li>customer usage metrics </li><li>decentralized Access to Blockchain Infrastructure </li><li>Stake as opposed to paying a monthly fee </li><li>Highly redundant global set of nodes incentivized by cryptoeconomic incentives </li></ul></p>
2020-09-08 01:12:15 -04:00
<a name="api-keys--getDefaultProvider"></a><a name="api-keys--api-keys--getDefaultProvider"></a><h2 class="show-anchors"><div>Creating a Default Provider<div class="anchors"><a class="self" href="/v5/api-keys/#api-keys--getDefaultProvider"></a></div></div></h2><p>The <a href="/v5/api/providers/#providers-getDefaultProvider">default provider</a> connects to multiple backends and verifies their results internally, making it simple to have a high level of trust in third-party services.</p>
<p>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.</p>
<p>It is <b>highly recommended</b> that you provide an API for each service, to maximize your applications performance.</p>
<div class="code-title"><div>Passing API Keys into getDefaultProvider</div></div><div class="code"><span class="comment">// Use the mainnet
</span>const network = "homestead";
<span class="comment">// Specify your own API keys
</span><span class="comment">// Each is optional, and if you omit it the default
</span><span class="comment">// API key for that service will be used.
</span>const provider = ethers.getDefaultProvider(network, {
etherscan: YOUR_ETHERSCAN_API_KEY,
infura: YOUR_INFURA_PROJECT_ID,
2020-11-22 23:07:13 -05:00
<span class="comment"> // Or if using a project secret:
</span><span class="comment"> // infura: {
</span><span class="comment"> // projectId: YOUR_INFURA_PROJECT_ID,
</span><span class="comment"> // projectSecret: YOUR_INFURA_PROJECT_SECRET,
</span><span class="comment"> // },
</span> alchemy: YOUR_ALCHEMY_API_KEY,
pocket: YOUR_POCKET_APPLICATION_KEY
<span class="comment"> // Or if using an application secret key:
</span><span class="comment"> // pocket: {
</span><span class="comment"> // applicationId: ,
</span><span class="comment"> // applicationSecretKey:
</span><span class="comment"> // }
</span>});
2020-09-08 01:12:15 -04:00
</div>
<div class="footer">
2020-11-22 23:07:13 -05:00
<div class="nav previous"><a href="/v5/concepts/best-practices/"><span class="arrow">&larr;</span>Best Practices</a></div>
2020-09-08 01:12:15 -04:00
<div class="nav next"><a href="/v5/api/">Application Programming Interface<span class="arrow">&rarr;</span></a></div>
</div>
2021-02-08 15:26:10 -05:00
<div class="copyright">The content of this site is licensed under the <a href="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons License</a>. Generated on February 8, 2021, 3:25pm.</div>
2020-09-08 01:12:15 -04:00
</div>
<script src="/v5/static/script.js" type="text/javascript"></script>
2020-11-22 23:07:13 -05:00
<!--EXTRASCRIPT-->
2020-09-08 01:12:15 -04:00
</body>
</html>