-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
Hi all, I am trying to use the following code to send BTC transaction, the toAmount is 0.00007 of BTC, since my total amount is 0.00027 btc, I leave 0.0002 as mining fee, but I got error message:
Expected property "1" of type Satoshi, got Number 6999.999999999999
when the code is executing the line of:
txb.addOutput(toAddress, amount);
the amount is toAmount * precision, which is 0.00007 * 100000000 = 7000, which equals 6999.999999999999, but why I got this error? it is because I have too little of BTC balance?
`
let precision = 1e8;
............
const txb = new bitcoin.TransactionBuilder();
let resultData = await fetchUnspentList(fromAddress);
if(resultData && resultData.status == 200){
const unspentList = resultData.data;
// calculate total unspentList
const totalUnspent = unspentList.reduce(
(a, b) => a + b.satoshis,
0,
);
// add tx input
unspentList.forEach(({ txid, vout }) => txb.addInput(txid, vout));
let changeValue = 0;
if (btcTx) {
//btc transaction
const amount = toAmount * precision;
txb.addOutput(toAddress, amount);
// calculate fee value
feeValue = calculateTxFee(txb, fromAddress, fromPrivateKey, feeRate);
changeValue = totalUnspent - feeValue - amount;
feeValue = feeValue + amount;
}
............`
Metadata
Metadata
Assignees
Labels
No labels