I know for sure I have enough eth on account. Some prelims:

I am signing a raw transaction with web3.py, like so:

transaction = {
    'value': 1000,
    'gas': 2000000,
    'gasPrice': 20000000000,
    'nonce': 0,
    'chainId': 1,

I am using INFURA project id env variable in conjunction with this import:

from web3.auto.infura import w3

I sign successfully and attempt to send like so:

signed_tx = w3.eth.account.sign_transaction(transaction, 0xMYPRIVKEY)

web3.py version is: 5.10.0

And then bam this error. Any idea what might be causing it?

Running get balance on the sender address I get its balance:

>> 11000000000000000

Suppose I am writing incorrect units for gas, gasPrice or value ?

2000000 * 20000000000 + 1000 < 11000000000000000

is False, thus the error?

But when I use these params, it says the transaction is underpriced, what the... how does this work

value = 1000
gas = int(2000000 / 4)
gasPrice = 20000000000
  • The transaction is underpriced - this is typically because you've already executed a transaction with the same account and the same nonce, but with a higher gas price. – goodvibration May 21 at 20:14
  • gas = int(2000000 / 4) - this doesn't seem to have any logical reason behind it. – goodvibration May 21 at 20:15
  • For the rest of your question, please see my answer below. – goodvibration May 21 at 20:15
  • Pardon me about dividing. I was experimenting and looks like I didn't check what code I pasted here. Assume the "normal" gas and gasPrice. I will fix in due time – Naz May 24 at 16:33

The fact that you are not setting the data field implies that you are interested only in sending ether (rather than in executing a contract function).

If the destination address is of an externally-owned account, then you only need 21000.

If the destination address is of a smart-contract account, then you need slightly more than 21000.

However, even when the transaction requires much less gas for executing, configuring it with 'gas': 2000000 requires that you actually have the corresponding amount of ether (gas * gas price + value) in the account whose private key you are using in order to sign the transaction.

And although this account will not be charged that extra amount of gas, you still need to have the corresponding amount of ether (gas * gas price + value) in it.

| improve this answer | |
  • Thanks. I definitely have more than that – Naz May 24 at 16:31
  • I've been told that web3.eth.defaultAccount or from in transaction details need to be set to the address from which I send the txn. That doesnt help either. The problem is certainly not in the fact that I lack wei – Naz May 24 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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