Golang client for the Etherscan.io API(and its families like BscScan).
- Full implementation of Etherscan API, such as (accounts, transactions, tokens, contracts, blocks, stats)
- network support (Mainnet, Ropsten, Kovan, Rinkby, Goerli, BNBChain, Poloygan, etc.)
- depending on
go-ethereum/common
, so you can usecommon.Address
directly. - support rate limit, you can set the rate limit by yourself.
- support hooks, you can add hooks to do something before or after the request.
- combining current limiters to support concurrency.
go get github.com/xavierzho/explorer-api
Create an API instance and off you go.
package main
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/common"
//"github.com/xavierzho/explorer-api/modules/logs"
"github.com/xavierzho/explorer-api"
//"github.com/xavierzho/explorer-api/modules/accounts"
)
func main() {
// create a api client
client := explorer.NewClient(
"<you api key here>",
explorer.Ethereum,
explorer.ClientWithRTLimiter(5, 3),
)
// (optional) add hooks. useful for logging, metrics, etc.
client.BeforeHook = func(ctx context.Context, url string) error {
// ...
return nil
}
client.AfterHook = func(ctx context.Context, body []byte) {
// ...
}
// arbitrary module dependency injection client
// after v1.3
service := client.Accounts()
// compatible old version
//service := accounts.Service{Client: client}
//log := logs.Service{Client: client}
// and so on...
//_ = log
// get account balance
balance, _ := service.EtherBalance(common.HexToAddress("0xBE0eB53F46cd790Cd13851d5EFf43D12404d33E8"))
fmt.Println(balance)
}
other usage example on examples/
folder.
You may find full method list at GoDoc.
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).