Transaction takes forever

Hey there,
First of all you guys have a awesome Support. I really enjoy moralis.
I am sending multiple transaction like 4-5 including sending ether but it sometimes literally takes 5-7 hours and it gets stuck in the pending state. Why Is it like that ?

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 ?