English | 中文
etherscan-api
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. :wink:
Usage
go get github.com/nanmu42/etherscan-api
Create an API instance and off you go. :rocket:
import (
"github.com/nanmu42/etherscan-api"
"fmt"
)
func main() {
client := etherscan.New(etherscan.Mainnet, "[your API key]")
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) {
}
balance, err := client.AccountBalance("0x281055afc982d96fab65b3a49cac8b878184cb16")
if err != nil {
panic(err)
}
fmt.Println(balance.Int())
tokenBalance, err := client.TokenBalance("contractAddress", "holderAddress")
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. :smile:
License
Use of this work is governed by an MIT License.
You may find a license copy in project root.