5 Star 29 Fork 12

楠木 / etherscan-api

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

English | 中文

etherscan-api

GoDoc CI status codecov Go Report Card

Etherscan API的Golang客户端, 支持几乎所有功能(accounts, transactions, tokens, contracts, blocks, stats), 所有公共网络(Mainnet, Ropsten, Kovan, Rinkby, Goerli, Tobalaba)。 本项目只依赖于官方库。 :wink:

使用方法

go get github.com/nanmu42/etherscan-api

填入网络选项和API Key即可开始使用。 :rocket:

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

func main() {
	// 创建连接指定网络的客户端
	client := etherscan.New(etherscan.Mainnet, "[your API key]")
	
	// 或者,如果你要调用的是EtherScan家族的BscScan:
	//
	// client := etherscan.NewCustomized(etherscan.Customization{
	// Timeout:       15 * time.Second,
	// Key:           "You key here",
	// BaseURL:       "https://api.bscscan.com/api?",
	// Verbose:       false,
	// })	
	
	// (可选)按需注册钩子函数,例如用于速率控制
	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)
	}
	// 余额以 *big.Int 的类型呈现,单位为 wei
	fmt.Println(balance.Int())

	// 查询token余额
	tokenBalance, err := client.TokenBalance("contractAddress", "holderAddress")

	// 查询出入指定地址的ERC20转账列表
	transfers, err := client.ERC20Transfers("contractAddress", "address", startBlock, endBlock, page, offset)
}

客户端方法列表可在GoDoc查询。

Etherscan API Key

API Key可以在etherscan申请。

Etherscan的API服务是一个公开的社区无偿服务,请避免滥用。 API的调用速率不能高于5次/秒,否则会遭到封禁。

利益声明

我和Etherscan没有任何联系。我仅仅是觉得他们的服务很棒,而自己又恰好需要这样一个库。 :smile:

许可证

MIT

请自由享受开源,欢迎贡献开源。

MIT License Copyright (c) 2018 LI Zhennan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Golang 以太坊 Etherscan API库(也支持同一家族的BscScan) 展开 收起
Go
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/nanmu42/etherscan-api.git
git@gitee.com:nanmu42/etherscan-api.git
nanmu42
etherscan-api
etherscan-api
master

搜索帮助

14c37bed 8189591 565d56ea 8189591