Skip to content
Advertisement

web3 python ethereum raw transaction

im getting this error while trying to send ethereum using my local geth node.

ValueError: {'code': -32000, 'message': 'insufficient funds for gas * price + value'}

here is how i build the tx

from web3 import Web3

w3 = Web3(Web3.HTTPProvider("http://localhost:8545"))

amount = 0.01
from_address = "0xF2........."
private_key = "cf.........."
address_to = "0x..."
nonce = w3.eth.getTransactionCount(from_address)

tx = {
  'from': from_address,
  'to': address_to,
  'value': w3.toWei(amount, 'ether'),
  'gas': 21000,
  'gasPrice': w3.eth.gas_price,
  'nonce': nonce,
  'chainId': 1
}
signed_txn = w3.eth.account.sign_transaction(tx, private_key=private_key)
send = w3.eth.sendRawTransaction(signed_txn.rawTransaction)
txid = send.hex()

My ethereum account has more than 2 ETH available What am I doing wrong?

Advertisement

Answer

The node error does not lie, so the node does not think you have 2 ETH available.

You can easily check with web3.eth.getBalance() how much you have available.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement