Skip to content

Commit 888707c

Browse files
committed
eth: migrate etherscan API to v2
1 parent 3c06a11 commit 888707c

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Introduce full screen selector for mobile in place of dropdown
99
- Fix wrong estimated confirmation time for ERC20 tokens.
1010
- Enable unlock test wallet in testnet
11+
- Upgrade Etherscan API to V2
1112

1213
# v4.47.2
1314
- Linux: fix compatiblity with some versions of Mesa that are incompatible with the bundled wayland libraries

backend/backend.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -517,19 +517,19 @@ func (backend *Backend) Coin(code coinpkg.Code) (coinpkg.Coin, error) {
517517
coin = btc.NewCoin(coinpkg.CodeLTC, "Litecoin", "LTC", coinpkg.BtcUnitDefault, &ltc.MainNetParams, dbFolder, servers,
518518
"https://blockchair.com/litecoin/transaction/", backend.socksProxy)
519519
case code == coinpkg.CodeETH:
520-
etherScan := etherscan.NewEtherScan("https://api.etherscan.io/api", backend.etherScanHTTPClient)
520+
etherScan := etherscan.NewEtherScan("1", backend.etherScanHTTPClient)
521521
coin = eth.NewCoin(etherScan, code, "Ethereum", "ETH", "ETH", params.MainnetChainConfig,
522522
"https://etherscan.io/tx/",
523523
etherScan,
524524
nil)
525525
case code == coinpkg.CodeSEPETH:
526-
etherScan := etherscan.NewEtherScan("https://api-sepolia.etherscan.io/api", backend.etherScanHTTPClient)
526+
etherScan := etherscan.NewEtherScan("11155111", backend.etherScanHTTPClient)
527527
coin = eth.NewCoin(etherScan, code, "Ethereum Sepolia", "SEPETH", "SEPETH", params.SepoliaChainConfig,
528528
"https://sepolia.etherscan.io/tx/",
529529
etherScan,
530530
nil)
531531
case erc20Token != nil:
532-
etherScan := etherscan.NewEtherScan("https://api.etherscan.io/api", backend.etherScanHTTPClient)
532+
etherScan := etherscan.NewEtherScan("1", backend.etherScanHTTPClient)
533533
coin = eth.NewCoin(etherScan, erc20Token.code, erc20Token.name, erc20Token.unit, "ETH", params.MainnetChainConfig,
534534
"https://etherscan.io/tx/",
535535
etherScan,

backend/coins/eth/etherscan/etherscan.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,16 @@ type EtherScan struct {
5353
url string
5454
httpClient *http.Client
5555
limiter *rate.Limiter
56+
chainId string
5657
}
5758

5859
// NewEtherScan creates a new instance of EtherScan.
59-
func NewEtherScan(url string, httpClient *http.Client) *EtherScan {
60+
func NewEtherScan(chainId string, httpClient *http.Client) *EtherScan {
6061
return &EtherScan{
61-
url: url,
62+
url: "https://api.etherscan.io/v2/api",
6263
httpClient: httpClient,
6364
limiter: rate.NewLimiter(rate.Limit(callsPerSec), 1),
65+
chainId: chainId,
6466
}
6567
}
6668

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

0 commit comments

Comments
 (0)