0

Today I created my very first transaction of bitcoin on the testnet programmatically. I created a wallet A, first generated my private key and I generated a deposit address. I deposited 0.00074 btc into it and waited till 6 confirmations so I can send bitcoin to somebody else. I decided to send 0.0000646 BTC to different address B and the transaction was successful however I noticed the transaction fee was 0.0006754 BTC so literally the rest of the balance from wallet A was used as a fee. I found this in the documentation of the api I am using apidocs "When the amount of funds that the recipient should receive is lower than the amount of funds from the UTXOs, the difference is used as a transaction fee."
Does that mean that for example if I deposit 1BTC to a specific address, if I want to send a certain amount of btc thats significantly smaller lets say 0.1 btc, 0.9btc will be used as a fee?? Then what If I want to send only a certain amount of money and dont want to pay such a massive fee do I have to create a completely new deposit address each time I want to send bitcoin and top it up only with the amount I want to send + fee? There must be a way to send small amounts I sent a small amounts from exchanges but did not see what logic is behind, could somebody please explain and give me some example?

Murch
  • 75,206
  • 34
  • 186
  • 622
Vladimir
  • 109
  • 3

1 Answers1

1

You should send some money back to yourself as change. Normally wallets do this automatically for you. Wallets normally generate a new change address for each transaction.

So if A has a UTXO of 1 BTC and wants to send 0.1 BTC to B with a fee of 0.001BTC the transaction would be

  • Inputs
    • 1 BTC (from A)
  • Outputs
    • 0.1 BTC to B
    • 0.899 BTC to A

This leaves 0.001 BTC unaccounted for which is the transaction fee to be claimed by a miner.

RedGrittyBrick
  • 26,841
  • 3
  • 25
  • 51
  • wow so simple and so smart at the same time I was not even thinking about sending the rest to myself back, would you recommend sending it back to the same address or generate a new one? Thanks @RedGrittyBrick – Vladimir Mar 30 '22 at 16:30
  • 1
    I would generate a new address. It improves privacy. – RedGrittyBrick Mar 30 '22 at 17:57