项目作者: nanmu42

项目描述 :
:guitar: Golang bindings to Ethereum Etherscan.io API(and its families like BscScan) | Golang 以太坊 Etherscan API库(也支持同一家族的BscScan)
高级语言: Go
项目地址: git://github.com/nanmu42/etherscan-api.git
创建时间: 2018-07-28T10:42:03Z
项目社区:https://github.com/nanmu42/etherscan-api

开源协议:MIT License

下载


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. :wink:

Usage

  1. go get github.com/nanmu42/etherscan-api

Create an API instance and off you go. :rocket:

  1. import (
  2. "github.com/nanmu42/etherscan-api"
  3. "fmt"
  4. )
  5. func main() {
  6. // create a API client for specified ethereum net
  7. // there are many pre-defined network in package
  8. client := etherscan.New(etherscan.Mainnet, "[your API key]")
  9. // or, if you are working with etherscan-family API like BscScan
  10. //
  11. // client := etherscan.NewCustomized(etherscan.Customization{
  12. // Timeout: 15 * time.Second,
  13. // Key: "You key here",
  14. // BaseURL: "https://api.bscscan.com/api?",
  15. // Verbose: false,
  16. // })
  17. // (optional) add hooks, e.g. for rate limit
  18. client.BeforeRequest = func(module, action string, param map[string]interface{}) error {
  19. // ...
  20. }
  21. client.AfterRequest = func(module, action string, param map[string]interface{}, outcome interface{}, requestErr error) {
  22. // ...
  23. }
  24. // check account balance
  25. balance, err := client.AccountBalance("0x281055afc982d96fab65b3a49cac8b878184cb16")
  26. if err != nil {
  27. panic(err)
  28. }
  29. // balance in wei, in *big.Int type
  30. fmt.Println(balance.Int())
  31. // check token balance
  32. tokenBalance, err := client.TokenBalance("contractAddress", "holderAddress")
  33. // check ERC20 transactions from/to a specified address
  34. transfers, err := client.ERC20Transfers("contractAddress", "address", startBlock, endBlock, page, offset)
  35. }

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.