【问题标题】:web3 python ethereum raw transactionweb3 python 以太坊原始交易
【发布时间】:2021-10-02 11:46:56
【问题描述】:

我在尝试使用我的本地 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 我究竟做错了什么?谢谢!

【问题讨论】:

    标签: python ethereum web3


    【解决方案1】:

    节点错误不是说谎,所以节点不认为你有 2 ETH 可用。

    您可以通过web3.eth.getBalance() 轻松查看您有多少可用空间。

    【讨论】:

      猜你喜欢
      • 2022-07-19
      • 2019-12-09
      • 2022-11-11
      • 1970-01-01
      • 2018-06-23
      • 2018-11-04
      • 2018-09-19
      • 2018-01-15
      • 1970-01-01
      相关资源
      最近更新 更多