When using metamask to initiate a transaction, what should I do if the transaction is stuck in pending?

Problem Description

        For example, if you initiate a transaction on the front-end page or directly using the metamask wallet, but find that the transaction has not been popped up to indicate success or failure, it may be that the transaction is stuck and has been in the pending state.

        On a blockchain browser, if you use the public chain of the blockchain browser you are currently using in the metamask wallet, the transaction initiated can be searched on the blockchain browser, just search your own wallet The address of the receiver or the address of the receiver's wallet can be searched. But if the transaction is suspended (that is, the stuck state I mentioned before), that is, the pending state, then the suspended transaction must be overwritten , otherwise the transaction cannot be initiated later.

Regarding the method of overriding pending transactions, there are two methods:

【1】Easy method. Send the transaction directly in metamask, and manually set the value of the nonce, because the pending transaction has a corresponding nonce, and now manually setting this nonce will overwrite the previously suspended transaction corresponding to the nonce, so that the transaction can still be normal afterwards conduct. Specific operation steps: Avatar in the upper right corner of the metamask wallet-Settings-Advanced: Change the advanced fuel control to enable, and then change the custom transaction nonce to enable .

[2] Use the web3 method, set the nonce in the method, and overwrite the pending transaction. I haven't implemented this method yet.

But you should use the sendTransaction method, because this method has a parameter that is nonce, which is used to overwrite the nonce of the previous transaction

Regarding the reason why the transaction is "stuck":        

        The reason may be that the gas fee is too low, and the miners feel that the gas fee is too low, so the miners will not verify the transaction, so this transaction cannot become a block on a certain public chain, which is naturally It means that the transaction cannot be completed, that is, it cannot be connected to the chain.

        Among them, there may be many stuck transactions, so as long as the transaction with nonce 0 is not covered, other transactions will be stuck. Among them, nonce means "transaction number".

Guess you like

Origin blog.csdn.net/qq_41083105/article/details/118802930