bswan
bswan

Reputation: 57

Web3 python can't send a transaction

I'm trying to send a transaction from address to address, everything works fine, but the status of my transaction on etherscan is: enter image description here

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)

How to send transactions properly?

Upvotes: 0

Views: 988

Answers (1)

sujith Kumar
sujith Kumar

Reputation: 11

There are 2 reasons for it

  1. You gas price is too low
  2. Other transactions from the same wallet/address are pending.

If there are pending transactions with the same address just wait for them to get proccessed. If it does'nt work then try setting up your gas price in between 65-90 gwei.

Upvotes: 1

Related Questions