From eb30191c7809d7cfc1f1d4fdcbbe91708e5d763f Mon Sep 17 00:00:00 2001 From: Tomas Vrba Date: Tue, 6 May 2025 11:53:03 +0200 Subject: [PATCH] eth: migrate etherscan API to v2 --- CHANGELOG.md | 3 +++ backend/backend.go | 6 +++--- backend/coins/eth/etherscan/etherscan.go | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8335d2a64..3abac64e67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ - Added support to show on the BitBox when a transaction's recipient is an address of a different account on the device. - Persist third party widget sessions +# v4.47.3 +- Upgrade Etherscan API to V2 + # v4.47.2 - Linux: fix compatiblity with some versions of Mesa that are incompatible with the bundled wayland libraries diff --git a/backend/backend.go b/backend/backend.go index bd928dcf53..3da4794061 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -520,19 +520,19 @@ func (backend *Backend) Coin(code coinpkg.Code) (coinpkg.Coin, error) { coin = btc.NewCoin(coinpkg.CodeLTC, "Litecoin", "LTC", coinpkg.BtcUnitDefault, <c.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, diff --git a/backend/coins/eth/etherscan/etherscan.go b/backend/coins/eth/etherscan/etherscan.go index fe7d29e561..e6efd2e41e 100644 --- a/backend/coins/eth/etherscan/etherscan.go +++ b/backend/coins/eth/etherscan/etherscan.go @@ -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, } } @@ -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)