Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: CyberOperations on May 05, 2022, 08:32:23 AM



Title: Sending coins and receive "change" on special BTCAdr
Post by: CyberOperations on May 05, 2022, 08:32:23 AM
Hello, this is my first post and I really hope this question wasn't answered already, or is too noobish.
My search did not find a related topic, but the forum tells me I might be searching too quick  ;D
So I am asking you specialists here.

I wanted to work with labels (accounts) inside my testwallet, so I can manage different people,
that got their address bound to this "label/account". I know accounts are deprecated, but did not find
another solution.

Currently I am sending coins like this:

sendfrom "label" "to-btcadr" "amount"

e.g. >> btc-cli.exe sendfrom "Person 1" BTCADRxyz 0.1

Label "Person 1" has only one BTCAddress, but the "change" from this transaction
will create a new BTCAddress. This leads to a wrong balance checking his main BTCAdr.

My question is: how could I still send from one BTCAddress (or label) to another BTCAddress
and receive the change on a specific BTCAddress (prefered my main BTCAddress for the senind person)
via cli?


Title: Re: Sending coins and receive "change" on special BTCAdr
Post by: BlackHatCoiner on May 05, 2022, 08:47:23 AM
My question is: how could I still send from one BTCAddress (or label) to another BTCAddress
and receive the change on a specific BTCAddress (prefered my main BTCAddress for the senind person)
via cli?
Using sendmany. Example from the RPC API Reference:
bitcoin-cli sendmany "" "{\"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl\":0.01,\"bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3\":0.02}"

The first address is your person's address, the second is the change.


Title: Re: Sending coins and receive "change" on special BTCAdr
Post by: CyberOperations on May 05, 2022, 09:10:33 AM
Thank you. I guess that is a good way to handle it.
But I still need to figure out how to set the address it lowers the balance from,
so it takes it from the right account.

Currently it seems it is picking the BTC from the entire wallet, not from
let's say label "John", who is sending 2 of his BTC to "Peter".

EDIT: seems like the "move" command might solve my problems here inside the same wallet working with accounts.
Will update once tested.

Update:
sendmany '.$fromadrlabel.' {\"'.$toadr.'\":'.$amount.'}"',

and

move "'.$fromadrlabel.'" "'.$toadrlabel.'" '.$amount.'1',

did the trick for me. Thank you for helping to understand :)


Title: Re: Sending coins and receive "change" on special BTCAdr
Post by: takuma sato on May 06, 2022, 05:04:51 PM
I wouldn't pick coins from "labels", you can make mistakes, have repeated labels etc. I would always manually copypaste the addresses I want to use, or just manually click on them with CoinControl enabled where you can see them on a list in a tree form and with the labels.


Title: Re: Sending coins and receive "change" on special BTCAdr
Post by: Cricktor on May 06, 2022, 10:52:55 PM
@CyberOperations
Do you understand that Bitcoin transactions spend whole UTXO(s) and don't work account based like a bank account where you can deduce some small fraction of the total balance? (UTXO is Unspend Transaction Output, ie. a spendable output of a previous transaction).

I suggest a visit to https://learnmeabitcoin.com for basics or more.


Title: Re: Sending coins and receive "change" on special BTCAdr
Post by: NotATether on May 07, 2022, 04:29:43 AM
You can use listaddressgroupings RPC call and pass it an address, and it will list all of the change addresses associated with it. Then proceed to sweep those change addresses into your main address.