Transactions model
Ethereum transactions model is vastly different from Bitcoin. Instead of using UTXO (unspent transaction outputs) transaction uniqueness and order are achieved using transaction nonce. It is an integer (uint256
) counter which is incremented for each transaction of an account. Its value is effectively the number of transactions sent from a given address and its value must be included in every transaction.
There are two rules:
transactions must be processed in order (transaction with a nonce of 1
must be processed before the transaction with a nonce of 2
)no skipping (transaction with a nonce of 4
cannot be included in a block until transactions with nonces of 1
, 2
, 3
are processed)
This way the network is able to identify duplicates of transactions and enforce their order (which is essential for smart contracts).
Gas price and transaction fees
Each transaction must set gas price which directly affects transaction fees. Miners optimize their profits by including transactions with a high gas price first.
If gas price is low the transaction will wait for a long time until it is mined. Eventually, it will be mined (sometimes many hours later) or dropped (miners have limited resources to queue pending transactions). However, even if the transaction is dropped by miners it may still await in pendingTransaction
list of your client and artificially increase your nonce
.
You can explore the list of pending transactions on Etherscan.
Blocked account
When a transaction is waiting for being mined all subsequent transactions are blocked. They cannot be included in a block until the previous one is included (it is determined by mentioned nonce value). Even if subsequent transactions have a very high gas price they cannot be processed as it would break the order of transactions and produce different state than expected. This makes the account effectively blocked.
How to cancel pending transaction
A single transaction with a low gas price renders the whole account unusable for many hours. The easiest and often most viable solution is to cancel the transaction. But wait, there is no such method in wallets or even API for that!
Fortunately, it is possible. The solution is not obvious but quite logical. A transaction can be overridden with a different transaction that is more attractive to miners.
The solution is to send another transaction with the same nonce and higher gas price. But what kind of transaction can act as a NOP (no operation)?
It turns out that transaction of sending 0 ether
to itself (from == to
) is a perfect candidate without any side effects. Obviously, the transaction must be signed by the same account as the one that sent the pending transaction.
Let’s start geth console
geth attach
The first step is to identify pending transaction hash. You can list pending transactions using geth
specific call:
eth.pendingTransactions
Also, you can locate it in the list of transactions from your account on Etherscan.
Next, we need to unlock the account to sign the transaction.
personal.unlockAccount('<YOUR_ACCOUNT>')
Unlock account <YOUR_ACCOUNT>
Passphrase:
true
When we unlocked the account and identified the pending transaction nonce
and previous gasPrice
, we can send zero value transaction from
and to
your account using more reasonable gas price and the same nonce as the pending transaction.
The gas price should be at least 10% higher than previously but I suggest checking ETH Gas Stations for the recommended gas price which varies depending on the network congestion.
gasPrice
should be expressed in wei
units (smallest Ethereum unit 10e-18
).
You can use web3
helpers to convert Ethereum units, for example, web3. toWei(21, 'gwei')
.
eth.sendTransaction({
from: '<YOUR_ACCOUNT>',
to: '<YOUR_ACCOUNT>',
value: 0,
gasPrice: <NEW_HIGHER_GAS_PRICE>,
gasLimit: 24000,
nonce: '<NONCE_OF_YOUR_PENDING_TRANSACTION>'
});
A long way ahead of GUI wallets
One can very easily block the account by sending a transaction with a low gas price. It may happen even if the price is reasonable but the network is experiencing congestion. Unfortunately, at the time of writing, Ethereum clients (official Wallet, Mist, MetaMask etc.) do not support canceling transactions nor increasing the gas price after transaction broadcast. I hope that such low-level solution will not be needed in the future as it may cause a lot of issues for the beginners.
Read More:
- How to cancel the commit, how to cancel the commit after git commit, and how to change the submitted content
- How to batch comment and cancel Python code
- Built on Ethereum, puppeth cannot be used to create the initial block, and an error is reported Fatal: Failed to write genesis block: unsupported fork ordering: eip15
- [Solved] Logon failed, use ctrl+c to cancel basic credential prompt. unable to access
- The Ethereum private chain is built, and the block information cannot be synchronized. The error is resolved: Node data write error err=”state node failed with all peers(1 tries, 1 peers)
- error: RPC failed; curl 92 HTTP/2 stream 0 was not closed cleanly: CANCEL (err 8)
- How to Fix Session is not Connecting (How to Diagnose it)
- How to set the custom blood bar UI in UE4 and how to call it
- How to print how to output Int64_ t,uint64_ The value of T in C
- How to Use Truffle to Deploy contracts on moonbeam
- How to Fix failed to Connect to MySQL at localhost:3306 with user root
- How to solve the problem of “unable to open source file XXXXX. H” in VS development?
- Come and watch! Let’s see how people use Python to visualize the congestion situation of cities
- How to Fix Failed to add the host to the list of known hosts
- How to Fix Unknown error: Unable to build: the file dx.jar was not loaded from the SDK folder!
- How to modify TeamViewer ID
- Java – how to shuffle an ArrayList
- How to solve problems like curl: (7) failed to connect to raw.githubusercontent.com Port 443: problem with connection used
- Tensorflow: How to use expand_Dim() to add dimensions
- Failed to connect to non-global ctrl_ifname: (nil) error: No such file or directory (How to Fix)