'How can I save the source code of a solidity smartcontract from the ethereum blockchain in python?
I'm looking for a quick way to get the source code of a smartcontract. I tried using the following python code:
import requests
import json
address = "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413"
api_key = my_api_key
request_string = f'''https://api.etherscan.io/api?module=contract&action=getsourcecode&address={address}&apikey={api_key}'''
response = requests.get(request_string)
print(response.text)
data = json.loads(response.text)['result'][0]['SourceCode']
file = open("contract.sol", "w")
a = file.write(data)
file.close()
So while this works for the given address, it doesn't work if the source code consists of multiple files (like with this address: 0xED5AF388653567Af2F388E6224dC7C4b3241C544). So is there a quick and easy way to save all of them into one file? Or do I just have to create a separate file for each one of the files?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
