[TOC]html
HundredLee
2013年起,便奋斗在数字货币交易平台开发第一线,2016年接触区块链,今后走上不归路。目前正在开发一套全新的高速撮合引擎。
微博 :weibo.com/hundredlee2…
邮箱 :hundred9411#gmail.comgit
连载一,介绍以太坊,查询余额等。
连载二,go-ethereum转出以太坊、如何对接token、如何查询token余额、如何转出token。
连载三,交易平台对接以太坊的一些经验和总结。github
百度百科:golang
以太坊(Ethereum)并非一个机构,而是一款可以在区块链上实现智能合约、开源的底层系统,以太坊从诞生到2017年5月,短短3年半时间,全球已有200多个以太坊应用诞生。以太坊是一个平台和一种编程语言,使开发人员可以创建和发布下一代分布式应用。 以太坊能够用来编程,分散,担保和交易任何事物:投票,域名,金融交易所,众筹,公司管理, 合同和大部分的协议,知识产权,还有得益于硬件集成的智能资产。编程
首先比较重要的一步,先 go get https://github.com/ethereum/go-ethereum
编程语言
若是上一步你成功安装了geth客户端,并开启了rpc功能,例如http://127.0.0.1
,那么你就能够在golang中链接rpc。分布式
直接上代码:区块链
import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
)
func connectToRpc() (*ethclient.Client, error) {
client, err := rpc.Dial("http://127.0.0.1")
if err != nil {
return nil, err
}
conn := ethclient.NewClient(client)
return conn, nil
}复制代码
import (
"context"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
)
//特别注意,这里的address就是你要查询的以太坊余额的地址。通常是0xddddd 这样的形式
func GetBalance(address string) {
client,err := connectToRpc()
if err != nil {
panic(err.Error())
}
balance, err := client.BalanceAt(context.TODO(),common.HexToAddress(address), nil)
}复制代码
if err != nil {
beego.Error(err.Error())
} else {
//这个就是地址中以太坊的余额
balanceV := float64(balance.Int64()) * math.Pow(10, -18)
}复制代码
接受捐赠,多少都是支持。
ui![]()
WechatIMG13