Ethereum 为什么通过web3.py运行我的事务时找不到它?

Ethereum 为什么通过web3.py运行我的事务时找不到它?,ethereum,web3,truffle,web3py,Ethereum,Web3,Truffle,Web3py,这是我第一次尝试使用web3进行任何操作,但我的交易没有发送。我检查了文档,所有内容似乎都是正确的,所以我不知道为什么它不起作用。我检查了我是否连接到我的Ganache区块链,我是,我也可以查询以查看链上的帐户余额,但在尝试发送交易时,我会不断收到相同的错误 from web3 import Web3 gnache_url = "HTTP://127.0.0.1:7545" web3 = Web3(Web3.HTTPProvider(gnache_url)) print

这是我第一次尝试使用web3进行任何操作,但我的交易没有发送。我检查了文档,所有内容似乎都是正确的,所以我不知道为什么它不起作用。我检查了我是否连接到我的Ganache区块链,我是,我也可以查询以查看链上的帐户余额,但在尝试发送交易时,我会不断收到相同的错误

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)
给出这个输出

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.
True
100000000000000000000
回溯(最近一次呼叫最后一次):
文件“/home/th3shadow/Documents/BlockChain Stuff/Dapp Begin.py”,第17行,在
nonce=web3.eth.getTransaction(account1)
调用者中的文件“/usr/local/lib/python3.8/dist-packages/web3/module.py”,第57行
结果=w3.manager.request\u阻塞(方法\u str、参数、错误\u格式化程序)
文件“/usr/local/lib/python3.8/dist-packages/web3/manager.py”,第160行,在请求块中
应用错误格式化程序(错误格式化程序、响应、参数)
文件“/usr/local/lib/python3.8/dist packages/web3/manager.py”,第65行,在apply\u error\u格式化程序中
格式化的\u响应=管道(参数、错误\u格式化程序)
文件“cytoolz/functoolz.pyx”,第667行,位于cytoolz.functoolz.pipe中
cytoolz.functoolz.c_管道中的文件“cytoolz/functoolz.pyx”,第642行
文件“/usr/local/lib/python3.8/dist packages/web3/\u utils/method\u formatters.py”,第604行,在raise\u事务中未找到
raise TransactionNotFound(f“具有哈希的事务:{Transaction\u hash}未找到。”)
web3.exceptions.TransactionNotFound:未找到哈希为0x9D7700325246447A5E481F355167637E1A2F2A000000000000000000000000的事务。

定义nonce变量时,请记住使用

 web3.eth.get_transaction_count
而不仅仅是

web3.eth.getTransaction