如何在Python中保存来自以太坊区块链的Solidity智能合约的源代码?
我正在寻找一种快速获取智能合约源代码的方法。我尝试使用以下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),则它不起作用。那么有没有一种快速简便的方法将它们全部保存到一个文件中呢?或者我只需要为每个文件创建一个单独的文件?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论