I am taking a course in solidity/python, where I have encountered an error, which it does seem I can solve myself.
from solcx import compile_standard, install_solc # <- import the install_solc method!
import json
from web3 import Web3
import os
from dotenv import load_dotenv
load_dotenv()
install_solc("0.6.0") # <- Add this line and run it
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",
)
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"]
#HTTP provider - connecting to ganache
w3 = Web3(Web3.HTTPProvider("http://XXXXXXX"))
#Network ID - Blockchain ID ganache
chain_id = XXXX
#Adress from ganache
my_address = "XXX"
private_key = os.getenv("my_private_key_1")
# From os env: my_private_key = os.getenv("Private_key_test_1")
# Create the contract in python
SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
#Get the latest transaction
nonce = w3.eth.getTransactionCount(my_address)
# 1. Build a transaction
# 2. Sign a transaction
# 3. Send a transaction
transaction = SimpleStorage.constructor().buildTransaction(
{"gasPrice": w3.eth.gas_price,
"chainID": chain_id,
"from": my_address,
"nonce": nonce}
)
signed_txn = w3.eth.account.sign_transaction(transaction, private_key=private_key)
print(signed_txn)
I have the following error:
TypeError("Transaction must not include unrecognized fields: %r" % superfluous_keys) TypeError: Transaction must not include unrecognized fields: {'chainID'} PS C:\Users\VSCode-win32-x64-1.40.1\Project\demos\web3_py_simple_storage>
Any help would be much appreciated...