Author

Topic: Bitcoin [ sendtoaddress ] command? (Read 200 times)

jr. member
Activity: 413
Merit: 5
May 06, 2018, 06:45:59 PM
#9
As far as I know,

If some send bitcoin by this command, [ sendtoaddress ],

then wallet decide where to pull bitcoin remaining balance from any inside accounts?


What is your wallet now?
I use new&old wallet. I manage many altcoins.
newbie
Activity: 80
Merit: 0
May 03, 2018, 02:54:40 AM
#8
As far as I know,

If some send bitcoin by this command, [ sendtoaddress ],

then wallet decide where to pull bitcoin remaining balance from any inside accounts?


What is your wallet now?
jr. member
Activity: 413
Merit: 5
May 03, 2018, 02:36:25 AM
#7

No!

This is the type of confusion that happens when people try to use the accounting system in Bitcoin Core instead of implementing their own accounting system.

Bitcoin Core will just as likely choose to use bitcoins that were previously received at an account that currently has a 0 (or even negative) balance.

Think about this like a bank.

Imagine you deposit $200 into YOUR ACCOUNT at the bank, and I deposit $500 into MY ACCOUNT at the same bank.  Now imagine that I return the next day and withdraw $200 from MY ACCOUNT.  Am I going to get those exact same bills from the bank that I gave them?  No.  The bank mixes the bills all up internally and stores them all together in a vault without any indication as to which bills were deposited into which account.  The account is just a number that is updated when the deposit is made.  After that, the actual money has NO CONNECTION to the account at all.  When I withdraw $200, I might get some of my original bills, I might get some of your original bills. It doesn't matter.  Regardless of which bills I get, MY ACCOUNT will be reduced by the amount that I withdraw.

Bitcoin Core accounts work the same way.  When you "receive at an account" the account value is increased, but the bitcoins are not in any way tied to that account.  When you "send from account", the account value is decreased, but the bitcoins themselves just come from the total bitcoins under the control of the wallet.  Some of the bitcoins sent MIGHT be the same bitcoins that were received at that account, some of the bitcoins sent MIGHT have been received at other accounts. It doesn't matter.  Regardless of which actual bitcoins are sent, the account that is being "sent from" will be reduced by the amount sent.
 
Thanks for clarification.
legendary
Activity: 3472
Merit: 4801
May 02, 2018, 09:52:29 AM
#6
If you have 2 accounts in bitcoin core, the default account and a new account named "A", and you have 2 BTC in default account but 5BTC in account B.
If you use the sendtoaddress command to send any amount of bitcoin, it will always debit the default account whether it has a balance or not.
For example if you send 3 BTC using the sendtoaddress command and the default account has 2 BTC balance, the transaction will succeed because Core will choose coins from the other account that has funds

No!

This is the type of confusion that happens when people try to use the accounting system in Bitcoin Core instead of implementing their own accounting system.

Bitcoin Core will just as likely choose to use bitcoins that were previously received at an account that currently has a 0 (or even negative) balance.

Think about this like a bank.

Imagine you deposit $200 into YOUR ACCOUNT at the bank, and I deposit $500 into MY ACCOUNT at the same bank.  Now imagine that I return the next day and withdraw $200 from MY ACCOUNT.  Am I going to get those exact same bills from the bank that I gave them?  No.  The bank mixes the bills all up internally and stores them all together in a vault without any indication as to which bills were deposited into which account.  The account is just a number that is updated when the deposit is made.  After that, the actual money has NO CONNECTION to the account at all.  When I withdraw $200, I might get some of my original bills, I might get some of your original bills. It doesn't matter.  Regardless of which bills I get, MY ACCOUNT will be reduced by the amount that I withdraw.

Bitcoin Core accounts work the same way.  When you "receive at an account" the account value is increased, but the bitcoins are not in any way tied to that account.  When you "send from account", the account value is decreased, but the bitcoins themselves just come from the total bitcoins under the control of the wallet.  Some of the bitcoins sent MIGHT be the same bitcoins that were received at that account, some of the bitcoins sent MIGHT have been received at other accounts. It doesn't matter.  Regardless of which actual bitcoins are sent, the account that is being "sent from" will be reduced by the amount sent.

but still debit the default account so the new balance for the default account will be -1 BTC.

Non-default accounts are also allowed to have a negative balance.
sr. member
Activity: 322
Merit: 363
39twH4PSYgDSzU7sLnRoDfthR6gWYrrPoD
May 01, 2018, 09:00:05 PM
#5
want to know both cases (HD wallet and old wallet).
If you have 2 accounts in bitcoin core, the default account and a new account named "A", and you have 2 BTC in default account but 5BTC in account B.
If you use the sendtoaddress command to send any amount of bitcoin, it will always debit the default account whether it has a balance or not.
For example if you send 3 BTC using the sendtoaddress command and the default account has 2 BTC balance, the transaction will succeed because Core will choose coins from the other account that has funds but still debit the default account so the new balance for the default account will be -1 BTC.

If instead you wish to send 3 BTC from the new wallet B instead then you'd use the
Code:
sendfrom
command instead.
For example
Code:
sendfrom "B" 1BitcoinAddress 3
This time it will debit account B instead and the account balances will be: default address: 2BTC and account B: 2BTC

If you wish to adjust the balances of different accounts then use the
Code:
move
command. This is a cosmetic change  within the wallet and so there's no need for a bitcoin transaction.
jr. member
Activity: 413
Merit: 5
May 01, 2018, 07:16:02 PM
#4
By "account" do you mean accounts with different HD seed & different addresses, or do you mean other addresses in the wallet.
If it's the former then
Code:
sendtoaddress
doesn't support accounts and will send from the default account ""

If it's the latter it just select UTXOs and spends according to the amount being sent.

So I want to know both cases (HD wallet and old wallet).

And account does not need maybe? When exchange's wallet, when issue address to user, attach that user's ID to address.

sr. member
Activity: 322
Merit: 363
39twH4PSYgDSzU7sLnRoDfthR6gWYrrPoD
May 01, 2018, 06:53:54 AM
#3
By "account" do you mean accounts with different HD seed & different addresses, or do you mean other addresses in the wallet.
If it's the former then
Code:
sendtoaddress
doesn't support accounts and will send from the default account ""

If it's the latter it just select UTXOs and spends according to the amount being sent.
legendary
Activity: 1946
Merit: 1427
May 01, 2018, 06:17:26 AM
#2
As far as I know,

If some send bitcoin by this command, [ sendtoaddress ],

then wallet decide where to pull bitcoin remaining balance from any inside accounts?





I'm not quite sure what you mean.

Do you mean

 A. What inputs are chosen by the wallet to be spent?

It uses a multi-pass approach, first trying to use only coins with at least six confirmations. In the next two passes it relaxes these requirements. Within each pass, it tries to minimize the number of transaction outputs claimed and then the amount of change returned.

Note that all coins in your wallet are considered. In the accounting model that the Bitcoin client uses, specific coins do not belong to specific accounts.
https://bitcoin.stackexchange.com/questions/1077/what-is-the-coin-selection-algorithm

Or

B. Where the so called "change" goes in case your inputs hold more bitcoin than you want to spend?

I believe the change simply gets send to the first adress in your keypool that doesn't hold any balance.

If you want to specify where the change goes i think you could use something like

Code:
changeaddress=yournewchangeaddress
https://bitcoin.stackexchange.com/a/32713

jr. member
Activity: 413
Merit: 5
May 01, 2018, 05:51:20 AM
#1
As far as I know,

If some send bitcoin by this command, [ sendtoaddress ],

then wallet decide where to pull bitcoin remaining balance from any inside accounts?



Jump to: