LogoLogo
HomeMetadata APIAPI PROTwitter
Etherscan V2
Etherscan V2
  • Introduction
  • Chef's Pick
  • Rate Limits
  • V1 to V2 API Migration Guide
  • ✨Getting Started
    • Creating an Account
    • Getting an API Key
    • Supported Chains
    • Supported Endpoints
  • 🎯API Endpoints
    • Nametags
    • Accounts
    • Contracts
    • Transactions
    • Blocks
    • Logs
    • Geth/Parity Proxy
    • Tokens
    • Gas Tracker
    • Stats
    • L2 Deposits/Withdrawals
    • Usage
  • 🏆API PRO
    • Etherscan API PRO
    • Metadata/Name Tag API
  • 🍳Cookbook
    • Track Uniswap V4 DEX Trades
  • Get An Address's Full Transaction History
  • 🤝Support
    • FAQ
    • Legacy V1 Docs
    • Checking Usage
    • Common Error Messages
    • Getting Help
  • Visit Etherscan.io
Powered by GitBook
On this page
  • 1. Integrating Google Apps Script
  • 2. Setting up auto refresh
  • 3. Making an API request
  • Extending and Building a Dashboard
  1. Tutorials

Integrating Google Sheets

Last updated 8 months ago

provides a convenient way to connect and import block explorer information for developers to use in your own apps and services .

Having technical knowledge is not a requirement for using APIs however, and non-developers can make use of the available endpoints to build your own dashboards and statistics by importing API data to Google Sheets .

A valid and a is required to follow along this tutorial.

1. Integrating Google Apps Script

In a new Google Sheets document, head over to Extensions > Apps Script.

We'll be utilizing an open source script called developed by and to help parse JSON responses returned by the API endpoints.

Paste the source code into the script editor, optionally you can rename the file to ImportJSON.gs.

2. Setting up auto refresh

Add a new Sheet from the small "+" icon at the bottom left and name it AutoRefresh.

Back to Google Apps Script, create a new file and name it AutoRefresh.gs. Paste in this following code.

function AutoRefresh() {  
    SpreadsheetApp.getActive().getSheetByName('AutoRefresh').getRange(1, 1).setValue(Math.random());
}

The idea of this script is to generate a random number to the AutoRefresh sheet, which is then appended to the end of the ImportJSON request.

Google Sheets only performs a new request if it detects that a formula has changed.

Select the function as AutoRefresh, event source as Time Driven, time based trigger to Minutes Timer and minute interval to Every Minute.

3. Making an API request

Once you have added both scripts, go back to Sheet1 and start making API endpoint calls with the following syntax in cell A1.

=ImportJSON("https://api.etherscan.io/v2/api?chainid=1
   &module=gastracker&action=gasoracle&apikey=YourApiKeyToken", "/result", "allHeaders", AutoRefresh!$A$1)
Parameter
Description

url

the endpoint url to make requests from, with your API Key

query

comma separated paths to import, such as /result or /result/SafeGasPrice

parseOptions

list of options to process the returned data, either noInherit, noTruncate, rawHeaders, noHeaders or allHeaders

Extending and Building a Dashboard

While the above was a straightforward method to call an API endpoint and output the response into a Google Sheet, it could use further optimizing and data formatting.

With the script in place, we can run this function every minute by going to Triggers > Add Trigger at the left panel.

The query above will return the following response, and refreshes auto-magically every minute!

Checkout some we have, simply duplicate this by going to File > Make a copy and go about customizing this to your taste!

📖
⏰
✨
🔗
prepared dashboard examples
💻
🙌
Etherscan's APIs
Etherscan API key
Google Account
ImportJSON
@bradjasper
@tommyvernieri