0

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

2

(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__":
    main()

Output:

Please input an address: 0xd26114cd6EE289AccF82350c8d8487fedB8A0C07

6003805460a060020a61ffff0219169055600060045560a0604052600860608190527f4f4d47546f6b656e000000000000000000000000000000000000000000000000608090815261005491600591906100c1565b506040805180820190915260038082527f4f4d4700000000000000000000000000000000000000000000000000000000006020909201918252610099916006916100c1565b5060126007555b60038054600160a060020a03191633600160a060020a03161790555b610161565b828054600181600116156101000203166002900490600052602060002090601f0160209...

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.