How to get minimum fee for a transaction using bitcore-lib (NodeJs)?

1.8k views Asked by At

I'm doing a transaction of BTC using bitcore-lib nodejs package. when I set 1 satoshi fee per byte it shows an error like "Fee is too small: expected more than x but got y". Is there any way to get that x value to set fee?

let tx = bitcore.Transaction();

tx.from(utxos);
tx.to(toAddress,sendAmountInSatoshi);
tx.change(fromAddress);
tx.fee(fee);
tx.sign(pKey);
2

There are 2 answers

0
Parikshit Sharma On

If you are using the bitcoin testnet make sure to include the minimum amount of fees which is 3000 satoshis.

You can set the fees as low as you want in the livenet, but the testnet require this as the minimum amount so as to ensure people continue mining on the testnet to help the developer community.

Cheers!

0
Kristopher Ives On

While I'm not sure if it's part of the API specification you can use their _estimateFee() method:

https://github.com/bitpay/bitcore-lib/blob/86583608814dfc513e675d7b853806caf9bd95e7/lib/transaction/transaction.js#L242