-
Hello! Here's the code: from solcx import compile_standard, install_solc
import solcx
import json
from web3 import Web3
import os
solcx.install_solc("0.8.7") # or whatever version we want
with open("SimpleStorage.sol", "r") as file:
simple_storage_file = file.read()
print("Installing...")
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.sourceMap"]}
}
},
},
solc_version="0.6.0",
)
# print(compiled_sol)
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 = json.loads(
compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["metadata"]
)["output"]["abi"]
w3 = Web3(Web3.HTTPProvider("HTTP://127.0.0.1:7545"))
chain_id = 1337
my_address = "0xaADe4fEB069c55E1394Db2E5467Ff147D0fbC7Eb"
private_key = os.getenv("PRIVATE_KEY")
print(private_key)
SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
# Get the latest transaction
nonce = w3.eth.getTransactionCount(my_address)
print(nonce)
transaction = SimpleStorage.constructor().buildTransaction(
{
"chainId": chain_id,
"gasPrice": w3.eth.gas_price,
"from": my_address,
"nonce": nonce,
}
)
signed_txn = w3.eth.account.sign_transaction(transaction, private_key=private_key) The error:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hello @HalaAura you have a mismatch on the solcx versions Best regards, Cromewar. |
Beta Was this translation helpful? Give feedback.
Hello @HalaAura you have a mismatch on the solcx versions
solcx.install_solc("0.8.7") # or whatever version we want
you don't need this line. Also regarding to the env variables, as you are on windows you'll probably would have to add them to your path through windows advanced configuration, otherwise vscode might not recognize it.Best regards, Cromewar.