0、前提条件
(1)操作系统
操作系统Windows10中进行开发测试
(2)参考代码
注:已使用科学上网
1、测试代码
import (
"github.com/nanmu42/etherscan-api"
"fmt"
)
func main() {
// create a API client for specified ethereum net
// there are many pre-defined network in package
client := etherscan.New(etherscan.Mainnet, "xxxxxxxx")
// check account balance
balance, err := client.AccountBalance("xxxxxxxx")
if err != nil {
panic(err)
}
// balance in wei, in *big.Int type
fmt.Println(balance.Int())
}
第一个"xxxxxxxx"表示为API key:在 https://etherscan.io/ 中生成,如下图所示
第二个"xxxxxxxx"表示为以太坊账户地址
以上2个"xxxxxxxx"替换成自己的API key与账户地址即可
2、错误信息
运行代码后报错,错误信息如下:
panic: Get "https://api-ropsten.etherscan.io/api?action=balance&address=xxxxxxxx&a

本文讲述了在Windows和Centos7环境下使用Golang的etherscan-api库进行以太坊账户余额和交易查询时遇到的问题,涉及科学上网、http代理设置、以及为何在Centos中失败。最终提供了解决方案,转向使用go-ethereum替代获取交易结果。

1037

被折叠的 条评论
为什么被折叠?



