etherscan

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 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

View Source
const (
	NoRecordsFound              = "No records found"
	ContractCodeAlreadyVerified = "Contract source code already verified"
)

Variables

This section is empty.

Functions

func CopyMap added in v1.0.4

func CopyMap(src map[string]string) map[string]string

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 CheckVerifyStatusReq added in v1.0.4

type CheckVerifyStatusReq struct {
	ChainID uint64 `json:"chainid"`
	GUID    string `json:"guid"` // the guid returned from the verify API
}

type Client

type Client interface {
	GetContractABI(req GetContractABIReq) (*StringResp, error)
	GetContractSourceCode(req GetContractSourceCodeReq) (*ContractSourcecodeResp, error)
	GetContractCreatorTxInfo(req GetContractCreatorTxInfoReq) (*ContractCreatorTxInfoResp, error)
	VerifySourceCode(req VerifySourceCodeReq) (resp *VerifySourceCodeResp, err error)
	CheckVerifyStatus(req CheckVerifyStatusReq) (resp *StringResp, err 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 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
}

type StringResp added in v1.0.4

type StringResp struct {
	Status  int    `json:"status,string"`
	Message string `json:"message"`
	Result  string `json:"result"`
}

type VerifySourceCodeReq added in v1.0.4

type VerifySourceCodeReq struct {
	ChainID              uint64  `json:"chainid"`
	CodeFormat           string  `json:"codeformat"`            // single file, use solidity-single-file JSON file ( recommended ), use solidity-standard-json-input
	SourceCode           string  `json:"sourceCode"`            // the Solidity source code
	ContractAddress      string  `json:"contractaddress"`       // the address your contract is deployed at
	ContractName         string  `json:"contractname"`          // the name of your contract, such as contracts/Verified.sol:Verified
	CompilerVersion      string  `json:"compilerversion"`       // compiler version used, such as v0.8.24+commit.e11b9ed9
	ConstructorArguments *string `json:"constructorArguements"` // optional, include if your contract uses constructor arguments
	CompilerMode         *string `json:"compilermode"`          // for ZK Stack, set to solc/zksync
	ZkSolcVersion        *string `json:"zksolcVersion"`         // for ZK Stack, zkSolc version used, such as v1.3.14
}

type VerifySourceCodeResp added in v1.0.4

type VerifySourceCodeResp BaseResp

func (*VerifySourceCodeResp) GetData added in v1.0.4

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

Jump to

Keyboard shortcuts

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