I'm currently playing with bitcoinjs (https://bitcoinjs.org/) and I'm creating offline transactions that I broadcast over the network after.

I've successfully create my first transaction using this : https://medium.com/@orweinberger/how-to-create-a-raw-transaction-using-bitcoinjs-lib-1347a502a3a

But it seems my transaction is stuck since I haven't put enough fee on it to get it mined.

How using a var tx = new bitcoin.TransactionBuilder(); can I set the fee to a certain amount ? Is this calculated using a default value ?

Thank you for your help !


The fee is the sum of unspent value in a Transaction.

Aka the value NOT SENT by your outputs.

fee = in - out

For an example, if we assume the input aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31, 0 has an unspent value of 15000...

var txb = new bitcoin.TransactionBuilder()
txb.addInput('aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31', 0)
txb.addOutput('1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK', 15000)

When we send 15000 to 1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK, the fee is the value of the inputs minus the value of outputs.

in:15000 - out:15000 = fee:0

For a fee to be non-zero, in > out is required.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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