|
5 | 5 | [](https://codecov.io/gh/nanmu42/etherscan-api)
|
6 | 6 | [](https://godoc.org/github.com/nanmu42/etherscan-api)
|
7 | 7 |
|
8 |
| -Go bindings to the Etherscan.io API |
| 8 | +Go bindings to the Etherscan.io API, with nearly Full implementation(accounts, transactions, tokens, contracts, blocks, stats), full network support(Mainnet, Ropsten, Kovan, Rinkby, Tobalaba), and only depending on standard library. :wink: |
9 | 9 |
|
10 |
| -Under development now. :) |
| 10 | + |
| 11 | + |
| 12 | +# Usage |
| 13 | + |
| 14 | +Create a API instance and off you go. :rocket: |
| 15 | + |
| 16 | +```go |
| 17 | +import ( |
| 18 | + "github.com/nanmu42/etherscan-api" |
| 19 | + "fmt" |
| 20 | +) |
| 21 | + |
| 22 | +func main() { |
| 23 | + // create a API client for specified ethereum net |
| 24 | + // there are many pre-defined network in package |
| 25 | + client := etherscan.New(etherscan.Mainnet, "[your API key]") |
| 26 | + |
| 27 | + // (optional) add hooks, e.g. for rate limit |
| 28 | + client.BeforeRequest = func(module, action string, param map[string]interface{}) error { |
| 29 | + // ... |
| 30 | + } |
| 31 | + client.AfterRequest = func(module, action string, param map[string]interface{}, outcome interface{}, requestErr error) { |
| 32 | + // ... |
| 33 | + } |
| 34 | + |
| 35 | + // check account balance |
| 36 | + balance, err := client.AccountBalance("0x281055afc982d96fab65b3a49cac8b878184cb16") |
| 37 | + if err != nil { |
| 38 | + panic(err) |
| 39 | + } |
| 40 | + // balance in wei, in *big.Int type |
| 41 | + fmt.Println(balance.Int()) |
| 42 | + |
| 43 | + // check token balance |
| 44 | + tokenBalance, err := client.TokenBalance("contractAddress", "holderAddress") |
| 45 | + |
| 46 | + // check ERC20 transactions from/to a specified address |
| 47 | + transfers, err := client.ERC20Transfers("contractAddress", "address", startBlock, endBlock, page, offset) |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +You may find full method list at [GoDoc](https://godoc.org/github.com/nanmu42/etherscan-api). |
| 52 | + |
| 53 | +# Etherscan API Key |
| 54 | + |
| 55 | +You may apply for an API key on [etherscan](https://etherscan.io/apis). |
| 56 | + |
| 57 | +> 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). |
| 58 | +
|
| 59 | +# Paperwork Things |
| 60 | + |
| 61 | +I am not from Etherscan and I just find their service really useful, so I implement this. :smile: |
| 62 | + |
| 63 | +# License |
| 64 | + |
| 65 | +Use of this work is governed by a MIT License. |
| 66 | + |
| 67 | +You may find a license copy in project root. |
0 commit comments