简体   繁体   中英

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? Thank you!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM