<p>The miner fee will, by default, equal the inputs - outputs of your transaction.<br /><br />
I notice some problems with your code. You do not specify a change address to send the left-over amount. If I have an unspent output of <code>100</code> BTC and I want to send <code>10</code> BTC to someone else, I should have 1 input (the unspent output from the previous transaction) and 2 outputs (the receiver address and the change address). The inputs and outputs will look like this:</p>

<p><strong>Inputs</strong></p>

<ul>
<li>Unspent output of <code>100</code> BTC</li>
</ul>

<p><strong>Outputs</strong></p>

<ul>
<li>Receiver address with <code>10</code> BTC</li>
<li>Change address (your BTC address) with <code>89.999</code> BTC</li>
</ul>

<p>The fee will be <code>0.001</code> BTC since <code>(in)(100) - (out)(10 + 89.999) = 0.001</code>.<br /><br />
Hope I was able to help.</p>

CC BY-SA 3.0
2017-12-11T00:07:16.487Z
2017-12-11T01:19:21.413Z
2017-12-11T01:19:21.413Z
Monstrum
<p>I'm trying to send testnet with bitcoinjs, but when I go to broadcast the hex, it gives me an error code that says "fee is too high: 12372928". Now, from my understanding, the fee is the input - output. However, even if I increase the output to match the wallet's balance, I get the same exact error message. Here's my code: </p>

<pre><code>        this.setState({
            address: 'mphWVWbPgGKuaMpSpGNA3Ffrpva5cRChqP',
            privateKey: 'cW6dLEqkk2HAbQTSJaHnn4w3kd2iJfhBREccEE3vzrq8kcVE5TqS',
        });      
}

createTransaction = (e) =&gt; {
    e.preventDefault()
    const {address, privateKey} = this.state;
    var hashURL = `https://api.blockcypher.com/v1/btc/test3/addrs/${address}`


        axios.get(hashURL).then((response) =&gt; {
            this.setState({
                hash: response.data.txrefs[0].tx_hash
            })
        }).then((result) =&gt; {

        var tx = new bitcoin.TransactionBuilder(testnet);

        var txId = this.state.hash;

        console.log(txId);

        tx.addInput(txId, 0)

        tx.addOutput(this.state.add, 1000000)

        var keyPair2 = bitcoin.ECPair.fromWIF(privateKey, testnet);

        tx.sign(0, keyPair2);
        console.log(tx.build().toHex());
        }
    )

}
</code></pre>

<p>Would there be a way to manually set the fee to always be something like .0001?</p>

<transactions><transaction-fees><bitcoinjs>
Having issues broadcasting BitcoinJS transaction.
Setheroni
# Having issues broadcasting BitcoinJS transaction.

(Asked by: username_0 on 2017-12-10)

I'm trying to send testnet with bitcoinjs, but when I go to broadcast the hex, it gives me an error code that says "fee is too high: 12372928". Now, from my understanding, the fee is the input - output. However, even if I increase the output to match the wallet's balance, I get the same exact error message. Here's my code: 
        this.setState({
            address: 'mphWVWbPgGKuaMpSpGNA3Ffrpva5cRChqP',
            privateKey: 'cW6dLEqkk2HAbQTSJaHnn4w3kd2iJfhBREccEE3vzrq8kcVE5TqS',
        });      
}

createTransaction = (e) => {
    e.preventDefault()
    const {address, privateKey} = this.state;
    var hashURL = `https://api.blockcypher.com/v1/btc/test3/addrs/${address}`


        axios.get(hashURL).then((response) => {
            this.setState({
                hash: response.data.txrefs[0].tx_hash
            })
        }).then((result) => {

        var tx = new bitcoin.TransactionBuilder(testnet);

        var txId = this.state.hash;

        console.log(txId);

        tx.addInput(txId, 0)

        tx.addOutput(this.state.add, 1000000)

        var keyPair2 = bitcoin.ECPair.fromWIF(privateKey, testnet);

        tx.sign(0, keyPair2);
        console.log(tx.build().toHex());
        }
    )

}

Would there be a way to manually set the fee to always be something like .0001?

**Tags:** transactions, transaction-fees, bitcoinjs


---

## 1 answers

### Answer by username_1 on 2017-12-11. Score: 0 | Accepted answer

The miner fee will, by default, equal the inputs - outputs of your transaction.  
  
I notice some problems with your code. You do not specify a change address to send the left-over amount. If I have an unspent output of `100` BTC and I want to send `10` BTC to someone else, I should have 1 input (the unspent output from the previous transaction) and 2 outputs (the receiver address and the change address). The inputs and outputs will look like this:

**Inputs**

* Unspent output of `100` BTC

**Outputs**

* Receiver address with `10` BTC
* Change address (your BTC address) with `89.999` BTC

The fee will be `0.001` BTC since `(in)(100) - (out)(10 + 89.999) = 0.001`.  
  
Hope I was able to help.


---

