【发布时间】: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)
如何正确发送交易?
【问题讨论】: