3

What's happening when I use importprivkey? Are the coins merged to my existing private key or is the new key added to my wallet?

I want to import a private key, receive funds on it, and send the same coins using this key, not the others present in my wallet, is it possible with RPC commands? (for my website, I want the user to be able to see where his money is going by tracking the blockchain).

2

When you use importprivkey, the new private key is added to your wallet, giving you the ability to send coins received by a corresponding Bitcoin address. Your "balance" will also reflect this, including the coins accessible by this key in the total balance.

Bitcoind low level API gives you a pretty fine-grained control over your coins. Since there is no notion of a "source address" in the Bitcoin protocol, you have to specify the exact transaction and its output that you want to spend. Instead of using the common high-level RPC like sendtoaddress, you need to manually create a raw transaction, which comes in a few steps:

  1. Prepare the transaction via createrawtransaction command, specifying outputs that you want to spend,
  2. Sign the transaction using your imported private key via signrawtransaction,
  3. Send it onto network using sendrawtransaction.

Be careful when using this API as Bitcoind does not protect you from making fatal mistakes, rendering your coins unspendable. Make sure you test your code on the testnet thoroughly before going live.

0

Yes, you can send from specific address using RPC. For sure you can send money from specific address using raw transactions.
I haven't used bitcoind for a while, but I hope they might already have added CoinControl.

0

A good way to think of it is when you import a key to your wallet all of its inputs are added to the "input pool" as i like to call it. When a sendtoaddress or sendmany command is initiated it will pull what it thinks are the best inputs to make that transaction from the "input pool". Keys can be added/removed from accounts at any time taking their inputs with them. (although a rescan is required and done by default which takes some time)

This is the way its designed to work. But if you want to customize it to work with you it is possible. Just always be cautious of modifying and know what your doing. Mistakes with bitcoin transaction are irreversible and can be quite costly. You have a few options.

Accounts are usefull for this. A wallet can have multiple accounts. Think of accounts as a way to group keys together. You could make a new account for each user then use the sendfrom command to initiate all withdrawals from the wallet.

bitcoind sendfrom "fromaccount" "tobitcoinaddress" "amount" [minconf=1]

Where "fromaccount" is the account you want to send from. "tobitcoinaddress" is the destination. "amount" is the amount you want to send and [minconf=1] will not allow it to spend any input with less than 1 confirmation or any value you specify.

This will send only from the account you specify. Each account can have as many addresses as you like or just one.

Just be aware accounts should never be used for balance tracking. Only for groupings of keys. And if you ever use the sendto or sendmany commands they will pull the inputs from all accounts to make the withdrawal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.