【问题标题】:Web3 python can't send a transactionWeb3 python无法发送交易
【发布时间】:2021-10-22 18:26:18
【问题描述】:

我正在尝试从一个地址到另一个地址发送交易,一切正常,但我在 etherscan 上的交易状态是:

web3 = Web3(Web3.HTTPProvider(infura_url))
def send_transaction(from_address, private_key, to_address, amount_eth, gwei, gas_limit):

    # get the nonce
    nonce = web3.eth.getTransactionCount(from_address)

    # build transaction
    tx = {
        'nonce': nonce,
        'to': to_address,
        'value': web3.toWei(amount_eth, 'ether'),
        'gas': gas_limit,
        'gasPrice': web3.toWei(gwei, 'gwei')
    }

    tx_usd_price = (eth_usd_price*gas_limit*tx['gasPrice'])/10**18
    # print(f'Tx usd price: {tx_usd_price}')


    # sign transaction
    signed_tx = web3.eth.account.signTransaction(tx, private_key)

    # send transaction # get transaction hash
    tx_hash = web3.eth.sendRawTransaction(signed_tx.rawTransaction)

如何正确发送交易?

【问题讨论】:

    标签: python ethereum web3


    【解决方案1】:

    有两个原因

    1. 你的gas价格太低了
    2. 来自同一钱包/地址的其他交易正在等待处理。

    如果有相同地址的待处理交易,请等待它们被处理。 如果不起作用,请尝试将您的 gas 价格设置在 65-90 gwei 之间。

    【讨论】:

      猜你喜欢
      • 2019-10-25
      • 2023-01-13
      • 2022-01-04
      • 2019-12-05
      • 2020-12-06
      • 2021-10-02
      • 2018-11-04
      • 2023-02-12
      • 2021-05-29
      相关资源
      最近更新 更多