Recently, I'm trying coding with Bitcoin like creating raw transaction and filling with some data finally send the raw transcation.

There is a question I don't know how to deal with.

With my own Golang code to create and send raw transcations, the average transcation fee is so much higher than that of the transcation I create with Bitcoin core software. Refer to tx1 and tx2.

Is there some kind of optimization to create transcations?


1 Answer 1


It looks like you aren't adding a change output so you're just throwing away the change to transaction fees. The transaction fee is the difference between the sum of the output amounts, and the sum of the input amounts. Additionally, change does not automatically come back to you. When you spend a UTXO, you can't spend just a part of it, you must spend all of it, and send the remainder (minus however much for transaction fees) back to yourself in another output. If you forget to make a change output, then that change becomes part of the difference between the sum of the output amounts and the sum of the inputs amounts, and so it becomes part of the transaction fee.

  • Thanks a lot! I read docs about change, now I knew how to save BTCs. Apr 4, 2022 at 6:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.