当我在 Visual Studio Code 中编写编译代码时无法获得结果,我运行 python deploy.py 并给出错误。我必须在代码中编辑什么

问题描述 投票:0回答:3

我刚刚开始编码,代码中似乎缺少一些东西,这是编译后的代码。运行 python deploy.py 后给我的错误消息 我检查了很多次还是有同样的错误。

代码来自我正在此链接中学习的课程: https://github.com/PatrickAlphaC/web3_py_simple_storage 此链接中的代码:https://github.com/PatrickAlphaC/web3_py_simple_storage/blob/main/deploy.py

这是代码和错误消息,非常感谢您:)

代码:

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)

错误:

INFO: Could not find files for the given pattern(s).
Traceback (most recent call last):
  File "C:\Users\user\web3_py_simple_storage\deploy.py", line 8, in <module>
    compiled_sol = compile_standard(
  File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\solcx\main.py", line 394, in compile_standard
    raise SolcError(
solcx.exceptions.SolcError: Only "Solidity" or "Yul" is supported as a language.

command: `C:\Users\user\.solcx\solc-v0.6.0\solc.exe --standard-json`
return code: `0`
stdout:
{"errors":[{"component":"general","formattedMessage":"Only \"Solidity\" or \"Yul\" is supported as a language.","message":"Only \"Solidity\" or \"Yul\" is supported as a language.","severity":"error","type":"JSONError"}]}
python blockchain ethereum solidity smartcontracts
3个回答
0
投票

你有两个错别字

compiled_sol=compile_standard({
    # not "solidity"
    "language":"Solidity",
    # not "simpleStorage"
    "sources":{"SimpleStorage.sol":{"content":simple_storage_file}},
    "settings":{
        "outputSelection":{
            "*":{
                "*":["abi","metadata","evm.bytecode","evm.sourceMap"]
            }
        }
    }
},

0
投票

将“语言”:“坚固性”更改为 “语言”:“坚固性”,


0
投票

试试这个:


from solcx import compile_standard, install_solc

with open("./SimpleStorage.sol", "r") as file:
    simple_storage_file = file.read()

print("Installing...")
install_solc("0.6.0")


compiled_sol = compile_standard(
    {

        "language": "Solidity",
        "sources": {"SimpleStorage.sol": {"content": simple_storage_file}}, 
        "settings": {
            "outputSelection": {
                "*": {"*": ["abi", "metadeta", "evm.bytecode", "evm.sourceMap"]}
            }
        },
    },
    solc_version="0.6.0",
)
print(compiled_sol) 
© www.soinside.com 2019 - 2024. All rights reserved.