full-blockchain-solidity-course-py
full-blockchain-solidity-course-py copied to clipboard
Stuck because of KeyError: 'evm'
In the web3 section of Patrick Collin's Solidity course I got stuck because of this annoying and hard to explain error when compiling the deploy.py file. Here's the code (the same as everyone's doing this tutorial):
from solcx import compile_standard, install_solc
import json
install_solc("0.6.0")
with open("./SimpleStorage.sol", "r") as file:
simple_storage_file = file.read()
# compile our solidity
install_solc("0.6.0")
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
"settings": { "outputSelection": {
"*": {
"*": ["abi", "metadata", "evm.bytecode", "evm.bytecode.sourceMap"]}
}
},
},
)
with open("compiled_code.json", "w") as file:
json.dump(compiled_sol, file)
# get bytecode
bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["evm"]["bytecode"]["object"]
# get abi
abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]
print(abi)
My compiled json:
{
"contracts": {
"SimpleStorage.sol": {
"SimpleStorage": {
"abi": [
{
"inputs": [
{ "internalType": "string", "name": "_name", "type": "string" },
{
"internalType": "uint256",
"name": "_favoriteNumber",
"type": "uint256"
}
],
"name": "addPerson",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "string", "name": "", "type": "string" }
],
"name": "nameToFavoriteNumber",
"outputs": [
{ "internalType": "uint256", "name": "", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256", "name": "", "type": "uint256" }
],
"name": "people",
"outputs": [
{
"internalType": "uint256",
"name": "favoriteNumber",
"type": "uint256"
},
{ "internalType": "string", "name": "name", "type": "string" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "retrieve",
"outputs": [
{ "internalType": "uint256", "name": "", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_favoriteNumber",
"type": "uint256"
}
],
"name": "store",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"evm": {
"bytecode": {
"functionDebugData": {},
"generatedSources": [],
"linkReferences": {},
"object":
{
"contracts": {
"SimpleStorage.sol": {
"SimpleStorage": {
"abi": [
{
"inputs": [
{ "internalType": "string", "name": "_name", "type": "string" },
{
"internalType": "uint256",
"name": "_favoriteNumber",
"type": "uint256"
}
],
"name": "addPerson",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "string", "name": "", "type": "string" }
],
"name": "nameToFavoriteNumber",
"outputs": [
{ "internalType": "uint256", "name": "", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256", "name": "", "type": "uint256" }
],
"name": "people",
"outputs": [
{
"internalType": "uint256",
"name": "favoriteNumber",
"type": "uint256"
},
{ "internalType": "string", "name": "name", "type": "string" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "retrieve",
"outputs": [
{ "internalType": "uint256", "name": "", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_favoriteNumber",
"type": "uint256"
}
],
"name": "store",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"evm": {
"bytecode": {
"functionDebugData": {},
"generatedSources": [],
"linkReferences": {},
"object":
{
"contracts": {
"SimpleStorage.sol": {
"SimpleStorage": {
"abi": [
{
"inputs": [
{ "internalType": "string", "name": "_name", "type": "string" },
{
"internalType": "uint256",
"name": "_favoriteNumber",
"type": "uint256"
}
],
"name": "addPerson",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "string", "name": "", "type": "string" }
],
"name": "nameToFavoriteNumber",
"outputs": [
{ "internalType": "uint256", "name": "", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256", "name": "", "type": "uint256" }
],
"name": "people",
"outputs": [
{
"internalType": "uint256",
"name": "favoriteNumber",
"type": "uint256"
},
{ "internalType": "string", "name": "name", "type": "string" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "retrieve",
"outputs": [
{ "internalType": "uint256", "name": "", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_favoriteNumber",
"type": "uint256"
}
],
"name": "store",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"evm": {
"bytecode": {
"functionDebugData": {},
"generatedSources": [],
"linkReferences": {},
"object":
Output:
line 25, in
did you find the solution?