The Cryptonomics™
  • Home
  • Blockchain
  • Bitcoin
  • Ethereum
  • NFTS
  • Altcoin
  • Mining
  • Consulting
Reading: script – Sending Bitcoin: Anticipated property “signature” of sort Buffer, received Uint8Array
Share
Please enter CoinGecko Free Api Key to get this plugin works.
The Cryptonomics™The Cryptonomics™
Font ResizerAa
Search
  • Home
  • Blockchain
  • Bitcoin
  • Ethereum
  • NFTS
  • Altcoin
  • Mining
  • Consulting
Follow US
  • About Us
  • Advertising Solutions
  • Privacy
  • Terms
  • Advertise
Copyright © MetaMedia™ Capital Inc, All right reserved
The Cryptonomics™ > Bitcoin > script – Sending Bitcoin: Anticipated property “signature” of sort Buffer, received Uint8Array
Bitcoin

script – Sending Bitcoin: Anticipated property “signature” of sort Buffer, received Uint8Array

admin
Last updated: December 25, 2024 2:37 pm
admin Published December 25, 2024
Share
script – Sending Bitcoin: Anticipated property “signature” of sort Buffer, received Uint8Array


I’m attempting to ship the bitcoin with my personal key utilizing the script and the bitcoinjs-lib. I’m consistently getting the error Anticipated property "signature" of sort Buffer, received Uint8Array over the road after I name pstb.signInput().

I’m not in a position to determine the best way 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 operate sendBitcoin() {
    strive {
        // Import personal key
        const keyPair = ECPair.fromWIF(PRIVATE_KEY_WIF, NETWORK);

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

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

        if (!Array.isArray(utxos) || utxos.size === 0) {
            throw new Error("No UTXOs out there for the given tackle.");
        }

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

        let totalInput = 0;

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

        // Calculate the quantity to ship
        const sendAmount = 5000;
        if (sendAmount <= 0) {
            throw new Error("Inadequate funds after deducting charges.");
        }

        // Add output for vacation spot
        psbt.addOutput({
            tackle: DESTINATION_ADDRESS,
            worth: sendAmount,
        });

        // Add change output if relevant
        const change = totalInput - sendAmount - FEE;
        if (change > 0) {
            const changeAddress = bitcoin.funds.p2wpkh({
                pubkey: Buffer.from(keyPair.publicKey),
                community: NETWORK,
            }).tackle;
            console.log(`Including change output: ${changeAddress}`);
            psbt.addOutput({
                tackle: changeAddress,
                worth: change,
            });
        }

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

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

        psbt.finalizeAllInputs();

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

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

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

sendBitcoin();

If required, the under is the package deal model record:

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



Supply hyperlink

You Might Also Like

Snoop Dogg Drops NFT Presents on Telegram

Bitcoin Turns up the Warmth: Problem Jumps Almost 8% as Payouts Dip

BlockFi Chapter Administrator and DOJ Settle $35M Crypto Lawsuit

AIOZ is accessible for buying and selling!

Ethereum Reclaims NFT Market Dominance – Rises +30% In Gross sales

Share This Article
Facebook Twitter Email Copy Link Print
Previous Article BlackRock’s Bitcoin ETF sees document outflow as funds bleed .5B in 4 days BlackRock’s Bitcoin ETF sees document outflow as funds bleed $1.5B in 4 days
Next Article Reversing the gender hole: Girls who kicked ass in crypto in 2024 Reversing the gender hole: Girls who kicked ass in crypto in 2024
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Subscribe to our newslettern

Get Newest Articles Instantly!

- Advertisement -
Ad imageAd image
Popular News
Schiff Says Ditch BTC For Silver
Schiff Says Ditch BTC For Silver
The journey to a mature asset administration system
The journey to a mature asset administration system
High 3 Meme Coin Gems Price Shopping for Earlier than Could 2024 – PEPE, WIF, and DOGEVERSE
High 3 Meme Coin Gems Price Shopping for Earlier than Could 2024 – PEPE, WIF, and DOGEVERSE

Follow Us on Socials

We use social media to react to breaking news, update supporters and share information

Facebook Instagram Linkedin Pinterest Tiktok Twitter Youtube
The Cryptonomics™

Cryptonomics Magazine is your premier digital source for blockchain insights, offering cutting-edge research, news, interviews, and ICO updates for everyone from entrepreneurs to institutions. We drive blockchain knowledge and growth.

Subscribe to our newsletter

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

Schiff Says Ditch BTC For Silver
July 13, 2025
XRP Worth Flashes Power — Bulls In search of Continuation
July 13, 2025
Schiff Says Ditch BTC For Silver
July 13, 2025
Snoop Dogg Drops NFT Presents on Telegram
July 13, 2025
Chinese language trade group warns Web3 and DeFi high-return offers disguise basic Ponzi engines
July 12, 2025
Copyright © The Cryptonomics™ , All right reserved
  • About Us
  • Advertising Solutions
  • Privacy
  • Terms
  • Advertise
Join Us!

Subscribe & Stay Ahead of the Curve with Cryptonomics !

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?