I tried etherscan api to get the contract creation code (bytecode for depolying contracts). I tried both getContractABI and getSourceCode, but the return values are not what i am expecting.

I need the cotract creation code as in: https://etherscan.io/address/0xd26114cd6EE289AccF82350c8d8487fedB8A0C07#code

for any contract which i have its address


(Assuming that you don't just want to call web3.eth.getCode(), and you want something web-based... )

Doesn't appear to be supported by the API, as you've found.

Some horrible scrape-y Python:

#!/usr/bin/env python

import requests
from bs4 import BeautifulSoup

BASE_URL = "https://etherscan.io/address/"

def main():
    address = str(input("Please input an address: ").strip())

    url = BASE_URL + address
    page = requests.get(url)
    soup = BeautifulSoup(page.text, 'html.parser')

    print(soup.find("div", { "id": "verifiedbytecode2" }).text)

if __name__ == "__main__":


Please input an address: 0xd26114cd6EE289AccF82350c8d8487fedB8A0C07


Note that the contract must have been verified for this data to be available.

I imagine doing something similar in Node with Cheerio/Axios wouldn't be too difficult.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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