Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: noureddin_regula on April 12, 2022, 04:42:34 AM



Title: Is there a way to import coins into a Bitcoin Core wallet?
Post by: noureddin_regula on April 12, 2022, 04:42:34 AM
Is there a way to import coins (UTXOs) into a Bitcoin Core wallet?

And can these coins also be used to build transactions / PSBTs (to be partially signed by the original / hot wallet)?


Title: Re: Is there a way to import coins into a Bitcoin Core wallet?
Post by: nc50lc on April 12, 2022, 06:17:33 AM
Bitcoin Core has RPC commands: createrawtransaction to manually create a transaction and converttopsbt to convert it into PSBT.
Neither require the UTXO set nor blockchain to use.

Reference: developer.bitcoin.org/reference/rpc/index.html (https://developer.bitcoin.org/reference/rpc/index.html#rawtransactions-rpcs)


Title: Re: Is there a way to import coins into a Bitcoin Core wallet?
Post by: noureddin_regula on April 12, 2022, 07:15:45 PM
Thanks. But creating a transaction or PSBT does not add it to the wallet (specifically to the `mapWallet` collection).
What I'm looking for is a way to import a coin (UTXO) into the wallet so that it can be considered when calculating the inputs for a transaction.

Is there an RPC to add a specific transaction to a wallet even if its outputs do not belong to the wallet ?


Title: Re: Is there a way to import coins into a Bitcoin Core wallet?
Post by: hosseinimr93 on April 12, 2022, 08:42:27 PM
What I'm looking for is a way to import a coin (UTXO) into the wallet so that it can be considered when calculating the inputs for a transaction.
You can use the following command and import the private key of the address holding the UTXO.

Code:
importprivkey "YourPrivateKey"

Note that you can use coin control feature to specify which UTXOs you want to use for your transaction.


Title: Re: Is there a way to import coins into a Bitcoin Core wallet?
Post by: BitMaxz on April 12, 2022, 11:58:59 PM
Are you talking about importing UTXO to an offline bitcoin core wallet? or online Bitcoin core wallet with prune enabled?

I can't find on Google if you can able to import UTXO in the offline wallet so that you can make a sign transaction without importing raw transaction.

Why don't you just make a raw transaction on https://coinb.in/#txoutputs and sign it with your offline wallet?
It would be easier than importing UTXO to offline wallet?


Title: Re: Is there a way to import coins into a Bitcoin Core wallet?
Post by: nc50lc on April 13, 2022, 04:20:20 AM
-snip-
Is there an RPC to add a specific transaction to a wallet even if its outputs do not belong to the wallet ?
AFAIK, there's none.

You can use the command suggested by hosseinimr93 to import a private key or importaddress (https://developer.bitcoin.org/reference/rpc/importaddress.html) to include its associated transaction(s) to the wallet.
If you're planning to use this method and there's more than one address to be imported,
I'd suggest to use "false" 'rescan' flag for the first few (so it wont scan right away) and "true" on the last.