Search code examples
pythonblockchainethereumsoliditysmartcontracts

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


I have just started coding and it seems that there is something missing in the code, this is a compiled code. the error message that it gives me after running python deploy.py I checked it many times but still has the same error.

the code is from a lesson I am working on in this link: https://github.com/PatrickAlphaC/web3_py_simple_storage The code in this link: https://github.com/PatrickAlphaC/web3_py_simple_storage/blob/main/deploy.py

here's the code and the error message, thank you so much in advance :)

Code:

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)

Error:

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

Solution

  • You have two typos

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