[Lesson 4] KeyError: 'evm' #780
Answered
by
cromewar
spencergoff
asked this question in
Q&A
-
Given this code: from solcx import compile_standard, install_solc
import json
install_solc('0.6.0')
with open('./SimpleStorage.sol', 'r') as f:
simple_storage_file = f.read()
compiled_sol = compile_standard(
{
'language': 'Solidity',
'sources': {'SimpleStorage.sol': {'content': simple_storage_file}},
'settings': {
'outputSelection': {
'*': {'*': ['abi', 'metadata', 'evm.sourceMap']}
}
}
},
solc_version = '0.6.0',
)
with open('compiled_code.json', 'w') as file:
json.dump(compiled_sol, file)
bytecode = compiled_sol['contracts']['SimpleStorage.sol']['SimpleStorage']['evm']['bytecode']['object']
print(f'bytecode: {bytecode}') I get this output:
Here is my compiled_code.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"
}
],
"metadata": "{\"compiler\":{\"version\":\"0.6.0+commit.26b70077\"},\"language\":\"Solidity\",\"output\":{\"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\"}],\"devdoc\":{\"methods\":{}},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"SimpleStorage.sol\":\"SimpleStorage\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"SimpleStorage.sol\":{\"keccak256\":\"0x2d1fb3be1abc6740b1dbd06a57fa5dbb4c40f1f01bb6378bdc5eeb316de0e559\",\"urls\":[\"bzz-raw://8f44f4925f7c11f296c8f5fc22c68f281d2a62afbe119c26ac0309b9d2063b98\",\"dweb:/ipfs/QmSuUT9ouegfFVD5jdmFrhZzg3hSfwL64YyP27USpG6fFA\"]}},\"version\":1}"
}
}
},
"sources": {
"SimpleStorage.sol": {
"id": 0
}
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
cromewar
Jan 14, 2022
Replies: 2 comments 10 replies
-
Hello @spencergoff the reason is you are missing the following: "outputSelection": {
"*": {
"*": ["abi", "metadata", "evm.bytecode", "evm.bytecode.sourceMap"]
}
} "evm.bytecode", give it a try. |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
spencergoff
-
I have the exact same issue, BUT in my case I didn't miss the "evm.bytecode" in my code, and I still get the same error. I cannot find a solution anywhere on the whole internet. What should I do? Here's the codeÚ 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) ` |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @spencergoff the reason is you are missing the following:
"evm.bytecode", give it a try.