There is same question on stackexchange but the answer to that question does not include the new api on etherscan which, given an address as input, allows you to download source code of that verified smart contract.

But I want to download source code of a random verified contracts without knowing its address.

My ultimate goal is to make folders based on versions of contracts and download 50-100 for each version if available enough. I also want to know how many verified smart contracts are there on etherscan so that i can estimate time of download as only last 500 verified contracts are visible on etherscan.

edit: If I know addresses of verified smart contract then the api will work since i can loop over all addresses. Is there any way to get a list of addresses of all verified smart contracts?

4 Answers 4


I think your best chance is to build a scraper to harvest the Ethereum address of random smart contracts and if they are verified, then feed the address into the API to grab the source code.


It's Official Etherscan API:


Just make ID, and use API.

Free limit:-

  • 5 calls/second limit
  • Up to 100,000 API calls a day

Cost of Etherscan API: https://etherscan.io/apis

If you want to create your own api for this purpose use puppeteer or selenium or something similar.

There maybe many third party APIs also. You may search on internet.

  • How can I convert the flattened source to "normal" source code? May 16, 2023 at 0:49
  • there is not such tool made. if you find somewhere, tell me too.
    – aakash4dev
    May 26, 2023 at 13:46

When I tried to scrape using API calls, its working perfectly fine with addresses that have a single .sol file. But for multiple .sol files, the extracted data contains lots of noise.

This is my function:


def get_contract_source_codes(api_key, addresses, url):
    # create an empty list to hold the source code for each contract
    source_codes = []

    # iterate through the addresses and get the source code for each contract
    for address in addresses:
        full_url = f"{url}&address={address}&apikey={api_key}"
        response = requests.get(full_url)
        data = response.json()

        # extract the source code from the response
        source_code = data["result"][0]

        # add the source code to the list

    # create a pandas DataFrame with the source codes and addresses
    df = pd.DataFrame({"Address": addresses, "Source Code": source_codes})
    return df

#for this address, this function works fine
get_contract_source_codes(api_key, ['0x2189455051A1c1E6190276f84f73Ec6Fb2fe62DF'], url)

#for this address, it contains lots of noise
get_contract_source_codes(api_key, ['00xcc42315f99979fC051Eb7Bee82E869ac41eC514F'], url)

Given your last edit I think this would help you

Is there any way to get a list of addresses of all verified smart contracts? Blockquote

This will give you the list of contracts in a csv:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.