diff --git a/README.md b/README.md index 56acd1f..83d6974 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,25 @@ -**English** | [中文](https://github.com/nanmu42/etherscan-api/blob/master/README_ZH.md) +**English** | [中文](https://github.com/the-web3/etherscan-api/blob/master/README_ZH.md) # etherscan-api -[![GoDoc](https://godoc.org/github.com/nanmu42/etherscan-api?status.svg)](https://godoc.org/github.com/nanmu42/etherscan-api) -[![CI status](https://github.com/nanmu42/etherscan-api/actions/workflows/ci.yaml/badge.svg)](https://github.com/nanmu42/etherscan-api/actions) +[![GoDoc](https://godoc.org/github.com/the-web3/etherscan-api?status.svg)](https://godoc.org/github.com/the-web3/etherscan-api) +[![CI status](https://github.com/the-web3/etherscan-api/actions/workflows/ci.yaml/badge.svg)](https://github.com/the-web3/etherscan-api/actions) [![codecov](https://codecov.io/gh/nanmu42/etherscan-api/branch/master/graph/badge.svg)](https://codecov.io/gh/nanmu42/etherscan-api) -[![Go Report Card](https://goreportcard.com/badge/github.com/nanmu42/etherscan-api)](https://goreportcard.com/report/github.com/nanmu42/etherscan-api) +[![Go Report Card](https://goreportcard.com/badge/github.com/the-web3/etherscan-api)](https://goreportcard.com/report/github.com/the-web3/etherscan-api) Golang client for the Etherscan.io API(and its families like BscScan), with nearly full implementation(accounts, transactions, tokens, contracts, blocks, stats), full network support(Mainnet, Ropsten, Kovan, Rinkby, Goerli, Tobalaba), and only depending on standard library. :wink: # Usage ```bash -go get github.com/nanmu42/etherscan-api +go get github.com/the-web3/etherscan-api ``` Create an API instance and off you go. :rocket: ```go import ( - "github.com/nanmu42/etherscan-api" + "github.com/the-web3/etherscan-api" "fmt" ) @@ -61,7 +61,7 @@ func main() { } ``` -You may find full method list at [GoDoc](https://godoc.org/github.com/nanmu42/etherscan-api). +You may find full method list at [GoDoc](https://godoc.org/github.com/the-web3/etherscan-api). # Etherscan API Key diff --git a/README_ZH.md b/README_ZH.md index 905a770..2cf1eaa 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -1,11 +1,11 @@ -[English](https://github.com/nanmu42/etherscan-api/blob/master/README.md) | **中文** +[English](https://github.com/the-web3/etherscan-api/blob/master/README.md) | **中文** # etherscan-api -[![GoDoc](https://godoc.org/github.com/nanmu42/etherscan-api?status.svg)](https://godoc.org/github.com/nanmu42/etherscan-api) -[![CI status](https://github.com/nanmu42/etherscan-api/actions/workflows/ci.yaml/badge.svg)](https://github.com/nanmu42/etherscan-api/actions) +[![GoDoc](https://godoc.org/github.com/the-web3/etherscan-api?status.svg)](https://godoc.org/github.com/the-web3/etherscan-api) +[![CI status](https://github.com/the-web3/etherscan-api/actions/workflows/ci.yaml/badge.svg)](https://github.com/the-web3/etherscan-api/actions) [![codecov](https://codecov.io/gh/nanmu42/etherscan-api/branch/master/graph/badge.svg)](https://codecov.io/gh/nanmu42/etherscan-api) -[![Go Report Card](https://goreportcard.com/badge/github.com/nanmu42/etherscan-api)](https://goreportcard.com/report/github.com/nanmu42/etherscan-api) +[![Go Report Card](https://goreportcard.com/badge/github.com/the-web3/etherscan-api)](https://goreportcard.com/report/github.com/the-web3/etherscan-api) Etherscan API的Golang客户端, 支持几乎所有功能(accounts, transactions, tokens, contracts, blocks, stats), @@ -15,14 +15,14 @@ Etherscan API的Golang客户端, # 使用方法 ```bash -go get github.com/nanmu42/etherscan-api +go get github.com/the-web3/etherscan-api ``` 填入网络选项和API Key即可开始使用。 :rocket: ```go import ( - "github.com/nanmu42/etherscan-api" + "github.com/the-web3/etherscan-api" "fmt" ) @@ -63,7 +63,7 @@ func main() { } ``` -客户端方法列表可在[GoDoc](https://godoc.org/github.com/nanmu42/etherscan-api)查询。 +客户端方法列表可在[GoDoc](https://godoc.org/github.com/the-web3/etherscan-api)查询。 # Etherscan API Key diff --git a/account.go b/account.go index e6a9ac1..357a94b 100644 --- a/account.go +++ b/account.go @@ -7,6 +7,8 @@ package etherscan +import "strings" + // AccountBalance gets ether balance for a single address func (c *Client) AccountBalance(address string) (balance *BigInt, err error) { param := M{ @@ -86,7 +88,7 @@ func (c *Client) InternalTxByAddress(address string, startBlock *int, endBlock * // and TokenDecimal is 0. // // More information can be found at: -// https://github.com/nanmu42/etherscan-api/issues/8 +// https://github.com/the-web3/etherscan-api/issues/8 func (c *Client) ERC20Transfers(contractAddress, address *string, startBlock *int, endBlock *int, page int, offset int, desc bool) (txs []ERC20Transfer, err error) { param := M{ "page": page, @@ -155,6 +157,30 @@ func (c *Client) ERC1155Transfers(contractAddress, address *string, startBlock * return } +// SwapTransactions get a list of transaction +func (c *Client) SwapTransactions(address string, startBlock *int, endBlock *int, page int, offset int, desc bool) (txs []SwapTransaction, err error) { + param := M{ + "page": page, + "offset": offset, + } + compose(param, "address", address) + compose(param, "startblock", startBlock) + compose(param, "endblock", endBlock) + if desc { + param["sort"] = "desc" + } else { + param["sort"] = "asc" + } + err = c.call("account", "txlist", param, &txs) + var txList []SwapTransaction + for _, tx := range txs { + if tx.MethodId != "0x" && strings.ContainsAny(tx.FunctionName, "execute") { // maybe swap transaction + txList = append(txList, tx) + } + } + return txList, nil +} + // BlocksMinedByAddress gets list of blocks mined by address func (c *Client) BlocksMinedByAddress(address string, page int, offset int) (mined []MinedBlock, err error) { param := M{ diff --git a/account_e2e_test.go b/account_e2e_test.go index f7688e3..9ef4006 100644 --- a/account_e2e_test.go +++ b/account_e2e_test.go @@ -115,6 +115,10 @@ func TestClient_ERC20Transfers(t *testing.T) { } } +func TestClient_SwapTransactions(t *testing.T) { + +} + func TestClient_BlocksMinedByAddress(t *testing.T) { const wantLen = 10 diff --git a/doc.go b/doc.go index d345cab..855d5f1 100644 --- a/doc.go +++ b/doc.go @@ -5,5 +5,5 @@ // with full network support(Mainnet, Ropsten, Kovan, Rinkby, Tobalaba), // and only depending on standard library. // -// Example can be found at https://github.com/nanmu42/etherscan-api +// Example can be found at https://github.com/the-web3/etherscan-api package etherscan diff --git a/go.mod b/go.mod index 5837de6..d878570 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/nanmu42/etherscan-api +module github.com/the-web3/etherscan-api go 1.13 diff --git a/response.go b/response.go index 5c418cf..b71e4c4 100644 --- a/response.go +++ b/response.go @@ -142,6 +142,32 @@ type ERC1155Transfer struct { Confirmations int `json:"confirmations,string"` } +// SwapTransaction all swap transactions +type SwapTransaction struct { + BlockNumber int `json:"blockNumber,string"` + TimeStamp Time `json:"timeStamp"` + Hash string `json:"hash"` + Nonce int `json:"nonce,string"` + BlockHash string `json:"blockHash"` + From string `json:"from"` + ContractAddress string `json:"contractAddress"` + To string `json:"to"` + TokenID *BigInt `json:"tokenID"` + TokenName string `json:"tokenName"` + TokenSymbol string `json:"tokenSymbol"` + TokenDecimal uint8 `json:"tokenDecimal,string"` + TokenValue uint8 `json:"tokenValue,string"` + TransactionIndex int `json:"transactionIndex,string"` + Gas int `json:"gas,string"` + GasPrice *BigInt `json:"gasPrice"` + GasUsed int `json:"gasUsed,string"` + CumulativeGasUsed int `json:"cumulativeGasUsed,string"` + Input string `json:"input"` + MethodId string `json:"methodId"` + FunctionName string `json:"functionName"` + Confirmations int `json:"confirmations,string"` +} + // MinedBlock holds info from query for mined block by address type MinedBlock struct { BlockNumber int `json:"blockNumber,string"`