Web3.py transactions are not broadcast on Ethereum Rinkby testnet

Question:

I am using the web.py code below to try and send a transaction with 1 ETH on the Rinkeby testnet via a local geth node. I can see the transactions as submitted in live local ethereum node log stream, but they don’t ever seem to be broadcast to the network (I can never see them on rinkeby.io block explorer). I am manually setting the nonce each time, but I read that if a previous nonce was used and it didn’t broadcast it may be stuck? As a part of the answer it would be great if the nonce purpose/usage can be explained.

import web3, json, requests
from web3 import Web3, HTTPProvider
provider = HTTPProvider( 'http://localhost:8545' )
web3 = Web3(provider)

web3.eth.enable_unaudited_features()
with open('/Users/.../Library/Ethereum/rinkeby/keystore/UTC...') as keyfile:
    encrypted_key = keyfile.read()
    private_key = web3.eth.account.decrypt(encrypted_key, 'password')

tx = {'value': 1000000000000000000, 'to': '0xBa4DE7E3Fd62995ee0e1929Efaf7a19b73df028f', 'nonce': 100000000, 'chainId': 4, 'gasLimit': 6994000, 'gasPrice': 1000000000 }
tx['gas'] = web3.eth.estimateGas(tx)

signed = web3.eth.account.signTransaction(tx, private_key)
web3.eth.sendRawTransaction(signed.rawTransaction)
Asked By: Initial Commit

||

Answers:

The nonce for an externally owned account (EOA) starts at 0 and increases by one with each transaction. So the very first transaction an account sends needs to have the nonce 0, the second needs to have nonce 1, etc.

To get the correct current nonce, you can use web3.eth.getTransactionCount(<address>).

Answered By: user94559