-
|
Hello everyone, I trust this meets you well. So my question is after building, signing and sending the transaction, I can't find the sent transaction on ganache (the transaction did not go through). I thought if it was as a result of the environment variables ( I'm working with windows) so I exposed my private key but it still did not work. (When I exposed my private key, i commented the import os and load dot env out) And this was what I got from the terminal INFO: Could not find files for the given pattern(s). The above exception was the direct cause of the following exception: Traceback (most recent call last): |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
|
Hi, the first thing I see is your chain id: 5777, this is most likely the network ID and you should set your chain id programmatically like so Please have a look at the section "Confusing network ID and chain ID" in this document: https://github.com/smartcontractkit/full-blockchain-solidity-course-py/blob/main/chronological-issues-from-video.md |
Beta Was this translation helpful? Give feedback.
-
`import json
from web3 import Web3
from solcx import compile_standard, install_solc
install_solc("0.8.7")
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)
# Compile solidity
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
"settings": {
"outputSelection": {
"*": {"*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]}
}
},
},
solc_version="0.8.7",
)
with open("compiled_code.json", "w") as file:
json.dump(compiled_sol, file)
# deploying in python
# get bytecode
bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][
"bytecode"
]
["object"]
# get abi
abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]
# for connecting to ganache
w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:7545"))
chain_id = 1337
my_address = "0xFfDc3c1cC6d4f5A1441D4DE4C6385eD39578a7db"
private_key = "0x11596c35b343ac83213d9ac84542556adad6b60ec45949ca2651d4f5046a6562"
# Create a contract
SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
# Get the latest transaction
nonce = w3.eth.getTransactionCount(my_address)
# Build transaction
transaction = SimpleStorage.constructor().buildTransaction(
{
"gasPrice": w3.eth.gas_price,
"chainId": chain_id,
"from": my_address,
"nonce": nonce,
}
)
# Sign transaction
signed_txn = w3.eth.account.signed_transaction(transaction, private_key=private_key)
# Send signed transaction
tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
# Wait for transaction to be mined and get on transaction receipt
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
[depoy.txt](https://github.com/smartcontractkit/full-blockchain-solidity-course-py/files/8043885/depoy.txt)
` |
Beta Was this translation helpful? Give feedback.
-
|
OK, so the problem was the wrong chain ID number as stated in my first reply. Happy it works now! Would you please be so kind and mark this post a "answered". This way others know that there is no need for further assistance. |
Beta Was this translation helpful? Give feedback.
OK, so the problem was the wrong chain ID number as stated in my first reply. Happy it works now!
Would you please be so kind and mark this post a "answered". This way others know that there is no need for further assistance.