From 4e53c70f62d251af7974b09e33e8b08066834f7f Mon Sep 17 00:00:00 2001 From: Ed Zynda Date: Tue, 24 Sep 2024 12:33:57 +0300 Subject: [PATCH] use OKLINK key --- apis_generated.go | 1 + main.go | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apis_generated.go b/apis_generated.go index 8ef2608..9d2c7dc 100644 --- a/apis_generated.go +++ b/apis_generated.go @@ -163,4 +163,5 @@ var etherscanConfig map[string]string = map[string]string{ "7777777": "https://explorer.zora.energy/api", "999999999": "https://sepolia.explorer.zora.energy/api", "999": "https://testnet.explorer.zora.energy/api", + "196": "https://www.oklink.com/api/v5/explorer/xlayer/api", } diff --git a/main.go b/main.go index a08b3d3..228e79c 100644 --- a/main.go +++ b/main.go @@ -394,16 +394,27 @@ func getCachedABI( func getAbiFromEtherscan( chainId, address string, ) (string, []map[string]interface{}, error) { + client := &http.Client{} + apiKey := os.Getenv("CHAIN_" + chainId + "_ETHERSCAN_KEY") apiUrl := fmt.Sprintf( "%s?module=contract&action=getsourcecode&address=%s&apikey=%s", etherscanConfig[chainId], address, - os.Getenv("CHAIN_"+chainId+"_ETHERSCAN_KEY"), + apiKey, ) log.Println(apiUrl) + request, err := http.NewRequest(http.MethodGet, apiUrl, nil) + if err != nil { + return "", nil, err + } + + if strings.Contains(apiUrl, "oklink") { + request.Header.Add("Ok-Access-Key", apiKey) + } + // Send GET request to Etherscan API - response, err := http.Get(apiUrl) + response, err := client.Do(request) if err != nil { return "", nil, err }