etherscan

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2025 License: MIT Imports: 11 Imported by: 0

README

etherscan-go

Golang client for Etherscan API(V2)

Etherscan api doc

https://docs.etherscan.io/etherscan-v2

Usage

go get github.com/ABT-Tech-Limited/etherscan-go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FreeRateLimiter

func FreeRateLimiter() func(client *resty.Client, req *resty.Request) error

func StructToMap

func StructToMap(obj any) map[string]string

func ToStringE

func ToStringE(i any) (string, error)

ToStringE casts any value to a string type.

Types

type BaseResp

type BaseResp struct {
	Status  int             `json:"status,string"` // 1 for good, 0 for error
	Message string          `json:"message"`       // OK for good, other words when Status equals 0
	Result  json.RawMessage `json:"result"`
}

type Client

type Client interface {
	GetContractABI(req GetContractABIReq) (*ContractABIResp, error)
	GetContractSourceCode(req GetContractSourceCodeReq) (*ContractSourcecodeResp, error)
	GetContractCreatorTxInfo(req GetContractCreatorTxInfoReq) (*ContractCreatorTxInfoResp, error)

	GetEventLogsByAddress(req GetEventLogsByAddressReq) (*LogResp, error)
	GetEventLogsByTopics(req GetEventLogsByTopicsReq) (*LogResp, error)
	GetEventLogsByAddressFilterByTopics(req GetEventLogsByAddressFilterByTopicsReq) (*LogResp, error)

	Debug() Client
}

Client is the interface for interacting with Etherscan API

func New

func New(apiKey string, opts ...Options) Client

func NewWithClient

func NewWithClient(apiKey string, restyCli *resty.Client) Client

type ContractABIResp

type ContractABIResp BaseResp

func (*ContractABIResp) GetData

func (r *ContractABIResp) GetData() (string, error)

type ContractCreatorTxInfo

type ContractCreatorTxInfo struct {
	ContractAddress  string `json:"contractAddress"`
	ContractCreator  string `json:"contractCreator"`
	TxHash           string `json:"txHash"`
	BlockNumber      string `json:"blockNumber"`
	Timestamp        string `json:"timeStamp"`
	ContractFactory  string `json:"contractFactory"`
	CreationBytecode string `json:"creationBytecode"`
}

type ContractCreatorTxInfoResp

type ContractCreatorTxInfoResp BaseResp

func (*ContractCreatorTxInfoResp) GetData

type ContractSourceCode

type ContractSourceCode struct {
	SourceCode           string `json:"SourceCode"`
	ABI                  string `json:"ABI"`
	ContractName         string `json:"ContractName"`
	CompilerVersion      string `json:"CompilerVersion"`
	CompilerType         string `json:"CompilerType"`
	OptimizationUsed     string `json:"OptimizationUsed"`
	Runs                 string `json:"Runs"`
	ConstructorArguments string `json:"ConstructorArguments"`
	EVMVersion           string `json:"EVMVersion"`
	Library              string `json:"Library"`
	ContractFileName     string `json:"ContractFileName"`
	LicenseType          string `json:"LicenseType"`
	Proxy                string `json:"Proxy"`
	Implementation       string `json:"Implementation"`
	SwarmSource          string `json:"SwarmSource"`
	SimilarMatch         string `json:"SimilarMatch"`
}

type ContractSourcecodeResp

type ContractSourcecodeResp BaseResp

func (*ContractSourcecodeResp) GetData

type GetContractABIReq

type GetContractABIReq struct {
	ChainID uint64 `json:"chainid"`
	Address string `json:"address"` // the string representing the address of the contract
}

type GetContractCreatorTxInfoReq

type GetContractCreatorTxInfoReq struct {
	ChainID   uint64   `json:"chainid"`
	Addresses []string `json:"contractaddresses"` // the array representing the addresses of the contract
}

type GetContractSourceCodeReq

type GetContractSourceCodeReq struct {
	ChainID uint64 `json:"chainid"`
	Address string `json:"address"` // the string representing the address of the contract
}

type GetEventLogsByAddressFilterByTopicsReq

type GetEventLogsByAddressFilterByTopicsReq struct {
	ChainID   uint64            `json:"chainid"`
	Address   string            `json:"address"`   // the string representing the address to check for logs
	FromBlock uint64            `json:"fromBlock"` // the integer block number to start searching for logs eg. 12878196
	ToBlock   uint64            `json:"toBlock"`   // the integer block number to stop searching for logs eg. 12879196
	Topics    map[string]string `json:"topics"`    // topic & topicOperator
	Page      *int              `json:"page"`      // the integer page number, if pagination is enabled
	Offset    *int              `json:"offset"`    // the number of transactions displayed per page, limited to 1000 records per query, use the page parameter for subsequent records
}

type GetEventLogsByAddressReq

type GetEventLogsByAddressReq struct {
	ChainID   uint64 `json:"chainid"`
	Address   string `json:"address"`   // the string representing the address to check for logs
	FromBlock uint64 `json:"fromBlock"` // the integer block number to start searching for logs eg. 12878196
	ToBlock   uint64 `json:"toBlock"`   // the integer block number to stop searching for logs eg. 12879196
	Page      *int   `json:"page"`      // the integer page number, if pagination is enabled
	Offset    *int   `json:"offset"`    // the number of transactions displayed per page, limited to 1000 records per query, use the page parameter for subsequent records
}

type GetEventLogsByTopicsReq

type GetEventLogsByTopicsReq struct {
	ChainID   uint64            `json:"chainid"`
	FromBlock uint64            `json:"fromBlock"` // the integer block number to start searching for logs eg. 12878196
	ToBlock   uint64            `json:"toBlock"`   // the integer block number to stop searching for logs eg. 12879196
	Topics    map[string]string `json:"topics"`    // topic & topicOperator
	Page      *int              `json:"page"`      // the integer page number, if pagination is enabled
	Offset    *int              `json:"offset"`    // the number of transactions displayed per page, limited to 1000 records per query, use the page parameter for subsequent records
}

type Log

type Log struct {
	Address          string   `json:"address"`
	Topics           []string `json:"topics"`
	Data             string   `json:"data"`
	BlockNumber      string   `json:"blockNumber"`
	BlockHash        string   `json:"blockHash"`
	TimeStamp        string   `json:"timeStamp"`
	GasPrice         string   `json:"gasPrice"`
	GasUsed          string   `json:"gasUsed"`
	LogIndex         string   `json:"logIndex"`
	TransactionHash  string   `json:"transactionHash"`
	TransactionIndex string   `json:"transactionIndex"`
}

type LogResp

type LogResp BaseResp

func (*LogResp) GetData

func (r *LogResp) GetData() ([]Log, error)

GetData 获取日志数据,如果result是错误信息则返回错误

type Options

type Options struct {
	Timeout       time.Duration
	BaseUrl       string
	Verbose       bool
	Transport     *http.Transport
	BeforeRequest []resty.RequestMiddleware // for rate limit
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL