To get started using the GraphQL Etherscan API, follow these steps:
- Clone this repository
- Run
npm install
to install dependencies - Create an Etherscan API key (explained below)
- Start the Apollo server (explained below)
- Make GraphQL queries against the server (example below)
Wrapping the Etherscan REST APIs in a GraphQL API provides the following benefits:
- Query multiple related resources in a single API call
- Strong typing system
- Intuitive query language
- Built-in documentation
To use the Etherscan APIs, you'll need an API key. Follow these steps:
- Sign up for an Etherscan account at https://etherscan.io/register
- Go to https://etherscan.io/myapikey to generate an API key
- Add the API key to a
.env
file asETHERSCAN_API=your_api_key
The GraphQL API wraps the following Etherscan REST endpoints:
etherBalanceByAddress
- Get ETH balance for an addresstotalSupplyOfEther
- Get total ETH supplylatestEthereumPrice
- Get latest ETH priceblockConfirmationTime
- Get estimated block confirmation time
See the schema.graphql
file for details.
Starting the Apollo GraphQL Server:
- Open your terminal on VSCode
- Run the following command to start the server:
node index.js
- Upon successful startup, you should see this message: 🚀 Server ready at http://localhost:9000/
- Access the Apollo Server by navigating to http://localhost:9000 on your browser
Below is a sample GraphQL query to fetch the necessary data from Etherscan
query {
etherBalanceByAddress {
message
result
}
totalSupplyOfEther {
message
result
}
latestEthereumPrice {
message
result {
ethbtc
ethusd
ethusd_timestamp
}
}
blockConfirmationTime {
message
result
}
}