[英]web3 python ethereum raw transaction
我在尝试使用我的本地 geth 节点发送以太坊时收到此错误。
ValueError: {'code': -32000, 'message': 'insufficient funds for gas * price + value'}
这是我如何构建 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()
我的以太坊账户有超过 2 个可用的 ETH 我做错了什么? 谢谢!
节点错误不会说谎,因此节点认为您没有可用的 2 ETH。
您可以使用web3.eth.getBalance()
轻松查看您有多少可用空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.