• About
  • FAQ
  • Earn Bitcoin while Surfing the net
  • Buy & Sell Crypto on Paxful
Newsletter
Approx Foundation
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
Approx Foundation
No Result
View All Result
Home Bitcoin

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

Moussa by Moussa
December 24, 2024
in Bitcoin
0
peer discovery – how to obtain the IP addresses of nodes for mining pools?
189
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


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"
  }
}



Source link

Related articles

Ethereum Price Climbs Gradually, Can Bulls Break $2,400 Barrier?

Ethereum Price Climbs Gradually, Can Bulls Break $2,400 Barrier?

April 27, 2026
TRM Labs Highligihts Rise of Stablecoins in Venezuela

TRM Labs Highligihts Rise of Stablecoins in Venezuela

April 27, 2026
Share76Tweet47

Related Posts

Ethereum Price Climbs Gradually, Can Bulls Break $2,400 Barrier?

Ethereum Price Climbs Gradually, Can Bulls Break $2,400 Barrier?

by Moussa
April 27, 2026
0

Ethereum price started a fresh increase and remained stable above $2,365. ETH is now consolidating and might aim for more...

TRM Labs Highligihts Rise of Stablecoins in Venezuela

TRM Labs Highligihts Rise of Stablecoins in Venezuela

by Moussa
April 27, 2026
0

Key Takeaways: TRM Labs reports a Q1 2026 shift to USDT, boosting Venezuela’s volume to $17.9B for future savings. Binance...

How do Bitcoin mining pools typically handle payout frequency versus thresholds?

lightning network – Need help with a .conf file to run a lighting node?

by Moussa
April 27, 2026
0

This is my configuration file and i followed all of the instructions for the program but it always gives me...

Bitcoin Derivatives Buying Pressure Continues To Rise — Is $80K Inevitable?

Bitcoin Derivatives Buying Pressure Continues To Rise — Is $80K Inevitable?

by Moussa
April 26, 2026
0

Trusted Editorial content, reviewed by leading industry experts and seasoned editors. Ad Disclosure The price of Bitcoin has been enjoying...

Bitcoin Price To Bottom At $45K? On-Chain Indicator Says Yes

Bitcoin Sees Renewed Demand From US Institutional Players — What’s Changing?

by Moussa
April 26, 2026
0

According to an on-chain analyst, Bitcoin has been witnessing a shift in investor behavior in one of its major markets,...

Load More

youssufi.com

sephina.com

[vc_row full_width="stretch_row" parallax="content-moving" vc_row_background="" background_repeat="no-repeat" background_position="center center" footer_scheme="dark" css=".vc_custom_1517813231908{padding-top: 60px !important;padding-bottom: 30px !important;background-color: #191818 !important;background-position: center;background-repeat: no-repeat !important;background-size: cover !important;}" footer_widget_title_color="#fcbf46" footer_button_bg="#fcb11e"][vc_column width="1/4"]

We bring you the latest in Crypto News

[/vc_column][vc_column width="1/4"][vc_wp_categories]
[/vc_column][vc_column width="1/4"][vc_wp_tagclo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bnAtZmllbGQlMjB0bnAtcHJpdmFjeS1maWVsZCUyMiUzRSUzQ2xhYmVsJTNFJTNDaW5wdXQlMjB0eXBlJTNEJTIyY2hlY2tib3glMjIlMjBuYW1lJTNEJTIybnklMjIlMjByZXF1aXJlZCUyMGNsYXNzJTNEJTIydG5wLXByaXZhY3klMjIlM0UlQzIlQTBCeSUyMGNvbnRpbnVpbmclMkMlMjB5b3UlMjBhY2NlcHQlMjB0aGUlMjBwcml2YWN5JTIwcG9saWN5JTNDJTJGbGFiZWwlM0UlM0MlMkZkaXYlM0UlM0NkaXYlMjBjbGFzcyUzRCUyMnRucC1maWVsZCUyMHRucC1maWVsZC1idXR0b24lMjIlM0UlM0NpbnB1dCUyMGNsYXNzJTNEJTIydG5wLXN1Ym1pdCUyMiUyMHR5cGUlM0QlMjJzdWJtaXQlMjIlMjB2YWx1ZSUzRCUyMlN1YnNjcmliZSUyMiUyMCUzRSUwQSUzQyUyRmRpdiUzRSUwQSUzQyUyRmZvcm0lM0UlMEElM0MlMkZkaXYlM0UlM0NiciUyRiUzRSUzQyUyRnAlM0U=[/vc_raw_html][/vc_column][/vc_row]
No Result
View All Result
  • Contact Us
  • Homepages
  • Business
  • Guide

© 2024 APPROX FOUNDATION - The Crypto Currency News