2

I was following this course on ytb and after making the same code than him I encoutered a problem with solcx. Tanks a lot in advance. This is the error message (i'm french so the first line is french but i think you'll understand):

Information�: impossible de trouver des fichiers pour le(s) mod�le(s) sp�cifi�(s).
Traceback (most recent call last):
  File "d:\Code\Blockchain\demos\web3_py_simpleStorage\deploy.py", line 34, in <module>
    bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"]["bytecode"]["object"]
KeyError: 'evm'

This is my code (exactly the same as in the course):

import json
from solcx import compile_standard, install_solc

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


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

        },

    },
    solc_version="0.8.0"

)


with open("compiled_code.json", "w") as file:
    json.dump(compiled_sol, file)


# get bytecode
bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"]["bytecode"]["object"]


# get abi
abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]

The solidity code if you need but i think the problem is not here:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimpleStorage {
    // this will get initialized to 0!
    uint256 favoriteNumber;
    bool favoriteBool;
    struct People {
        uint256 favoriteNumber;
        string name;
    }
    People[] public people;
    mapping(string => uint256) public nameToFavoriteNumber;

    function store(uint256 _favoriteNumber) public {
        favoriteNumber = _favoriteNumber;
    }

    function retrieve() public view returns (uint256) {
        return favoriteNumber;
    }

    function addPerson(string memory _name, uint256 _favoriteNumber) public {
        people.push(People(_favoriteNumber, _name));
        nameToFavoriteNumber[_name] = _favoriteNumber;
    }
}

1 Answers1

0

there is a missing "," somehow in between "evm.bytecode" and "evm.bytecode.sourceMap", thus no evm related generate in the compiled_code.json