While deploying my smart contract, I keep getting this error: Warning! Error encountered during contract execution [invalid opcode: PUSH0
import solcx
solcx.install_solc('0.6.0')
from solcx import compile_standard
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(simple_storage_file)
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
"settings": {
"outputSelection": {
"*": {
"*": ["abi", "metadata", "evm.bytecode", "evm.bytecode.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 = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]
print(abi)
w3 = Web3(Web3.HTTPProvider("https://goerli-rollup.arbitrum.io/rpc"))
chain_id = 421613
my_address = "0xc80e5761af132995BecefD637**************"
private_key = "0x1d70b76bc2**********************"
#Create contract in Ganache
SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
#Get the latest transaction
nonce = w3.eth.get_transaction_count(my_address)
print(nonce)
#Build a transaction
#Sign a transaction
#Send a transaction
#transaction = SimpleStorage.constructor().build_transaction({"chainId" : chain_id, "gasPrice": w3.eth.gas_price,"from" : my_address, "nonce": nonce})
print(w3.eth.gas_price)
transaction = SimpleStorage.constructor().build_transaction(
{
"chainId": chain_id,
"gasPrice": 900000000,
"from": my_address,
"gas": 100000,
"nonce": nonce,
}
)
print(transaction)
signed_txn = w3.eth.account.sign_transaction(transaction, private_key=private_key)
private_key = os.getenv("PRIVATE_KEY")
print(private_key)
print(signed_txn)
tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
I am following this tutorial https://www.youtube.com/watch?v=M576WGiDBdQ Lesson 4
This is my solidity file:
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
contract SimpleStorage {
uint256 favoriteNumber;
// This is a comment!
struct People {
uint256 favoriteNumber;
string name;
}
People[] public people;
mapping(string => uint256) public nameToFavoriteNumber;
function store(uint256 _favoriteNumber) public {
favoriteNumber = _favoriteNumber;
}
function retrieve() public view returns (uint256){
return favoriteNumber;
}
function addPerson(string memory _name, uint256 _favoriteNumber) public {
people.push(People(_favoriteNumber, _name));
nameToFavoriteNumber[_name] = _favoriteNumber;
}
}