Author

Topic: details for bitcoin core sendtoaddress method (Read 78 times)

legendary
Activity: 2394
Merit: 5531
Self-proclaimed Genius
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".
legendary
Activity: 2954
Merit: 4158
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.
newbie
Activity: 9
Merit: 1
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?
legendary
Activity: 2954
Merit: 4158
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.
newbie
Activity: 9
Merit: 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?
Jump to: