Matthew Pinnock
Matthew Pinnock

Reputation: 61

Why is my transaction not being found when running it through web3.py?

This is my first time trying anything with web3 and my transaction isn't sending I have checked the documentation and everything seems to be correct so i don't know why it isn't working.I have checked that I am connecting to my Ganache block chain and I am, I can also query to see account balances on the chain but I keep getting the same error when trying to send a transaction.

from web3 import Web3


gnache_url = "HTTP://127.0.0.1:7545"
web3 = Web3(Web3.HTTPProvider(gnache_url))

print(web3.isConnected())

account1 = "0x9D7700325246447A5e481f355167637e1a2f2a0A"
account2 = "0x3F764C22F69Da4754b16796cD4D2e5383FE43a5e"

private_key = "9aa34d6f42d04aa53146cdbba11a3e7e45d10971ae5b2bc49683d64b21cfa2b1"

#building the transaction
balance1 = web3.eth.get_balance(account1)
print(balance1)
nonce = web3.eth.getTransaction(account1)
transaction_info = {
    'nonce': nonce,
    'to': account2,
    'value': web3.toWei(1, 'ether'),
    'gas': 2000000,
    'gasPrice': web3.toWei('50','gwei')
}
signed_transaction = web3.eth.account.signTransaction(transaction_info,private_key)
print(signed_transaction.rawTransaction)

gives this output

True
100000000000000000000
Traceback (most recent call last):
  File "/home/th3shadow/Documents/BlockChain Stuff/Dapp Begin.py", line 17, in <module>
    nonce = web3.eth.getTransaction(account1)
  File "/usr/local/lib/python3.8/dist-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str, params, error_formatters)
  File "/usr/local/lib/python3.8/dist-packages/web3/manager.py", line 160, in request_blocking
    apply_error_formatters(error_formatters, response, params)
  File "/usr/local/lib/python3.8/dist-packages/web3/manager.py", line 65, in apply_error_formatters
    formatted_response = pipe(params, error_formatters)
  File "cytoolz/functoolz.pyx", line 667, in cytoolz.functoolz.pipe
  File "cytoolz/functoolz.pyx", line 642, in cytoolz.functoolz.c_pipe
  File "/usr/local/lib/python3.8/dist-packages/web3/_utils/method_formatters.py", line 604, in raise_transaction_not_found
    raise TransactionNotFound(f"Transaction with hash: {transaction_hash} not found.")
web3.exceptions.TransactionNotFound: Transaction with hash: 0x9d7700325246447a5e481f355167637e1a2f2a0a000000000000000000000000 not found.

Upvotes: 2

Views: 2874

Answers (1)

Matthew Pinnock
Matthew Pinnock

Reputation: 61

When defining the nonce variable remember to use

 web3.eth.get_transaction_count

instead of just

web3.eth.getTransaction

Upvotes: 4

Related Questions