Skip to content

🎸 Golang client for Ethereum Etherscan API (and its families like BscScan) / Golang 以太坊 Etherscan API库(也支持同一家族的BscScan)

License

Notifications You must be signed in to change notification settings

nanmu42/etherscan-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0d2eec1 · Mar 12, 2024
Feb 14, 2023
Dec 5, 2021
Jul 28, 2018
Oct 15, 2021
Oct 15, 2021
Dec 12, 2022
Dec 12, 2022
Oct 15, 2021
Oct 15, 2021
May 16, 2021
Jul 31, 2018
Aug 5, 2018
Aug 5, 2018
Aug 6, 2018
Jul 28, 2018
Aug 4, 2018
Oct 25, 2022
Oct 25, 2022
Dec 13, 2022
Dec 12, 2022
Sep 8, 2018
Aug 4, 2018
Mar 3, 2022
Aug 9, 2022
Aug 19, 2021
Feb 21, 2020
Mar 11, 2024
Nov 12, 2020
Aug 6, 2018
Aug 6, 2018
Aug 6, 2018
Aug 5, 2018

Repository files navigation

English | 中文

etherscan-api

GoDoc CI status codecov Go Report Card

Golang client for the Etherscan.io API(and its families like BscScan), with nearly full implementation(accounts, transactions, tokens, contracts, blocks, stats), full network support(Mainnet, Ropsten, Kovan, Rinkby, Goerli, Tobalaba), and only depending on standard library. 😉

Usage

go get github.com/nanmu42/etherscan-api

Create an API instance and off you go. 🚀

import (
	"github.com/nanmu42/etherscan-api"
	"fmt"
)

func main() {
	// create a API client for specified ethereum net
	// there are many pre-defined network in package
	client := etherscan.New(etherscan.Mainnet, "[your API key]")
	
	// or, if you are working with etherscan-family API like BscScan
	//
	// client := etherscan.NewCustomized(etherscan.Customization{
	// Timeout:       15 * time.Second,
	// Key:           "You key here",
	// BaseURL:       "https://api.bscscan.com/api?",
	// Verbose:       false,
	// })

	// (optional) add hooks, e.g. for rate limit
	client.BeforeRequest = func(module, action string, param map[string]interface{}) error {
		// ...
	}
	client.AfterRequest = func(module, action string, param map[string]interface{}, outcome interface{}, requestErr error) {
		// ...
	}

	// check account balance
	balance, err := client.AccountBalance("0x281055afc982d96fab65b3a49cac8b878184cb16")
	if err != nil {
		panic(err)
	}
	// balance in wei, in *big.Int type
	fmt.Println(balance.Int())

	// check token balance
	tokenBalance, err := client.TokenBalance("contractAddress", "holderAddress")

	// check ERC20 transactions from/to a specified address
	transfers, err := client.ERC20Transfers("contractAddress", "address", startBlock, endBlock, page, offset)
}

You may find full method list at GoDoc.

Etherscan API Key

You may apply for an API key on etherscan.

The Etherscan Ethereum Developer APIs are provided as a community service and without warranty, so please just use what you need and no more. They support both GET/POST requests and a rate limit of 5 requests/sec (exceed and you will be blocked).

Paperwork Things

I am not from Etherscan and I just find their service really useful, so I implement this. 😄

License

Use of this work is governed by an MIT License.

You may find a license copy in project root.