<p>I'd like to generate a double spend transaction and increase the gas fees over the previous, unconfirmed transaction that has been stuck for a week. I know there's other answers regarding double spend but I'm looking for more of a technical answer specific to my thought process and sample code.</p>
<p>I understand the general premise is to recreate the originating transaction in its entirety. I've started by utilizing <code>bitcore-lib</code> to perform a <code>getRawTransaction</code> of my currently stuck transaction. From here, I'm iterating over the <code>vin</code> and performing a <code>getRawTransaction</code> of the vin's <code>txid</code> to retrieve the parent. I'm then parsing the parent, iterating over each <code>vout</code> and looking for <code>vout.n</code> to match the previous <code>vin.vout</code>. Once I find a match, I'm generating a <code>utxo</code> which effectively looks like this:</p>
<pre><code>const utxo = {
    address: output.scriptPubKey.addresses[0],
    txId: vin.txid,
    outputIndex: vin.vout,
    script: output.scriptPubKey,
    satoshis: output.value
};
</code></pre>
<p>I then use these utxos to generate and sign the transaction as follows (sorry for lack of full class, but the actual process of signing transactions is fully functional):</p>
<pre><code>const transaction = new Bitcore.Transaction();

transaction.fee(this.fee());
transaction.from(utxos);
targets.forEach((target) =&gt; {
    transaction.to(target.address, this.amountToSatoshis(target.amount));
});
transaction.change(address);
transaction.sign(this.privateKey(privateKey));
</code></pre>
<p><strong>So my questions are...</strong></p>
<ol>
<li>Is my thought process correct in how I could go about regenerating the original transaction for submission by <code>bitcore</code>?</li>
<li>Is there an easier way to regenerate the transaction and increase the fees than how I'm trying to do it?</li>
<li>When attempting to replicate/duplicate the previous utxos, would I want to also provide the <code>sequence</code> number in the utxo?</li>
<li>Will this even work or will I even be able to submit this transaction to my same core node?</li>
<li>If it won't work, would it work if I ran <code>-zapwallettxes</code> on the core node first?</li>
</ol>

CC BY-SA 4.0
2021-04-22T02:10:19.180Z
You are probably better off just doing a Child Pays For Parent transaction, assuming there was a change output and/or you are the recipient.
m1xolyd1an
CC BY-SA 4.0
2021-04-23T12:30:46.363Z
In this scenario, I am the sender wishing to increase the gas fees of my sent transaction @m1xolyd1an. It's currently being sent to an exchange address I don't control.
coffeeplease
<bitcoin-core><unconfirmed-transactions><doublespend><bitcore>
How to create a double spend to prioritize a new transaction over a previous unconfirmed transaction?
coffeeplease
# How to create a double spend to prioritize a new transaction over a previous unconfirmed transaction?

(Asked by: username_0 on 2021-04-21)

I'd like to generate a double spend transaction and increase the gas fees over the previous, unconfirmed transaction that has been stuck for a week. I know there's other answers regarding double spend but I'm looking for more of a technical answer specific to my thought process and sample code.
I understand the general premise is to recreate the originating transaction in its entirety. I've started by utilizing bitcore-lib to perform a getRawTransaction of my currently stuck transaction. From here, I'm iterating over the vin and performing a getRawTransaction of the vin's txid to retrieve the parent. I'm then parsing the parent, iterating over each vout and looking for vout.n to match the previous vin.vout. Once I find a match, I'm generating a utxo which effectively looks like this:
const utxo = {
    address: output.scriptPubKey.addresses[0],
    txId: vin.txid,
    outputIndex: vin.vout,
    script: output.scriptPubKey,
    satoshis: output.value
};

I then use these utxos to generate and sign the transaction as follows (sorry for lack of full class, but the actual process of signing transactions is fully functional):
const transaction = new Bitcore.Transaction();

transaction.fee(this.fee());
transaction.from(utxos);
targets.forEach((target) => {
    transaction.to(target.address, this.amountToSatoshis(target.amount));
});
transaction.change(address);
transaction.sign(this.privateKey(privateKey));

So my questions are...

Is my thought process correct in how I could go about regenerating the original transaction for submission by bitcore?
Is there an easier way to regenerate the transaction and increase the fees than how I'm trying to do it?
When attempting to replicate/duplicate the previous utxos, would I want to also provide the sequence number in the utxo?
Will this even work or will I even be able to submit this transaction to my same core node?
If it won't work, would it work if I ran -zapwallettxes on the core node first?

**Tags:** bitcoin-core, unconfirmed-transactions, doublespend, bitcore

> **Comments:**
> **username_1**: You are probably better off just doing a Child Pays For Parent transaction, assuming there was a change output and/or you are the recipient.  
> **username_0**: In this scenario, I am the sender wishing to increase the gas fees of my sent transaction @username_1. It's currently being sent to an exchange address I don't control.  

---

## 0 answers

