Lesson 4 - Attribute Error #16
Answered
by
PatrickAlphaC
oceanKingEth
asked this question in
Q&A
-
In lesson 4, trying to send first transaction to ganache. tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction) i get this error: could someone please point me in the right direction to figure this out? |
Beta Was this translation helpful? Give feedback.
Answered by
PatrickAlphaC
Sep 13, 2021
Replies: 1 comment 1 reply
-
Does all the rest of your code look like this: import json
from web3 import Web3
# In the video, we forget to `install_solc`
# from solcx import compile_standard
from solcx import compile_standard, install_solc
import os
from dotenv import load_dotenv
load_dotenv()
with open("./SimpleStorage.sol", "r") as file:
simple_storage_file = file.read()
# We add these two lines that we forgot from the video!
print("Installing...")
install_solc("0.6.0")
# Solidity source code
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",
)
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(os.getenv("RINKEBY_RPC_URL")))
chain_id = 4
# For connecting to ganache
# w3 = Web3(Web3.HTTPProvider("http://0.0.0.0:8545"))
# chain_id = 1337
my_address = "YOUR_ADDRESS_HERE"
private_key = os.getenv("PRIVATE_KEY")
# Create the contract in Python
SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
# Get the latest transaction
nonce = w3.eth.getTransactionCount(my_address)
# Submit the transaction that deploys the contract
transaction = SimpleStorage.constructor().buildTransaction(
{"chainId": chain_id, "from": my_address, "nonce": nonce}
)
# Sign the transaction
signed_txn = w3.eth.account.sign_transaction(transaction, private_key=private_key)
print("Deploying Contract!")
# Send it!
tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
PatrickAlphaC
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does all the rest of your code look like this: