2

I have a bitcoin address generated in bitcoin-core (offline computer) I imported that one address into electrum as a watch-only wallet (online computer) From electrum I created an unsigned transaction scan it back using QR code to the offline computer.

Which one should I use to sign the unsigned transaction using bitcoin-core? signrawtransactionwithwallet or signrawtransactionwithkey? If possible please tell me the different cases of which one to use?

Please also tell me if there is any better way to sign unsigned transaction using bitcoin-core.

1 Answer 1

2

signrawtransactionwithwallet is used to sign transactions for your wallet in which you can avoid entering private keys for spending different UTXOs as the private keys are in your wallet. You may need to enter passphrase using walletpassphrase

signrawtransactionwithkey is used to sign transactions for spending any UTXO using private keys

Examples:

  1. I create a transaction for spending UTXO associated with address tb1qlqyjzjuxel0r80gs97uf5snh0a0kesmjyxxzey that belongs to my wallet
createrawtransaction "[{\"txid\":\"a1a564ae1983e1a87e731c4b9b205f3e8edbd724bb03d4474090f32ccd8f55a0\",\"vout\":0}]" "[{\"tb1qlu4kjktgcdru8cjnlx47me2ha4phxgceg2v4mj\":0.01}]" 0 true

Sign the transaction using signrawtransactionwithwallet without entering any private key

signrawtransactionwithwallet 0200000001a0558fcd2cf3904047d403bb24d7db8e3e5f209b4b1c737ea8e18319ae64a5a10000000000fdffffff0140420f0000000000160014ff2b695968c347c3e253f9abede557ed4373231900000000

Or I could sign the same transaction using private key for tb1qlqyjzjuxel0r80gs97uf5snh0a0kesmjyxxzey

dumpprivkey tb1qlqyjzjuxel0r80gs97uf5snh0a0kesmjyxxzey
signrawtransactionwithkey "0200000001a0558fcd2cf3904047d403bb24d7db8e3e5f209b4b1c737ea8e18319ae64a5a10000000000fdffffff0140420f0000000000160014ff2b695968c347c3e253f9abede557ed4373231900000000" "[\"cT29Pb7V9kxCp6VRfwNNips8T9beVV6AkJDJ9PZcn1RSx3pCnfCd\"]"
  1. I create a transaction in Bitcoin Core for spending UTXO that belongs to my wallet in Electrum and private key for it is in Electrum.

electrum-utxo

createrawtransaction "[{\"txid\":\"542646583f5bd9b8424832d84ccfd23148f1e19b1b75cf3945bc8693d2dcb82e\",\"vout\":2}]" "[{\"tb1qlu4kjktgcdru8cjnlx47me2ha4phxgceg2v4mj\":0.022}]" 0 true

I copy its private key from Electrum.

private-key-electrum

Sign transaction in Bitcoin Core using signrawtransactionwithkey:

signrawtransactionwithkey "02000000012eb8dcd29386bc4539cf751b9be1f14831d2cf4cd8324842b8d95b3f584626540200000000fdffffff01c091210000000000160014ff2b695968c347c3e253f9abede557ed4373231900000000" "[\"cSBRq5UwGRZdKwLh6XGf3XFkYDvLdz6WwMxmtTdTvrNyw76mHHAV\"]"
8
  • Thank you very much as always. So basically I would need to do the signature with wallet since the address is from that bitcoin-core wallet. It is save to expose the generated signed transaction string right?
    – bbnn
    Commented May 2, 2021 at 8:57
  • Yes you can use signrawtransactionwithwallet. Signed transaction hex does not contain private keys. But I will still not share it publicly and only use internally when required for broadcasting or other things.
    – user103136
    Commented May 2, 2021 at 9:06
  • Ok thank you, actually I will only make it public when I broadcast it to some unknown node using my bluewallet on iPhone, and that is my only concern of making it public.
    – bbnn
    Commented May 2, 2021 at 9:55
  • Turned out I cannot use both of them to sign transaction using the string generated from electrum. I need to save it as psbt file on electrum and then load it in bitcoin core. Is this normal?
    – bbnn
    Commented May 3, 2021 at 3:17
  • 1. I never said you can use both for signing input that doesn't belong to your bitcoin core wallet. In this case Example 2 will work. Both can only be used for inputs for which you have private keys in bitcoin core. 2. There are basically 3 steps for a transaction: Create, Sign and Broadcast. Yes you can create transaction in Electrum, copy PSBT and sign it in Bitcoin Core. Or create transaction in Bitcoin Core, copy hex and sign in Electrum. Related Q&A: bitcoin.stackexchange.com/questions/99111/…
    – user103136
    Commented May 3, 2021 at 3:26

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.