Title: details for bitcoin core sendtoaddress method Post by: ayza_aa on June 13, 2021, 08:48:46 AM 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? Title: Re: details for bitcoin core sendtoaddress method Post by: ranochigo on June 13, 2021, 09:17:38 AM 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.Title: Re: details for bitcoin core sendtoaddress method Post by: ayza_aa on June 13, 2021, 09:47:28 AM 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?Title: Re: details for bitcoin core sendtoaddress method Post by: ranochigo on June 13, 2021, 10:07:25 AM 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. Title: Re: details for bitcoin core sendtoaddress method Post by: nc50lc on June 13, 2021, 10:48:58 AM 1) if I set "subtractfeefromamount" to false, fee deducted from where? and How is fee calculated? It's always "false" by default and the fee should be covered by the input, 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 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 (https://bitcoincore.org/en/doc/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\"]"
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". |