From 00e4111f35444dfbba1ac65d68c4f39f7926d0ca Mon Sep 17 00:00:00 2001 From: Joel Willmore <95916148+jlwllmr@users.noreply.github.com> Date: Fri, 8 Nov 2024 15:50:19 +0000 Subject: [PATCH] Add Etherscan API page (#822) --- .../tooling/data-indexers/etherscan.mdx | 48 +++++++++++++++++++ sidebars.js | 1 + 2 files changed, 49 insertions(+) create mode 100644 docs/developers/tooling/data-indexers/etherscan.mdx diff --git a/docs/developers/tooling/data-indexers/etherscan.mdx b/docs/developers/tooling/data-indexers/etherscan.mdx new file mode 100644 index 000000000..d440b1b94 --- /dev/null +++ b/docs/developers/tooling/data-indexers/etherscan.mdx @@ -0,0 +1,48 @@ +--- +title: Etherscan +description: Use one API key across multiple chains with the Etherscan API v2 +--- + +Use the Etherscan API v2 to access data across over 50 [supported chains](https://docs.etherscan.io/etherscan-v2/getting-started/supported-chains), +including Linea, with a single API key. + +To get started, create an account on [Etherscan](https://etherscan.io/register), and then head to +the [API key page](https://etherscan.io/myapikey) and generate a new key. + +:::warning + +Although you can use the same API key across multiple chains, you can only make requests to one +chain at a time. + +::: + +From here, you can use the API key in any request, defining the chains you want to use it with: + +```javascript +async function main() { + + // query ETH balances on Ethereum Mainnet and Linea + + const chains = [1, 59144] + + for (const chain of chains) { + + const query = await fetch(`https://api.etherscan.io/v2/api + ?chainid=${chain} + &module=account + &action=balance + &address=INSERT_ADDRESS + &tag=latest&apikey=INSERT_API_KEY`) + + const response = await query.json() + + const balance = response.result + console.log(balance) + + } +} + +main() +``` + +For full details of how to use the Etherscan API v2, see the [documentation](https://docs.etherscan.io/etherscan-v2). diff --git a/sidebars.js b/sidebars.js index a94442056..802d91164 100644 --- a/sidebars.js +++ b/sidebars.js @@ -223,6 +223,7 @@ const sidebars = { }, "developers/tooling/data-indexers/dune", "developers/tooling/data-indexers/envio", + "developers/tooling/data-indexers/etherscan", "developers/tooling/data-indexers/flair", { type: "category",