我正在使用python 3.6,Django 2.1.1,Solidity和web3.py v4开发网站。 我想将交易添加到ropsten testnet中,但是交易从未得到确认。这是代码:
amount_in_wei = w3.toWei(questionEtherValue,'ether')
nonce=w3.eth.getTransactionCount(w3.toChecksumAddress(questionairAddress))+1
txn_dict = {
'to': contractAddress,
'value': amount_in_wei,
'gas': 2000000,
'gasPrice': w3.toWei('70', 'gwei'),
'nonce': nonce,
'chainId': 3
}
signed_txn = account.signTransaction(txn_dict)
txn_hash = w3.eth.sendRawTransaction(signed_txn.rawTransaction)
try:
txn_receipt = w3.eth.waitForTransactionReceipt(txn_hash, timeout=300)
except Exception:
return {'status': 'failed', 'error': 'timeout'}
else:
return {'status': 'success', 'receipt': txn_receipt}
答案 0 :(得分:0)
啊,就像@ yasaman.h发现的那样,nonce
中存在一个错误的错误:
# original:
nonce = w3.eth.getTransactionCount(w3.toChecksumAddress(questionairAddress)) + 1
# should be:
nonce = w3.eth.getTransactionCount(w3.toChecksumAddress(questionairAddress))
事务的nonce
必须等于先前发送的事务计数。因此,新帐户发送的第一笔交易的nonce
为零。