Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: doublemining on August 21, 2014, 10:43:16 PM



Title: Spend exactly the coins of a given private address
Post by: doublemining on August 21, 2014, 10:43:16 PM
Hi,
Can you help me with understanding what the importprivkey and sendfrom functions does exactly?

I would like to be able to import a private key in the wallet, and then spend the coins (I mean, the same, with no link to my others private keys) using the imported private key. Does importprivkey mix everything or are private keys well separated in bitcoind?


Title: Re: Spend exactly the coins of a given private address
Post by: grue on August 21, 2014, 11:11:46 PM
use listunspent to get the amount stored at a particular address then use raw transactions api to create a transaction to spend from that particular address


Title: Re: Spend exactly the coins of a given private address
Post by: DannyHamilton on August 22, 2014, 02:09:49 PM
"sendfrom" does not send from an address. It sends from an account.  The wallet will choose bitcoins that were received that other addresses, and then update the internal account value.

The only way you are going to control which outputs you spend is to either use a wallet with coin control from the user interface, or to build raw transactions.


Title: Re: Spend exactly the coins of a given private address
Post by: Abdussamad on August 22, 2014, 09:44:34 PM
Bitcoin core has coin control since 0.9.0. See the screens here:

https://bitcoinspakistan.com/blog/whats-new-in-version-0-9-0-of-bitcoin-qt/

Select only the unspent outputs of your imported address and you'll keep things separated.


Title: Re: Spend exactly the coins of a given private address
Post by: DannyHamilton on August 23, 2014, 11:00:30 PM
What about assigning the address to a brand new account and using the sendfrom function?

"sendfrom" does not send from an address. It sends from an account.  The wallet will choose bitcoins that were received that other addresses, and then update the internal account value.

The only way you are going to control which outputs you spend is to either use a wallet with coin control from the user interface, or to build raw transactions.


Title: Re: Spend exactly the coins of a given private address
Post by: DannyHamilton on August 25, 2014, 07:56:33 PM
Oh yes thanks.
So I successfully created a raw transaction following this schema:

  • Get a list of not-yet-spent outputs with listunspent
  • Create a transaction using createrawtransaction
  • Apply signatures using signrawtransaction
  • Submit it using sendrawtransaction

I just have a last question to be sure I'm doing things right: here's signrawtransaction doc:
signrawtransaction <hex string> [{"txid":txid,"vout":n,"scriptPubKey":hex},...] [<privatekey1>,...] [sighash="ALL"]

I used signrawtransaction <hex string> and it worked, I was wondering if I had to specify the private key I want to use since all the inputs in the tx are from the same address?

You should not be testing on the bitcoin network.  That's a good way to lose a lot of money if you don't know what you are doing.

You should test on testnet until you are certain that you fully understand all the implications and consequences of what you are doing.

The parameters inside the square brackets [] are optional parameters.  If the private keys, and the unspent outputs are already known to the wallet, they are unnecessary.