Close Menu
  • Home
  • Altcoin
  • Bitcoin
  • Crypto
  • Forex
  • Online Money
What's Hot

Electrum wallet JSON – get WIFs or hex private keys

December 6, 2025

Nils Rooijmans speaks on when ignoring Google emails can cost you

December 6, 2025

Ready to Earn? Your Wirex Pay Node Rewards Are Here!

December 5, 2025
Facebook X (Twitter) Instagram
  • Altcoin
  • Bitcoin
  • Crypto
  • Forex
  • Online Money
Facebook X (Twitter) Instagram
Cointelegraphe
  • Home
  • Altcoin
  • Bitcoin
  • Crypto
  • Forex
  • Online Money
Cointelegraphe
Home»Bitcoin»script – Sending Bitcoin: Expected property “signature” of type Buffer, got Uint8Array
script – Sending Bitcoin: Expected property “signature” of type Buffer, got Uint8Array
Bitcoin

script – Sending Bitcoin: Expected property “signature” of type Buffer, got Uint8Array

adminBy adminDecember 26, 2024No Comments3 Mins Read
Share
Facebook Twitter LinkedIn Pinterest Email


I am trying to send the bitcoin with my private key using the script and the bitcoinjs-lib. I am constantly getting the error Expected property "signature" of type Buffer, got Uint8Array over the line when I call pstb.signInput().

I am not able to figure out how to resolve this,

const bitcoin = require('bitcoinjs-lib');
const ecc = require('tiny-secp256k1');
const ECPairFactory = require('ecpair').default;
const ECPair = ECPairFactory(ecc);
const { getUtxos } = require('./utxo');

const NETWORK = bitcoin.networks.bitcoin
const PRIVATE_KEY_WIF = "PRIVATE_KEY"; 
const DESTINATION_ADDRESS = "bc1q9es00454u6n49ullgg2cyh23prpglpees5ptyc"; 
const FEE = 1500; 

async function sendBitcoin() {
    try {
        // Import private key
        const keyPair = ECPair.fromWIF(PRIVATE_KEY_WIF, NETWORK);

        // Generate the address (Native SegWit - P2WPKH)
        const { address } = bitcoin.payments.p2wpkh({
            pubkey: Buffer.from(keyPair.publicKey),
            network: NETWORK,
        });
        console.log(`Sending from: ${address}`);

        // Fetch UTXOs for the address
        const utxos = await getUtxos();
        console.log(`Fetched UTXOs:`, utxos);

        if (!Array.isArray(utxos) || utxos.length === 0) {
            throw new Error("No UTXOs available for the given address.");
        }

        // Create a new PSBT
        const psbt = new bitcoin.Psbt({ network: NETWORK });
        console.log(`Initialized PSBT:`, psbt);

        let totalInput = 0;

        // Add inputs from UTXOs
        utxos.forEach((utxo) => {
            console.log(`Adding UTXO: ${JSON.stringify(utxo)}`);
            psbt.addInput({
                hash: utxo.txid,
                index: utxo.vout,
                witnessUtxo: {
                    script: Buffer.from(bitcoin.address.toOutputScript(address, NETWORK)),
                    value: utxo.value,
                },
            });
            totalInput += utxo.value;
        });

        // Calculate the amount to send
        const sendAmount = 5000;
        if (sendAmount <= 0) {
            throw new Error("Insufficient funds after deducting fees.");
        }

        // Add output for destination
        psbt.addOutput({
            address: DESTINATION_ADDRESS,
            value: sendAmount,
        });

        // Add change output if applicable
        const change = totalInput - sendAmount - FEE;
        if (change > 0) {
            const changeAddress = bitcoin.payments.p2wpkh({
                pubkey: Buffer.from(keyPair.publicKey),
                network: NETWORK,
            }).address;
            console.log(`Adding change output: ${changeAddress}`);
            psbt.addOutput({
                address: changeAddress,
                value: change,
            });
        }

        utxos.forEach((_, index) => {
            console.log(`Signing input at index: ${index}`);
            psbt.signInput(index, keyPair);
        });

        const isValid = psbt.validateSignaturesOfAllInputs();
        console.log(`Signatures valid: ${isValid}`);

        psbt.finalizeAllInputs();

        const rawTransaction = psbt.extractTransaction().toHex();
        console.log(`Raw Transaction: ${rawTransaction}`);

        console.log('Transaction ready to broadcast:', rawTransaction);

        const broadcastResponse = await axios.post('https://blockstream.info/api/tx', rawTransaction);
        console.log(`Transaction successfully broadcasted. TXID: ${broadcastResponse.data}`);
    } catch (error) {
        console.error(`Error: ${error.stack}`);
    }
}

sendBitcoin();

If required, the below is the package version list:

{
  "dependencies": {
    "@mempool/mempool.js": "^2.3.0",
    "axios": "^1.7.9",
    "bip32": "^5.0.0-rc.0",
    "bip39": "^3.1.0",
    "bitcoinjs-lib": "^6.1.7",
    "bs58": "^6.0.0",
    "ecpair": "^3.0.0-rc.0",
    "hdkey": "^2.1.0",
    "tiny-secp256k1": "^2.2.3"
  },
  "devDependencies": {
    "dotenv": "^16.4.7"
  }
}

Stack Trace Error:

Error: Error: Expected property "signature" of type Buffer, got Uint8Array
    at captureStackTrace (/home/self-cutodial-wallet/node_modules/typeforce/errors.js:20:11)
    at tfSubError (/home/self-cutodial-wallet/node_modules/typeforce/errors.js:99:3)
    at _object (/home/self-cutodial-wallet/node_modules/typeforce/index.js:117:15)
    at typeforce (/home/self-cutodial-wallet/node_modules/typeforce/index.js:233:9)
    at typeforce (/home/self-cutodial-wallet/node_modules/typeforce/index.js:239:10)
    at Object.encode (/home/self-cutodial-wallet/node_modules/bitcoinjs-lib/src/script_signature.js:63:3)
    at Psbt._signInput (/home/self-cutodial-wallet/node_modules/bitcoinjs-lib/src/psbt.js:679:38)
    at Psbt.signInput (/home/self-cutodial-wallet/node_modules/bitcoinjs-lib/src/psbt.js:648:17)
    at /home/self-cutodial-wallet/gg.js:82:18
    at Array.forEach ()
    ```



Source link

bitcoin Buffer expected property script Sending signature type Uint8Array
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
admin
  • Website

Related Posts

Electrum wallet JSON – get WIFs or hex private keys

December 6, 2025

Ready to Earn? Your Wirex Pay Node Rewards Are Here!

December 5, 2025

Can the Fusaka Upgrade Renew Ethereum’s Momentum After Recent Price Hit?

December 3, 2025

Vanguard Opens Its $11T Platform To Bitcoin And Crypto ETFs

December 2, 2025
Add A Comment
Leave A Reply Cancel Reply

Top Insights

Electrum wallet JSON – get WIFs or hex private keys

December 6, 2025

Nils Rooijmans speaks on when ignoring Google emails can cost you

December 6, 2025

Ready to Earn? Your Wirex Pay Node Rewards Are Here!

December 5, 2025

10 Trading Affirmations to Begin Every Trading Day » Learn To Trade The Market

December 5, 2025
ads

Subscribe to Updates

Get the latest creative news from Cointelegraphe about Crypto, bItcoin and Altcoin.

About Us
About Us

At CoinTelegraphe, we are dedicated to bringing you the latest and most insightful news, analysis, and updates from the dynamic world of cryptocurrency. Our mission is to provide our readers with accurate, timely, and comprehensive information to help them navigate the complexities of the crypto market.

Facebook X (Twitter) Instagram Pinterest YouTube
Top Insights

Electrum wallet JSON – get WIFs or hex private keys

December 6, 2025

Nils Rooijmans speaks on when ignoring Google emails can cost you

December 6, 2025

Ready to Earn? Your Wirex Pay Node Rewards Are Here!

December 5, 2025
Get Informed

Subscribe to Updates

Get the latest creative news from Cointelegraphe about Crypto, bItcoin and Altcoin.

Please enable JavaScript in your browser to complete this form.
Loading
  • About us
  • Contact Us
  • Shop
  • Privacy Policy
  • Terms and Conditions
Copyright 2024 Cointelegraphe Design By Horaam Sultan.

Type above and press Enter to search. Press Esc to cancel.