Bitcoin Forum
April 26, 2024, 02:15:13 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: details for bitcoin core sendtoaddress method  (Read 78 times)
ayza_aa (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 1


View Profile
June 13, 2021, 08:48:46 AM
 #1

hi everyone
I want to use "sendtoaddress" method for withdrawing my users.

1) if I set "subtractfeefromamount" to false, fee deducted from where? and How is fee calculated?

2) for example , if i have 2 bitcoin in my wallet, and the user withdraws one bitcoin, the rest coin (one bitcoin - fee) how calculated (utxo) ?

3) consider the above example, I want the rest coin return to the new address (different from the source address (HD wallet)), Is there a way?
1714097713
Hero Member
*
Offline Offline

Posts: 1714097713

View Profile Personal Message (Offline)

Ignore
1714097713
Reply with quote  #2

1714097713
Report to moderator
1714097713
Hero Member
*
Offline Offline

Posts: 1714097713

View Profile Personal Message (Offline)

Ignore
1714097713
Reply with quote  #2

1714097713
Report to moderator
1714097713
Hero Member
*
Offline Offline

Posts: 1714097713

View Profile Personal Message (Offline)

Ignore
1714097713
Reply with quote  #2

1714097713
Report to moderator
No Gods or Kings. Only Bitcoin
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714097713
Hero Member
*
Offline Offline

Posts: 1714097713

View Profile Personal Message (Offline)

Ignore
1714097713
Reply with quote  #2

1714097713
Report to moderator
1714097713
Hero Member
*
Offline Offline

Posts: 1714097713

View Profile Personal Message (Offline)

Ignore
1714097713
Reply with quote  #2

1714097713
Report to moderator
1714097713
Hero Member
*
Offline Offline

Posts: 1714097713

View Profile Personal Message (Offline)

Ignore
1714097713
Reply with quote  #2

1714097713
Report to moderator
ranochigo
Legendary
*
Offline Offline

Activity: 2954
Merit: 4165


View Profile
June 13, 2021, 09:17:38 AM
 #2

1) if I set "subtractfeefromamount" to false, fee deducted from where? and How is fee calculated?
From the amount being specified. The command accepts a floating fee with the confirmation target parameter or your own set fees. That is true for 0.21.0. Anything earlier than that doesn't expect a txfee being specified in the command itself, only the confirmation target.

2) for example , if i have 2 bitcoin in my wallet, and the user withdraws one bitcoin, the rest coin (one bitcoin - fee) how calculated (utxo) ?
If you set subtract fee from amount, the amount sent to the user is 1BTC - fees. Otherwise, it maintains the 1BTC as the amount and subtracts the fees from your other outputs/change instead.

3) consider the above example, I want the rest coin return to the new address (different from the source address (HD wallet)), Is there a way?
Not with sendtoaddress, AFAIK. You can make your own rawtx for the purpose.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
ayza_aa (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 1


View Profile
June 13, 2021, 09:47:28 AM
 #3

3) consider the above example, I want the rest coin return to the new address (different from the source address (HD wallet)), Is there a way?
Quote
Not with sendtoaddress, AFAIK. You can make your own rawtx for the purpose.
so with sendtoaddress method, utxo return to the source address or rest coin consume as a fee?
ranochigo
Legendary
*
Offline Offline

Activity: 2954
Merit: 4165


View Profile
June 13, 2021, 10:07:25 AM
 #4

so with sendtoaddress method, utxo return to the source address or rest coin consume as a fee?
UTXO doesn't get returned. Change is returned to a change address within your wallet.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
nc50lc
Legendary
*
Offline Offline

Activity: 2394
Merit: 5535


Self-proclaimed Genius


View Profile
June 13, 2021, 10:48:58 AM
 #5

1) if I set "subtractfeefromamount" to false, fee deducted from where? and How is fee calculated?

2) for example , if i have 2 bitcoin in my wallet, and the user withdraws one bitcoin, the rest coin (one bitcoin - fee) how calculated (utxo) ?
It's always "false" by default and the fee should be covered by the input,
if its value isn't enough, Bitcoin core will have to include your other inputs or select the one with the right value,
otherwise, it will return with an error: "Insufficient funds"

Quote from: ayza_aa
3) consider the above example, I want the rest coin return to the new address (different from the source address (HD wallet)), Is there a way?
Use sendmany (0.21.0/rpc/wallet/sendmany) instead of sendtoaddress and enable "subtractfeefromamount" for the "new address" to make sure that it wont generate a change address.
The tricky part is to set the correct amount up to the last satoshi, if it was set with lower amount, a change output will be added.

For example (RegTest):
Code:
sendmany "" "{\"bcrt1qk3hqnujdex64v045qdh7df28vywg5rwtdzj008\":1,\"2Mu9fzGjgnuvCrAJ1cuAu1vZGfDVzHZNHKU\":18.10239312}" 1 "comment" "[\"2Mu9fzGjgnuvCrAJ1cuAu1vZGfDVzHZNHKU\"]"
  • bcrt1qk3hqnujdex64v045qdh7df28vywg5rwtdzj008 - user's address that you'll pay.
  • 2Mu9fzGjgnuvCrAJ1cuAu1vZGfDVzHZNHKU - your "new address" from other wallet that will receive the rest of the balance.

The example wallet's balance is 19.10239312 RegTestBTC, so the values of the outputs are 1 and 18.10239312 respectively.
But the final sent amount to 2Mu9fzGjgnuvCrAJ1cuAu1vZGfDVzHZNHKU is only 18.10238080 RegTestBTC because it's set with subtractfeefromamount flag "true".

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!