Thursday, December 26, 2024

How do I spend bitcoins from a number of wallets in a single transaction?

There are at present three alternative ways to do that: uncooked transactions, PSBT in 0.17, and PSBT in 0.18. I like to recommend that you simply use PSBT in 0.18 as it’s the least problem, however I’ll describe all three right here for you.


Historically, you’d do that with createrawtransaction, fundrawtransaction, and signrawtransactionwithkey/signrawtransactionwithwallet. One particular person must know the entire inputs that had been getting used within the transaction or have all of these saved of their pockets (i.e. they’ve imported everybody else’s public keys and/or redeemScripts into their pockets) after which they will use createrawtransaction or fundrawtransaction to create the uncooked transaction.

createrawtransaction simply takes inputs and outputs which are specified by the person and offers the ensuing transaction as is (so you want to watch out about charges and alter). fundrawtransaction can select the inputs to make use of for you utilizing your pockets and it’ll deal with charges and alter outputs itself. Nevertheless fundrawtransaction must know the entire data essential to assemble the ultimate transaction (aside from the personal key, it will possibly simply use a dummy signature) with a view to accurately estimate the transaction charges, which is why you want to import the general public keys and scripts into your pockets.

Upon getting the uncooked transaction, you then ship it to every of the opposite folks concerned within the transaction. They then signal it utilizing signrawtransactionwithwallet (if the keys and scripts are of their pockets) or signrawtransactionwithkey (if their keys and scripts will not be of their pockets). Most individuals will use signrawtransactionwithwallet. They then ship the outcome again to you the place it’s important to mix the entire signed transactions into the ultimate transaction utilizing combinerawtransaction. Then you may broadcast it with sendrawtransaction.

As a substitute of sending the transactions out to everybody to signal on the identical time, you may ship to 1 one that indicators, who then sends to the subsequent particular person and so forth. This could not require combinerawtransaction. The final particular person would signal after which use sendrawtransaction to broadcast.

This course of is sort of cumbersome and requires that one particular person is aware of some (or all) of the data for the inputs getting used (aside from the personal keys).


Since Bitcoin Core 0.17, you need to use the assorted *psbt RPCs to attain the identical factor. With 0.17, the circulate is pretty much like the the uncooked transaction circulate described earlier. You would need to have the entire data for creating the ultimate transaction in your pockets (besides for personal keys) in order that price estimation could be correctly finished for coin choice, or you want to know which inputs to make use of. Both means, you employ walletcreatefundedpsbt and specify the inputs you need and the outputs you need. Bitcoin Core will then mechanically select extra inputs if there’s not sufficient to cowl the output quantity and create a change output for you. As a result of it must additionally conver transaction charges, it must have the identical data that you simply want for fundrawtransaction to have the ability to estimate charges for the inputs it chooses.

You then would ship the transaction to everybody else who would add their signatures (and different metadata) utilizing walletprocesspsbt. You too can do walletprocesspsbt first earlier than sending the transaction to everybody in order that varied metadata wanted for signing (just like the UTXO that’s being spent for every enter) is added beforehand. As soon as signed, everybody would ship the transaction again to you and also you mix them collectively utilizing combinepsbts You then create the ultimate transaction for broadcast utilizing finalizepsbt and ship the outcome utilizing sendrawtransaction.

After all utilizing PSBTs you are able to do the identical factor described above the place every particular person sends the transaction to the subsequent particular person to be signed as a substitute of sending again to you to be mixed.

Once more, this course of is sort of cumbersome and requires that one particular person is aware of some (or all) of knowledge for the inputs getting used (aside from the personal keys). However it’s barely much less prone to end in an error than the uncooked transaction methodology. PSBTs additionally lets you use different non-Bitcoin Core wallets that help PSBT, and you need to use this methodology with wallets which aren’t related to the web or in any other case do not need the blockchain or the UTXOs which are being spent within the transaction.


Nevertheless, Bitcoin Core 0.18 really makes this complete course of loads simpler. Bitcoin Core 0.18 introduces a few new *psbt RPCs which make it in order that one particular person doesn’t have to know the entire inputs getting used and the entire data for every enter. The one caveat is that this methodology assumes that every particular person has their very own outputs that they wish to create as a substitute of a number of folks pooling collectively their Bitcoin to make one massive output.

With 0.18, everybody would create their very own PSBT utilizing walletcreatefundedpsbt. They specify any of their very own inputs that they wish to use and all of their outputs. Any change outputs shall be added, and extra inputs from the pockets shall be added to cowl the output quantity and transaction price if not sufficient had been specified by the person. Since each person does this with their very own pockets, nobody particular person must know something about what the opposite customers have of their wallets.

Then every particular person would ship the PSBT to a delegated coordinator who makes use of joinpsbts to affix each PSBT into one massive PSBT. This PSBT can have the entire inputs and outputs that every particular person desires to spend and create. So as a substitute of getting many particular person PSBTs with their very own inputs and outputs, there’s now one massive PSBT with everybody’s inputs and outputs.

This PSBT is then despatched again to every one that makes use of walletprocesspsbt to replace the PSBT and add their enter data to the PSBT and indicators it. Even when a person has an airgapped setup the place their personal keys are someplace that doesn’t have entry to the blockchain, they will replace the PSBT from an internet watching solely pockets and ship the PSBT to the offline machine to be signed.

As soon as everybody has signed the PSBT, it’s despatched again to the coordinator who makes use of combinepsbt to mix the entire signatures and enter data into the identical PSBT, then creates the ultimate community transaction utilizing finalizepsbt and broadcasts it utilizing sendrawtransaction.

Once more, this may be finished serially like the opposite strategies described earlier and thus omit the necessity for combinepsbt.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles