17

This is a private network

A transaction was sent to create a contract using the eth_sendTransaction RPC call.

The transaction is "removed" marked "will be removed" because it ran out of gas but remains in the pending state and miners keep trying to process it.

1- Is there a way to cancel a pending transaction ?

According to the sendTransaction documentation resending a transaction with the same nonce allows to "overwrite your own pending transaction".

Using eth_getTransactionByHash it is possible to recover the nonce of a transaction.

However when sending a new transaction with the same nonce (and more gas), the new transaction fails with "TX (d37f7a1b) failed, will be removed: Transaction w/ invalid nonce"

2- How do we "overwrite" a pending transaction ?

Many Thanks


edit1: result of eth.pendingTransactions

The input is the same (same contract), and so is the the nonce.

The first 2 fail with TX (49dcf54d/7e591a92) failed, will be removed: Out of gas, the third one with TX (d37f7a1b) failed, will be removed: Transaction w/ invalid nonce. tx=8 state=9)

[{
    blockHash: null,
    blockNumber: null,
    from: "0x766b8dc3ee1a98dd53444ce3cc5a185305570861",
    gas: 90000,
    gasPrice: 20000000000,
    hash: "0x49dcf54d52ddad2cfb57d9805b1a94bbc6b60ad44eaac9c117399530424d1300",
    input: "0x60606...5056",
    nonce: 8,
    to: null,
    transactionIndex: null,
    value: 0
}, {
    blockHash: null,
    blockNumber: null,
    from: "0x766b8dc3ee1a98dd53444ce3cc5a185305570861",
    gas: 150000,
    gasPrice: 20000000000,
    hash: "0x7e591a92683453ea0ec6a7024d54198140ec2c23936b3662c4f3e0d9978fc828",
    input: "0x60606...5056",
    nonce: 8,
    to: null,
    transactionIndex: null,
    value: 0
}, {
    blockHash: null,
    blockNumber: null,
    from: "0x766b8dc3ee1a98dd53444ce3cc5a185305570861",
    gas: 500000,
    gasPrice: 20000000000,
    hash: "0xd37f7a1bcedef089723f31bbf155b6c4c66f77fd0b5a5f6c3168a0b8ff3af299",
    input: "0x60606...5056",
    nonce: 8,
    to: null,
    transactionIndex: null,
    value: 0
}]

edit2: change after the node that created the transactions started mining

The situation only changed when the node that created the transactions started mining

  • The first transaction was removed
  • The second transaction, although it was rejected with an OOG on storage allocation, completed and a contract address generated
  • The third transaction was removed

Is this the expected behaviour that the node that created the pending transaction must mine so that a transaction running OOG on another miner is actually removed ?

The original question still remains: how do we remove/cancel/overwrite a pending transaction ?

4
  • Are you sure the transaction has not been mined? What does "removed" mean, because miners will be happy to process that transaction that ran out of gas and collect the whole fee. In the console. trying ethereum.stackexchange.com/questions/645/… is one way to ascertain if the transaction is still pending.
    – eth
    Oct 7, 2016 at 1:05
  • @eth Hi. The transactions are still pending, see edit1 above. The exact message is "will be removed", but they are not. How do we remove/cancel/overwrite them ? Oct 7, 2016 at 3:53
  • @eth see edit2: I have problems understanding why a node that created a transaction must mine to clear the situation. Also the original question remains: How do we remove/cancel/overwrite pending transactions Oct 7, 2016 at 4:18
  • Have your tried re-sending the tx with a higher nonce and higher gas, if that gets mined then everyone should drop the pending tx with lower nonce.
    – xgabrielx
    Jul 10, 2017 at 17:46

2 Answers 2

5

To overwrite the original transaction, you will need to rebroadcast the same transaction with the same nonce but also with * > 10% higher gas price than before *

If you wish to cancel the transaction, rebroadcast a zero value transaction, with the same nonce, but > 10% higher gas price.

Only one of the transactions with that nonce can be included into the blockchain.

2
  • 2
    how do you "If you wish to cancel the transaction, rebroadcast a zero value transaction, with the same nonce, but > 10% higher gas price." Do you have any code?
    – JZ.
    Dec 14, 2017 at 7:30
  • You can do it from any wallet which lets you manually set the nonce. For instance, MyCrypto. Dec 18, 2018 at 15:37
6

I had a similar problem, I inadvertently made 20 transactions with GasPrice=0 which completely blocked my Geth instance. I followed the steps in this article to cancel the transactions. Essentially what you want to do is:

  1. Get a Geth console instance geth attach
  2. Check what transactions are pending (these are the ones blocking the whole thing) eth.pendingTransactions. This will return all the pending transactions. One or more objects that look like this: { blockHash: null, blockNumber: null, from: "your account", gas: 179412, gasPrice: 0, hash: "hex stuff", input: "hex stuff", nonce: 260, r: "hex stuff", s: "hex stuff", to: "hex stuff", transactionIndex: 0, v: "0x29", value: 0 }

Now one of two situations may arise, you only have one pending transaction or you have several.

Only one transaction

  1. Search for the transaction nonce (in the example above was 260)
  2. Unlock your account,

    personal.unlockAccount('<YOUR_ACCOUNT>') Unlock account <YOUR_ACCOUNT> Passphrase: true

  3. Send a transaction to yourself with the same nonce and 10% (at least) higher gas value, eth.sendTransaction({ from: '<YOUR_ACCOUNT>', to: '<YOUR_ACCOUNT>', value: 0, gasPrice: <NEW_HIGHER_GAS_PRICE>, gasLimit: 24000, nonce: '<NONCE_OF_YOUR_PENDING_TRANSACTION>' });

With several transactions

This is kind of a weird fix, but does the job :)

Do the same 1 & 2 steps from the previous case, then:

  1. Copy all the pending transaction objects and paste them on a text editor with multi-cursor functionality, such as sublime
  2. Select the nonce values (select one and then ctrl+D) and eliminate everything else
  3. Maintaining the multi-cursor, create the eth.sendTransaction() (fill out the account addresses and gas price before) around the nonce value. I made a gif showing this here.
  4. Copy that code and past it on the Geth console and press enter.

That should do it.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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