2
from web3 import Web3

infura_url = "https://goerli.infura.io/v3/<key>"
web3 = Web3(Web3.HTTPProvider(infura_url))
account_1 = '0x0BD2c4B74c3DEcF804567eb91DF84F3fAcC6DE32'
private_key1 = 'Private Key'
account_2 = '0xD1ED7acB72F84134203BB25AA0F5395a876BE18c'

#get the nonce.  Prevents one from sending the transaction twice
nonce = web3.eth.getTransactionCount(account_1)
tx = {
    'nonce': nonce,
    'to': account_2,
    'value': web3.toWei(1, 'gwei'),
    'gas': 4000,
    'gasPrice': web3.toWei('0', 'gwei')
}
signed_tx = web3.eth.account.sign_transaction(tx, private_key1)


#sign the transaction
signed_tx = web3.eth.account.sign_transaction(tx, private_key1)

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

#get transaction hash
print(web3.toHex(tx_hash))

after following chage i made in code , it worked. thanks you support.

tx = {
    'nonce': nonce,
    'to': account_2,
    'value': web3.toWei(1, 'gwei'),
    'gas': 6000000,
    'gasPrice': web3.toWei('0', 'gwei')
}

2 Answers 2

2

Are you trying to push this transaction on your local blockchain?

I think the issue is gas:4000

Please see if using more gas would fix this.

Example:

tx = {
    'nonce': nonce,
    'to': account_2,
    'value': web3.toWei(1, 'gwei'),
    'gas': 6000000,
    'gasPrice': web3.toWei('0', 'gwei')
}
0

I see two points:

  1. Gas price too low, one can not pay zero fee to validate an transaction: 'gasPrice': web3.toWei('0', 'gwei')
  2. You can also let the lib find the gas for you instead of pin it :gas': 4000,

try to send this:

tx = {
    'nonce': nonce,
    'to': account_2,
    'value': web3.toWei(1, 'gwei'),
    'gas': 0,
    'gasPrice': web3.eth.gas_price
}
gas = web3.eth.estimate_gas(tx)
tx.update({'gas': gas})
1
  • i add this , now it is giving diffarent err: File "cytoolz\functoolz.pyx", line 641, in cytoolz.functoolz.c_pipe File "C:\Python311\Lib\site-packages\web3_utils\method_formatters.py", line 580, in raise_solidity_error_on_revert raise ContractLogicError('execution reverted') web3.exceptions.ContractLogicError: execution reverted Feb 12, 2023 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.