What is the difference between signrawtransactionwithwallet vs signrawtransactionwithkey in signing unsigned raw transaction? 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.
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:

I create a transaction for spending UTXO associated with address tb1qlqyjzjuxel0r80gs97uf5snh0a0kesmjyxxzey that belongs to my wallet

createrawtransaction &quot;[{\&quot;txid\&quot;:\&quot;a1a564ae1983e1a87e731c4b9b205f3e8edbd724bb03d4474090f32ccd8f55a0\&quot;,\&quot;vout\&quot;:0}]&quot; &quot;[{\&quot;tb1qlu4kjktgcdru8cjnlx47me2ha4phxgceg2v4mj\&quot;:0.01}]&quot; 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 &quot;0200000001a0558fcd2cf3904047d403bb24d7db8e3e5f209b4b1c737ea8e18319ae64a5a10000000000fdffffff0140420f0000000000160014ff2b695968c347c3e253f9abede557ed4373231900000000&quot; &quot;[\&quot;cT29Pb7V9kxCp6VRfwNNips8T9beVV6AkJDJ9PZcn1RSx3pCnfCd\&quot;]&quot;


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.


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

I copy its private key from Electrum.

Sign transaction in Bitcoin Core using signrawtransactionwithkey:
signrawtransactionwithkey &quot;02000000012eb8dcd29386bc4539cf751b9be1f14831d2cf4cd8324842b8d95b3f584626540200000000fdffffff01c091210000000000160014ff2b695968c347c3e253f9abede557ed4373231900000000&quot; &quot;[\&quot;cSBRq5UwGRZdKwLh6XGf3XFkYDvLdz6WwMxmtTdTvrNyw76mHHAV\&quot;]&quot;