<p>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.</p>

CC BY-SA 4.0
2022-04-04T06:58:09.143Z
Thanks a lot! I read docs about change, now I knew how to save BTCs.
Junfei Ouyang
CC BY-SA 4.0
2022-04-03T04:52:31.623Z
2022-04-03T04:52:31.623Z
Ava Chow
<p>Recently, I'm trying coding with Bitcoin like creating raw transaction and filling with some data finally send the raw transcation.</p>
<p>There is a question I don't know how to deal with.</p>
<p>With my own <em>Golang</em> 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 <a href="https://mempool.space/testnet/tx/1abf1810e95d4fa7dfe178ad1fb874f1ad325de805777d3d5867af3be09b4aba" rel="nofollow noreferrer">tx1</a>
and <a href="https://mempool.space/testnet/tx/83a7a225a5ddead0ca82c8aec35ce353f4c337fb268cb8542a1ffa3236b27186" rel="nofollow noreferrer">tx2</a>.</p>
<p>Is there some kind of optimization to create transcations?</p>

<transaction-fees>
Why is the average transaction fee so high created by my own written code?
Junfei Ouyang
# Why is the average transaction fee so high created by my own written code?

(Asked by: username_0 on 2022-04-03)

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](https://mempool.space/testnet/tx/1abf1810e95d4fa7dfe178ad1fb874f1ad325de805777d3d5867af3be09b4aba)
and [tx2](https://mempool.space/testnet/tx/83a7a225a5ddead0ca82c8aec35ce353f4c337fb268cb8542a1ffa3236b27186).

Is there some kind of optimization to create transcations?

**Tags:** transaction-fees


---

## 1 answers

### Answer by username_1 on 2022-04-03. Score: 6 | Accepted answer

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.

> **Comments:**
> **username_0**: Thanks a lot! I read docs about change, now I knew how to save BTCs.  

---

