Since the mempool is filling up nicely the last couple of days and i see loads of new and longtime members struggeling getting their transactions confirmed after paying a fee that's to low for the current status of the mempool, i decided to dedicate a long post to executing a Child Pays For Parent (CPFP).What is a CPFP? Well, if you create a transaction, you use one or more unspent outputs as an input for your new transaction, and your transaction creates one or more new unspent outputs funding an address created by the receiver and USUALLY the leftover funds (the change) funds an address created by your own wallet (the change address).
If the fee (in sat/vbyte) you chose when creating your transaction was to low (sometimes the wallet set a low fee in your place), miners won't have an incentive to add your transaction to the block they're currently trying to solve (yep, the fees go to the miner, NOT to the creator of the wallet), so the odds of getting your transaction confirmed are low.
A CPFP fixes this problem. A CPFP is taking one new unspent output created by your unconfirmed transaction and using it as an input for a new transaction. This new transaction should have a fee that is at least enough to cover the fee of your stuck transaction + the fee of your new transaction (minus the fee already payed for the stuck transaction).
If i miner wants to collect this big fee of the second transaction, he also has to put the stuck transaction into the block he's trying to solve.
A theoretical exampleunspent output aaa with a value of 1 BTC funds address 1MyWalletAddress
you use unspent output aaa as an input for a new transaction funding address 1ReceiverAddress with unspent output bbb (value 0.5 BTC) and change address 1ChangeAddress with unspent output ccc (value 0.499999). The fee payed by this transaction is 1 - (0.5+0.499999) => 0.000001 (100 sats). Waaaay to low... This transaction is stuck in the mempool for ages if we don't do something...
Well, luckily both you and the receiver have access to an address that was funded by this stuck transaction:
you have address 1ChangeAddress funded by unspent output ccc
the receiver has address 1ReceiverAddress funded by unspent output bbb
Soooo.... Either you create a new transaction using unspent output ccc as an input or the receiver creates a new transaction using unspent output bbb as an input.
The fee you should pay for this new is:
(the optimal fee of the first transaction) + (the optimal fee of the second transaction) - (the fee already payed for the first transaction => 100 sat) + (something extra since you don't want both transactions to get stuck if there's a sudden influx of tx's in the mempool).
For newbies, it might be usefull to use tools like
https://coinb.in/#fees, together with block explorers like blockchair.com to get a hold of the sizes of transactions (yes, it's the size of the transaction that matters, not it's value... It's perfectly possible to transfer $1.000.000 in value and pay a smaller fee than transferring $50 in value... It all depends on the amount of unspent outputs used as an input, the amount of new unspent outputs created, and the type of wallet).
A little boilerplate background info before i start posting screenshots:- CPFP is NOT the only tool in your toolbox when being faced with stuck transactions. Ideally you should have enabled opt-in RBF so you can just bump the fee.. Or you could pay viabtc or use their free accelerator, or you could just wait it out...
- I'm giving demos on the TESTNET... Yeah, at current feerates i'm not going to do a demo on the main net
- I take no responsability if you follow this walktrough and things go wrong... DYOR before executing following steps
- I'm using electrum... Why electrum? Well, to begin with, electrum is a popular wallet by itself... But, it also allows you to use many popular hardware wallets together with electrum without compromising your xprv. It also allows you restore wallets from many other popular vendors, and last but not least: it allows you to easily import multiple private keys... So many situations can be solved by using electrum, even if the initial problem wasn't "created" using electrum. Oh yeah, electrum runs on linux, windows, mac and android
- Do be carefull when downloading electrum: only download from electrum.org AND verify ThomasV's signature!!!
Now, let's get to it... Creating a CPFP for newbies (the easy version):Right click on the stuck transaction and see if there's a menu: child pays for parent... Follow the wizard
you'll be presented with a nice gui:
and what do we learn from this gui?
- the sum of the sizes of the stuck tx + the cpfp tx is 417 bytes
- since the testnet only requires 1 sat/byte, the gui proposes a fee of 417 sats...
- since the stuck tx already had a fee of 226 sats, this makes the total fee for child + parent 643 sats
If presented with the following screen, just click on "sign", sometimes you have to enter your password or use your hardware wallet to sign
if presented with the following screen, click on "broadcast"
Now, let's get to it... Creating a CPFP for newbies (the hard version where you'll actually learn what you're doing and have full controll):i started my electrum client on the testnet... But everything should work the same on the main net!
I "accidentally" created a tx with a fee of 1 sat/byte... For the testnet, that's actually sufficient... But we're going to pretend we're on the main net, and our sat/byte tx will be stuck for days/weeks
if i copy the tx id and look it up on an explorer like blockstream, or blockchair, or blockchain,...
you can see the following things:
- the status is unconfirmed... that's the big problem isn't it
- the ETA is one block because we're on the testnet... You'll probably see a much larger number, otherwise you wouldn't be reading this walktrough
- you see a fee of 1 sat/vbyte
- you see i opted in RBF... If you see the same for YOUR transaction, there's a much easyer way to solve your stuck transaction... Just increase the fee with electrum's gui... But for this tutorial, i wanted to show a CPFP, so that's what we're going to do (eventough i can get this tx unstuck in an easyer way)
- but the most interesting thing to see on this screenshot is: there are 2 unspent outputs created: one funding address 2MyMu3v5U7P7Ri2gThigxRn9VmandyepBVG with an unspent output with value 0.005 (this is the "payment"), and one funding address mjUxPsHYbn9rrs9c8bqNr4WFKCoeWCatmw with an unspent output with value 0.04499776 (this is the change)... Remember address mjUxPsHYbn9rrs9c8bqNr4WFKCoeWCatmw it's going to come back to haunt us
we want to show our unspent outputs in electrum
go to the "coins" tab, and you'll see a list of unspent outputs funding your addresses:
Do you see the unspent output funding my change address? mjUxPsHYbn9rrs9c8bqNr4WFKCoeWCatmw? That's the one we need!!! You could verify this by looking in the same "coins" tab to the "output point" column. This should be the tx id of the stuck transaction!!!
This tutorial is written from the sender's point of view... HOWEVER, it works exactly the same way if you're the receiver. In this case, you'll also see an unspent output funding the address you gave to the sender, this is the unspent output you want to use
once you've found the unspent output funding the change address created by the stuck transaction, do the following:
go to "preferences"
the transactions tab:
- use replace by fee => check if you never want to create another CPFP
- check advanced preview
- the rest are my personal settings, you can do with them what you want after reading the help info
go to the "addresses" tab (wich you might have to activate by clicking "view" => "show addresses" and pick an unused address (or a used one, i don't care)
copy it
click on the send tab, paste it, click on "max"
since you enabled "advanced preview" in the settings, you'll end up on this page:
As you can see, you can manually set the fee for your CPFP tx... Remember, you need the fee to cover the fee for your stuck transaction AND your cpfp transaction... Calculating an appropriate fee is a completely different discussion... And since this post is already huge i'll skip it... As a rule of thumb, you should at least double the current fee, unless the stuck transaction is big (in that case doubling it won't do the trick).
click on sign
enter your password (or sign using your hardware wallet)
click on "broadcast"
here's the block explorer's view of the address i'm using to receive the change from my CPFP:
Now, this is concludes creating a CPFP... Now let's see on my node what we actually did... This step cannot be executed by you, and it's not something that's necessary to create a CPFP... It's just my way of showing what actually happened:
This is the mempool view of my CPFP tx: do you see the fee? It's much higher than the 1 sat/vbyte fee we used for our stuck transaction isn't it? What's even more important is to see the tx id of the stuck transaction in the section "depends". This actually means that a miner cannot claim the fee of the CPFP tx without also including the stuck transaction... The CPFP tx depends on the stuck transaction.
Once a miner mines a block that includes the CPFP tx, he also has to include the stuck tx, solving your problem