def broadcast_transaction(sender, private_key, amount, contract):
# Get the nonce. Prevents one from sending the transaction twice
nonce = web3.eth.getTransactionCount(sender)
to_address = web3.toChecksumAddress(contract)
# Build a transaction in a dictionary
tx = {
'nonce': nonce,
'to': to_address,
'value': web3.toWei(amount, 'gwei'),
'gas': 2000000,
'gasPrice': web3.toWei('7', 'gwei'),
'chainId': 0x38
}
# sign the transaction
signed_tx = web3.eth.account.sign_transaction(tx, private_key)
# send transaction
tx_hash = web3.eth.sendRawTransaction(signed_tx.rawTransaction)
# get transaction hash
tx_id = web3.toHex(tx_hash)
Mar 25, 2022, 9:04 PM
I had a working script on Git
But it stopped working for some reason @bondcoder
Mar 25, 2022, 9:05 PM
Print tx in console and check that all is right
Mar 25, 2022, 9:06 PM
All is right in console
Mar 25, 2022, 9:07 PM