我正在尝试打印变量(compiled_sol),正如您在python文件deploy.py的下面代码中所看到的那样,这样我就可以部署我的智能契约了,但是我一直在这个错误的情况下运行。
*****INFO: Could not find files for the given pattern(s).
Traceback (most recent call last):
File "C:\Users\houde\Desktop\Blockchain\solidity_projects\web3_py_simple_storage\deploy.py", line 8, in <module>
compiled_sol = compile_standard(
File "C:\Users\houde\AppData\Roaming\Python\Python39\site-packages\solcx\main.py", line 368, in compile_standard
solc_binary = get_executable(solc_version)
File "C:\Users\houde\AppData\Roaming\Python\Python39\site-packages\solcx\install.py", line 194, in get_executable
raise SolcNotInstalled(
solcx.exceptions.SolcNotInstalled: solc 0.6.0 has not been installed. Use solcx.install_solc('0.6.0') to install. ******我确实通过这个命令solc-x安装了pip install py-solc-x,这样我就可以编译合同了,但是我不知道如何升级版本,或者在本例中应该做些什么,我将把代码留在下面,非常感谢。
from solcx import compile_standard
with open("SimpleStorage.sol", "r") as file:
simple_storage_file = file.read()
compiled_sol = compile_standard(
{
"language": "solidity",
"sources": {"simpleStorage.sol": {"content": simple_storage_file}},
"settings": {
"outputSelection": {
"*": {"*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]}
}
},
},
solc_version="0.6.0",
)
print("compiled_sol")注:“solc版本0.6.0 i用于合同”
发布于 2021-09-25 08:23:23
我正在学习同样的课程,看看这个,它将向您展示如何在这里修复这个错误:https://github.com/smartcontractkit/full-blockchain-solidity-course-py/blob/main/chronological-issues-from-video.md
您只需执行以下操作:行上写着
from solcx import compile_standard我们需要把它改为这一行:
from solcx import compile_standard, install_solc然后,我们需要在运行compile_standard代码之前添加一行:
install_solc("0.6.0")或者,在安装solcx之前,您可以先使用安装Solc,它将为您提供包含的solidity编译器的旧版本。所以你要做的就是从solcx进口。
我还在您的设置数组中注意到:
"*": {"*": {"abi", "metadata", "evm.bytecode", "evm.sourceMap"}}您使用的是大括号而不是方括号,因此您需要在尝试编译之前修复它。它需要看起来像这样
"*": {"*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]}发布于 2021-09-26 15:16:02
您没有导入install_solc。然后安装您想要的版本。
from solcx import compile_standard, install_solc
install_solc("0.6.0")我建议使用像brownie这样的框架来避免这样的问题。如果你有布朗尼的话,你真的不需要自己做每件事。https://github.com/eth-brownie/brownie
发布于 2021-09-23 12:12:57
这是你的答案:安装旧Solc编译器版本
您只需要导入要调用的函数
https://ethereum.stackexchange.com/questions/110405
复制相似问题