-
|
Hi everyone, I had everything working well and was able to deploy transactions and see them on the Ganache GUI. Now, when I type "python deploy.py" in a new terminal window I get the message below.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
|
there might be a problem with the bytcode encode on your deploy script, please copy and paste it here, I'll check it. |
Beta Was this translation helpful? Give feedback.
-
|
Hi, thank you in advance. ` from solcx import compile_standard, install_solc
import json
from web3 import Web3
import os
from dotenv import load_dotenv
load_dotenv()
with open("./SimpleStorage.sol", "r") as file:
simple_storage_file = file.read()
print("Installing solc...")
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",
)
with open("compiled_code.json", "w") as file:
json.dump(compiled_sol, file)
bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][
"bytecode"
]["object"]
abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]
w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:8545"))
chain_id = 1337
my_address = "0x3bDf1eEcce4162f0C751C322dc3BFb4DBB8cd646"
private_key = os.getenv("PRIVATE_KEY")
SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
nonce = w3.eth.getTransactionCount(my_address)
transaction = SimpleStorage.constructor().buildTransaction(
{"chainId": chain_id, "from": my_address, "nonce": nonce}
)
signed_txn = w3.eth.account.sign_transaction(transaction, private_key=private_key)
print("Deploying contract...")
tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash) ## Wait for confirmation
print("Contract deployed!")
simple_storage = w3.eth.contract(address=tx_receipt.contractAddress, abi=abi)
print("Initial value stored on the contract:")
print(simple_storage.functions.retrieve().call())
print("Updating contract...")
store_transaction = simple_storage.functions.store(15).buildTransaction(
{"chainId": chain_id, "from": my_address, "nonce": nonce + 1}
)
signed_store_txn = w3.eth.account.sign_transaction(
store_transaction, private_key=private_key
)
send_store_txn = w3.eth.send_raw_transaction(signed_store_txn.rawTransaction)
tx_receipt = w3.eth.wait_for_transaction_receipt(send_store_txn)
print("Contract updated! New value stored on the contract:")
print(simple_storage.functions.retrieve().call())
` |
Beta Was this translation helpful? Give feedback.
-
|
Your code seems to be ok, the problem most probably is on
|
Beta Was this translation helpful? Give feedback.
Your code seems to be ok, the problem most probably is on
dotenvpython package which is nor recognizing your private key. Try to follow this steps: