SDKs overview

Etherscan API offers both official and community-contributed SDKs and libraries to facilitate interaction with its services. These tools abstract the underlying HTTP requests and JSON parsing, allowing developers to integrate blockchain data retrieval and analysis capabilities into their applications with reduced boilerplate code. The Etherscan API provides direct access to Ethereum blockchain data, including transaction details, block information, and token balances Etherscan API documentation.

Developers commonly use these SDKs for tasks such as:

  • Retrieving transaction histories for specific addresses.
  • Checking ERC-20 token balances.
  • Querying block details and timestamps.
  • Interacting with smart contract ABIs to decode events or call read-only functions.
  • Monitoring gas prices and network status.

The available SDKs cater to popular programming languages, ensuring broad compatibility for various development environments. While Etherscan maintains official libraries, the open-source nature of the blockchain ecosystem also encourages a thriving community of third-party tools that expand functionality or offer alternative implementations.

Official SDKs by language

Etherscan provides official SDKs to streamline development. These libraries are typically maintained by the Etherscan team or closely supported by them, ensuring compatibility with the latest API changes and offering robust functionality. Developers can find detailed information and usage guides within the official Etherscan API documentation Etherscan API endpoints reference.

Official Etherscan API SDKs

Language Package/Library Name Installation Command Maturity/Status
Python etherscan-python pip install etherscan-python Actively Maintained
JavaScript/TypeScript etherscan-api npm install etherscan-api Actively Maintained
Go go-etherscan go get github.com/nanmu42/go-etherscan Actively Maintained
Ruby etherscan gem install etherscan Community-Supported, Stable

Installation

Installing Etherscan API SDKs typically involves using the package manager specific to the programming language. Before installation, developers should ensure they have the appropriate language runtime and package manager set up on their system. An API key from Etherscan is required for most API requests, which can be obtained by registering on the Etherscan API page.

Python Installation

To install the Python SDK, use pip:

pip install etherscan-python

Prerequisites: Python 3.6+ and pip.

JavaScript/TypeScript Installation

For Node.js projects, use npm or yarn:

npm install etherscan-api
# or
yarn add etherscan-api

Prerequisites: Node.js 10+ and npm/yarn.

Go Installation

For Go projects, use go get:

go get github.com/nanmu42/go-etherscan

Prerequisites: Go 1.13+ and a properly configured Go environment. The Go language provides a robust ecosystem for concurrent programming, which can be beneficial when handling multiple API requests Go language installation guide.

Ruby Installation

For Ruby projects, use gem:

gem install etherscan

Prerequisites: Ruby 2.5+ and RubyGems.

Quickstart example

This quickstart demonstrates how to use the etherscan-python library to retrieve the Ether balance of an Ethereum address. Ensure you have your Etherscan API key ready.

Python Quickstart: Get Ether Balance

from etherscan.accounts import Account
import os

# Replace with your actual API key or set as environment variable
API_KEY = os.environ.get("ETHERSCAN_API_KEY", "YOUR_ETHERSCAN_API_KEY")

# Replace with the Ethereum address you want to query
ADDRESS = "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe" # Example: Vitalik Buterin's address

def main():
    try:
        # Initialize the Etherscan Account API client
        # For other networks like Sepolia, use client = Account(api_key=API_KEY, net='sepolia')
        client = Account(api_key=API_KEY)
        
        # Get Ether balance of the address
        balance = client.get_eth_balance(address=ADDRESS)
        
        # Etherscan returns balance in Wei, convert to Ether (1 Ether = 10^18 Wei)
        balance_eth = int(balance) / (10**18)
        
        print(f"Address: {ADDRESS}")
        print(f"Balance (Wei): {balance}")
        print(f"Balance (Ether): {balance_eth:.4f} ETH")
        
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    main()

To run this example:

  1. Install the Python SDK: pip install etherscan-python.
  2. Replace "YOUR_ETHERSCAN_API_KEY" with your API key, or set it as an environment variable named ETHERSCAN_API_KEY.
  3. Save the code as a .py file (e.g., get_balance.py).
  4. Execute from your terminal: python get_balance.py.

This script connects to the Etherscan API, queries the balance for a specified Ethereum address, and converts the result from Wei to Ether for readability. The Etherscan API's response format is typically JSON, which these SDKs parse into native language objects Mozilla Developer Network on Content-Type headers.

Community libraries

Beyond the officially supported SDKs, the Etherscan API benefits from a vibrant community that develops and maintains additional libraries across various programming languages. These community contributions often extend functionality, provide alternative interfaces, or support niche use cases not covered by official offerings. While not directly maintained by Etherscan, many of these libraries are widely adopted and can be valuable resources for developers.

Examples of community-driven efforts include:

  • PHP: Libraries for PHP developers to interact with Etherscan, often found on platforms like GitHub. These typically leverage standard HTTP client libraries within PHP to make API calls.
  • Java: While less common for direct Etherscan interaction compared to Web3j for general Ethereum RPC, some community libraries exist to specifically target Etherscan's public endpoints.
  • Rust: The Rust ecosystem, known for its focus on performance and safety, has seen community efforts to create wrappers for Etherscan API, often integrated into broader blockchain development frameworks.
  • PowerShell: For system administrators and developers working within Windows environments, community scripts and modules might exist to integrate Etherscan data into automation workflows.

When using community libraries, it is advisable to check their maintenance status, documentation, and community support. Resources like GitHub repositories and package manager statistics can provide insights into a library's reliability and activity. Developers should also verify that the library correctly handles API keys and adheres to Etherscan's rate limits and terms of service Etherscan Terms of Service.

Many community libraries are open-source, allowing developers to review the source code, contribute enhancements, or customize the library to fit specific project requirements. This collaborative approach fosters a rich ecosystem of tools around the Etherscan API.