【发布时间】:2022-07-17 01:18:39
【问题描述】:
我正在寻找一种快速获取智能合约源代码的方法。我尝试使用以下 python 代码:
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()
因此,虽然这适用于给定地址,但如果源代码包含多个文件(例如此地址:0xED5AF388653567Af2F388E6224dC7C4b3241C544),则它不起作用。那么有没有一种快速简便的方法可以将它们全部保存到一个文件中?还是我只需要为每个文件创建一个单独的文件?
【问题讨论】:
-
智能合约的源代码在以太坊区块链上不可用。只有它的字节码是。
标签: python python-3.x ethereum solidity etherscan