Transaction takes forever

did you try to send more eth than the wallet address has in balance?

Yeah is that even possible ? If yes how can I prevent it ?

did you create that transaction programmatically? in that case you should check current wallet balance, subtract the gas price of that transaction (21000 * price in this case), and send only less than what it remains

I send like other transactions before sending eth. Like 2 before that have different Gas fee.
I thought the Balance automatically updates. So I need to actually Substrat the transaction a out from the user balance + gas fee of the transaction

Basically at the same time. So I need to substract the Balance variable in order to not send too much eth ? Qhat I donā€™t understand is why metamask allows such transactions. The Balance donā€™t get updated when I sign the transactions which take gas fee. Then when I try to send eth like the exact amount in the wallet subtracted to the gas fee it goes through

metamask should do that automatically, did you use metamask for that transaction?

Yeah the weird thing is. I send 2 transaction taking about 15$ gas fee. Like smart contract transactions and other. Then I send right after the balance. The full balance.

Letā€™s say I got 50$ in eth.
After the 2 transactions I should have 35$ in eth. So at the end its a 35$ transaction. But thatā€™s not the case. It sends 50$ - gas fee so 45$. Which doesnā€™t make any sense. Metamask allows that to happen.

How can I fix that ?

maybe at the moment when you send that transaction, the previous transaction was not confirmed, and metamask didnā€™t know how to take in consideration that previous transaction?

Yeah true. But how can I prevent that without having to wait that the other transactions are comfirmed ?

If you do it programmatically, you can take in social ration the previous transaction info and compute the values for gas price and how much eth to send.

In current situation you will have to send that transaction again and rewrite/reuse that nonce for the transaction that is pending.

Can you help me understand. What do you mean by reuse nonce. What will it do ?

So you mean access the information using the hash and get thr balance if it and then sibstract it from the balance ?

Iā€™m not sure why you want this sort of functionality? Are multiple requests being made at the same time where it will take money out or perform transactions using your wallet and you want these processed simultaneously?

you can do that directly from metamask, to specify a nonce, so what you make another transaction that replaces that currently pending transaction

Yes multiple transaction at the same time. The balance doesnā€™t update thought correctly

one solution would be to add a delay of few minutes

No way. So I can use a nonce to prevent that ?

No, that nonce is related to fixing transactions that are already in that pending state

i dont understand :frowning: why should i use nonce. Any other solution exept waitong few minutes ?

There is a similar discussion here.

ethers.js has a similar function.

To try this you will have to use ethers.js or web3.js directly. If it does work for you then any transactions will naturally revert/fail if thereā€™s not enough balance.

Your pending transaction issues seems unrelated though, you can try setting higher gas.