【问题标题】:I couldn't get results when I write compiled code in Visual Studio Code, I run python deploy.py and it gives me error. what I have to edit in my code当我在 Visual Studio Code 中编写编译代码时,我无法得到结果,我运行 python deploy.py,它给了我错误。我必须在我的代码中编辑的内容
【发布时间】:2021-12-11 20:14:47
【问题描述】:

我刚开始编码,似乎代码中缺少某些内容,这是编译后的代码。运行 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"}]}

【问题讨论】:

  • 错误可能提示您必须使用字词Solidity(上面是S)而不是solidity(下面是s
  • 我读到了“如何提问”。谢谢,给克里斯带来的不便,我深表歉意。
  • furas,我在问题中添加了链接,并感谢您的 cmets 我不时编辑 Solidity(带有上 S)它给了我相同的错误消息。
  • 在 json 中尝试 simpleStorage.sol -> SimpleStorage.sol

标签: python blockchain ethereum solidity smartcontracts


【解决方案1】:

你有两个错别字

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"]
            }
        }
    }
},

【讨论】:

    【解决方案2】:

    将 "语言": "solidity" 更改为 “语言”:“团结”,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-11
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      • 1970-01-01
      相关资源
      最近更新 更多