Skip to content

eth: migrate etherscan API to v2 #3321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Introduce full screen selector for mobile in place of dropdown
- Fix wrong estimated confirmation time for ERC20 tokens.
- Enable unlock test wallet in testnet
- Upgrade Etherscan API to V2

# v4.47.2
- Linux: fix compatiblity with some versions of Mesa that are incompatible with the bundled wayland libraries
Expand Down
6 changes: 3 additions & 3 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,19 +517,19 @@ func (backend *Backend) Coin(code coinpkg.Code) (coinpkg.Coin, error) {
coin = btc.NewCoin(coinpkg.CodeLTC, "Litecoin", "LTC", coinpkg.BtcUnitDefault, &ltc.MainNetParams, dbFolder, servers,
"https://blockchair.com/litecoin/transaction/", backend.socksProxy)
case code == coinpkg.CodeETH:
etherScan := etherscan.NewEtherScan("https://api.etherscan.io/api", backend.etherScanHTTPClient)
etherScan := etherscan.NewEtherScan("1", backend.etherScanHTTPClient)
coin = eth.NewCoin(etherScan, code, "Ethereum", "ETH", "ETH", params.MainnetChainConfig,
"https://etherscan.io/tx/",
etherScan,
nil)
case code == coinpkg.CodeSEPETH:
etherScan := etherscan.NewEtherScan("https://api-sepolia.etherscan.io/api", backend.etherScanHTTPClient)
etherScan := etherscan.NewEtherScan("11155111", backend.etherScanHTTPClient)
coin = eth.NewCoin(etherScan, code, "Ethereum Sepolia", "SEPETH", "SEPETH", params.SepoliaChainConfig,
"https://sepolia.etherscan.io/tx/",
etherScan,
nil)
case erc20Token != nil:
etherScan := etherscan.NewEtherScan("https://api.etherscan.io/api", backend.etherScanHTTPClient)
etherScan := etherscan.NewEtherScan("1", backend.etherScanHTTPClient)
coin = eth.NewCoin(etherScan, erc20Token.code, erc20Token.name, erc20Token.unit, "ETH", params.MainnetChainConfig,
"https://etherscan.io/tx/",
etherScan,
Expand Down
7 changes: 5 additions & 2 deletions backend/coins/eth/etherscan/etherscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ type EtherScan struct {
url string
httpClient *http.Client
limiter *rate.Limiter
chainId string
}

// NewEtherScan creates a new instance of EtherScan.
func NewEtherScan(url string, httpClient *http.Client) *EtherScan {
func NewEtherScan(chainId string, httpClient *http.Client) *EtherScan {
return &EtherScan{
url: url,
url: "https://api.etherscan.io/v2/api",
httpClient: httpClient,
limiter: rate.NewLimiter(rate.Limit(callsPerSec), 1),
chainId: chainId,
}
}

Expand All @@ -69,6 +71,7 @@ func (etherScan *EtherScan) call(ctx context.Context, params url.Values, result
return errp.WithStack(err)
}
params.Set("apikey", apiKey)
params.Set("chainId", etherScan.chainId)
response, err := etherScan.httpClient.Get(etherScan.url + "?" + params.Encode())
if err != nil {
return errp.WithStack(err)
Expand Down