<p>I'm trying to send bitcoin with the <code>bitcoinjs-lib</code> library and I get the following error:</p>
<blockquote>
<p>TypeError: bitcoin.TransactionBuilder is not a constructor
at sendmoney (/Users/....../bitcoin.js:53:18)
at processTicksAndRejections (node:internal/process/task_queues:96:5)</p>
</blockquote>
<p>And my code:</p>
<pre><code>const sendmoney = async (amountSatoshis, fromAddress, privatekey, toAddress) =&gt; {
    const requestConfig = {
        method: 'GET',
        url: `https://blockchain.info/unspent?active=${fromAddress}`
    };

    try {
        const ECPair = ECPairFactory(ecc)
        let keyPair = ECPair.fromWIF(privatekey);

        const response = await axios(requestConfig);
        console.log(response.unspent_outputs)

        let tx = new bitcoin.TransactionBuilder();
        let txfeemin = 1000;

        let balance = 0;
        let inputCount = 0;

        response.data.unspent_outputs.forEach(uo =&gt; {
            tx.addInput(uo.tx_hash_big_endian, uo.tx_output_n);
            balance += uo.value;
            inputCount++;
        })


        var txfee = txfeemin;
        //Estimate transaction size in bytes
        var txSize = inputCount * 180 + 2 * 34 + 10 + inputCount;
        //Blockchain: Minimum fee is 1.5 satoshi / Byte
        if (txSize * 2 &gt; txfeemin){
            txfee = txSize * 2;
        }
        tx.addOutput(toAddress, amountSatoshis); //without fee
        //tx.addOutput(toAddress, amountSatoshis - txfee); // with fee
        for (var i = 0; i &lt; inputCount; i++) {
            tx.sign(i, keyPair);
        }
        var txHex = tx.build().toHex();

        let transactionConfig = {
            method: 'POST',
            url: 'https://blockchain.info/pushtx?cors=true',
            data: 'tx=' + txHex
        };

        try{
            const transaction = await axios(requestConfig);
            conasole.log('transaction', transaction)
        }
        catch(err){
            console.log(err)
        }


    }
    catch (err) {
        console.log(err);
        return err;
    }
}
</code></pre>

CC BY-SA 4.0
2023-01-11T16:51:27.950Z
Could You resolve the problem?
Maksim Zarenok
CC BY-SA 4.0
2023-12-22T05:03:25.327Z
it was removed in bitcoinjs v6.0.0 https://github.com/bitcoinjs/bitcoinjs-lib/blob/1f92ada3fda587c1c0a6aa93649afa04e8382b93/CHANGELOG.md?plain=1#L49 So use older version or migrate to Psbt() https://bitcoin.stackexchange.com/questions/92758/how-do-you-switch-your-bitcoinjs-integrationfrom-transactionbuilder-to-transacti
Donn Lee
<blockchain><bitcoind><bitcoin-cli><node.js>
bitcoin TransactionBuilder is not a constructor
Salvador
# bitcoin TransactionBuilder is not a constructor

(Asked by: username_0 on 2022-07-24)

I'm trying to send bitcoin with the bitcoinjs-lib library and I get the following error:

TypeError: bitcoin.TransactionBuilder is not a constructor
at sendmoney (/Users/....../bitcoin.js:53:18)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

And my code:
const sendmoney = async (amountSatoshis, fromAddress, privatekey, toAddress) => {
    const requestConfig = {
        method: 'GET',
        url: `https://blockchain.info/unspent?active=${fromAddress}`
    };

    try {
        const ECPair = ECPairFactory(ecc)
        let keyPair = ECPair.fromWIF(privatekey);

        const response = await axios(requestConfig);
        console.log(response.unspent_outputs)

        let tx = new bitcoin.TransactionBuilder();
        let txfeemin = 1000;

        let balance = 0;
        let inputCount = 0;

        response.data.unspent_outputs.forEach(uo => {
            tx.addInput(uo.tx_hash_big_endian, uo.tx_output_n);
            balance += uo.value;
            inputCount++;
        })


        var txfee = txfeemin;
        //Estimate transaction size in bytes
        var txSize = inputCount * 180 + 2 * 34 + 10 + inputCount;
        //Blockchain: Minimum fee is 1.5 satoshi / Byte
        if (txSize * 2 > txfeemin){
            txfee = txSize * 2;
        }
        tx.addOutput(toAddress, amountSatoshis); //without fee
        //tx.addOutput(toAddress, amountSatoshis - txfee); // with fee
        for (var i = 0; i < inputCount; i++) {
            tx.sign(i, keyPair);
        }
        var txHex = tx.build().toHex();

        let transactionConfig = {
            method: 'POST',
            url: 'https://blockchain.info/pushtx?cors=true',
            data: 'tx=' + txHex
        };

        try{
            const transaction = await axios(requestConfig);
            conasole.log('transaction', transaction)
        }
        catch(err){
            console.log(err)
        }


    }
    catch (err) {
        console.log(err);
        return err;
    }
}

**Tags:** blockchain, bitcoind, bitcoin-cli, node.js

> **Comments:**
> **username_1**: Could You resolve the problem?  
> **username_2**: it was removed in bitcoinjs v6.0.0 https://github.com/bitcoinjs/bitcoinjs-lib/blob/1f92ada3fda587c1c0a6aa93649afa04e8382b93/CHANGELOG.md?plain=1#L49 So use older version or migrate to Psbt() https://bitcoin.stackexchange.com/questions/92758/how-do-you-switch-your-bitcoinjs-integrationfrom-transactionbuilder-to-transacti  

---

## 0 answers

