Skip to content

Expected property "1" of type Satoshi, got Number 6999.999999999999 #1460

@idoor88

Description

@idoor88

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions