把ERC20上的交易数据抓取到docker容器中,今天试着用Golang写了一个代码,最终编译通过。
只是,过程中,docker及docker-compose的安装部署,实在令人生厌。
心得:容易部署方面,Linux比windows好用太多了。
package main
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/getamis/eth-indexer/model"
"github.com/getamis/eth-indexer/store/account"
"github.com/getamis/eth-indexer/store/sqldb"
"github.com/getamis/sirius/database"
"github.com/getamis/sirius/database/mysql"
)
func main() {
db, _ := sqldb.New("mysql",
database.DriverOption(
mysql.Database("ethdb"),
mysql.Connector(mysql.DefaultProtocol, "127.0.0.1", "3306"),
mysql.UserInfo("root", "my-secret-pw"),
),
)
addr := common.HexToAddress("0x756f45e3fa69347a9a973a725e3c98bc4db0b5a0")
store := account.NewWithDB(db)
account, err := store.FindAccount(context.Background(), model.ETHAddress, addr)
if err != nil {
fmt.Printf("Failed to find account: %v\n", err)
} else {
fmt.Printf("Find account, block_number: %v, balance: %v, \n", account.Balance, account.BlockNumber)
}
}
有疑问加站长微信联系(非本文作者)