Bitcoin Forum
September 23, 2021, 09:25:31 PM *
News: Latest Bitcoin Core release: 22.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: details for bitcoin core sendtoaddress method  (Read 54 times)
ayza_aa
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?
1632432331
Hero Member
*
Offline Offline

Posts: 1632432331

View Profile Personal Message (Offline)

Ignore
1632432331
Reply with quote  #2

1632432331
Report to moderator
1632432331
Hero Member
*
Offline Offline

Posts: 1632432331

View Profile Personal Message (Offline)

Ignore
1632432331
Reply with quote  #2

1632432331
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1632432331
Hero Member
*
Offline Offline

Posts: 1632432331

View Profile Personal Message (Offline)

Ignore
1632432331
Reply with quote  #2

1632432331
Report to moderator
ranochigo
Legendary
*
Offline Offline

Activity: 2478
Merit: 2652

@ me if you need my response


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.

ayza_aa
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: 2478
Merit: 2652

@ me if you need my response


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.

nc50lc
Legendary
*
Offline Offline

Activity: 1456
Merit: 2221


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".

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!