Skip to content

Commit eb30191

Browse files
Tomasvrbabenma
authored andcommitted
eth: migrate etherscan API to v2
1 parent 4e98a99 commit eb30191

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
- Added support to show on the BitBox when a transaction's recipient is an address of a different account on the device.
1212
- Persist third party widget sessions
1313

14+
# v4.47.3
15+
- Upgrade Etherscan API to V2
16+
1417
# v4.47.2
1518
- Linux: fix compatiblity with some versions of Mesa that are incompatible with the bundled wayland libraries
1619

backend/backend.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,19 +520,19 @@ func (backend *Backend) Coin(code coinpkg.Code) (coinpkg.Coin, error) {
520520
coin = btc.NewCoin(coinpkg.CodeLTC, "Litecoin", "LTC", coinpkg.BtcUnitDefault, &ltc.MainNetParams, dbFolder, servers,
521521
"https://blockchair.com/litecoin/transaction/", backend.socksProxy)
522522
case code == coinpkg.CodeETH:
523-
etherScan := etherscan.NewEtherScan("https://api.etherscan.io/api", backend.etherScanHTTPClient)
523+
etherScan := etherscan.NewEtherScan("1", backend.etherScanHTTPClient)
524524
coin = eth.NewCoin(etherScan, code, "Ethereum", "ETH", "ETH", params.MainnetChainConfig,
525525
"https://etherscan.io/tx/",
526526
etherScan,
527527
nil)
528528
case code == coinpkg.CodeSEPETH:
529-
etherScan := etherscan.NewEtherScan("https://api-sepolia.etherscan.io/api", backend.etherScanHTTPClient)
529+
etherScan := etherscan.NewEtherScan("11155111", backend.etherScanHTTPClient)
530530
coin = eth.NewCoin(etherScan, code, "Ethereum Sepolia", "SEPETH", "SEPETH", params.SepoliaChainConfig,
531531
"https://sepolia.etherscan.io/tx/",
532532
etherScan,
533533
nil)
534534
case erc20Token != nil:
535-
etherScan := etherscan.NewEtherScan("https://api.etherscan.io/api", backend.etherScanHTTPClient)
535+
etherScan := etherscan.NewEtherScan("1", backend.etherScanHTTPClient)
536536
coin = eth.NewCoin(etherScan, erc20Token.code, erc20Token.name, erc20Token.unit, "ETH", params.MainnetChainConfig,
537537
"https://etherscan.io/tx/",
538538
etherScan,

backend/coins/eth/etherscan/etherscan.go

Lines changed: 5 additions & 2 deletions
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)