• Home
  • About Us
  • disclaimer
  • Privacy Policy
  • Terms and Conditions
  • Contact Us
Crypto News
  • Home
  • Crypto News
  • Team Portofolio (Premium)
  • Member Login
No Result
View All Result
  • Home
  • Crypto News
  • Team Portofolio (Premium)
  • Member Login
No Result
View All Result
Crypto News
No Result
View All Result
Home Crypto News

script – Sending Bitcoin: Anticipated property “signature” of kind Buffer, obtained Uint8Array

Cryptoadmin by Cryptoadmin
December 25, 2024
in Crypto News
0
segregated witness – Is there some extent to utilizing taproot transactions over P2WSH if I solely wish to use the script path?
189
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


I’m making an attempt to ship the bitcoin with my personal key utilizing the script and the bitcoinjs-lib. I’m continually getting the error Anticipated property "signature" of kind Buffer, obtained Uint8Array over the road after I name pstb.signInput().

I’m not ready to determine easy methods 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 perform sendBitcoin() {
    strive {
        // Import personal key
        const keyPair = ECPair.fromWIF(PRIVATE_KEY_WIF, NETWORK);

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

        // Fetch UTXOs for the handle
        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 handle.");
        }

        // 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.handle.toOutputScript(handle, 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({
            handle: 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,
            }).handle;
            console.log(`Including change output: ${changeAddress}`);
            psbt.addOutput({
                handle: 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.put up('https://blockstream.information/api/tx', rawTransaction);
        console.log(`Transaction efficiently broadcasted. TXID: ${broadcastResponse.knowledge}`);
    } catch (error) {
        console.error(`Error: ${error.stack}`);
    }
}

sendBitcoin();

If required, the beneath is the package deal model checklist:

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

Tags: BitcoinBufferexpectedpropertyscriptSendingsignaturetypeUint8Array
Share76Tweet47
  • Trending
  • Comments
  • Latest
USDG Rewards: Earn as much as 4%+ APR in USDG on Kraken

USDG Rewards: Earn as much as 4%+ APR in USDG on Kraken

April 10, 2025
How Essential is Jito Solana MEV Bot Growth for the Cryptocurrency Ecosystem?

How Essential is Jito Solana MEV Bot Growth for the Cryptocurrency Ecosystem?

July 31, 2024
PURA Cost Processing | CoinPayments

PURA Cost Processing | CoinPayments

May 13, 2024
SUI staking is now dwell on Kraken – earn as much as 3%

SUI staking is now dwell on Kraken – earn as much as 3%

July 7, 2025
Ethiopia to begin mining Bitcoin by means of new information mining partnership

Ethiopia to begin mining Bitcoin by means of new information mining partnership

0
Be part of HitBTC official social media channels !

Be part of HitBTC official social media channels !

0
Bitwise launching spot bitcoin ETF (BITB) – CryptoNinjas

Bitwise launching spot bitcoin ETF (BITB) – CryptoNinjas

0
DeFi Masterclass. Decentralized Finance (DeFi) is an… | by Rohas Nagpal | Blockchain Weblog

DeFi Masterclass. Decentralized Finance (DeFi) is an… | by Rohas Nagpal | Blockchain Weblog

0
Solana Worth Up 1% As 21Shares Recordsdata SOL ETF, Cboe Approves It

Solana Worth Up 1% As 21Shares Recordsdata SOL ETF, Cboe Approves It

November 20, 2025
Retail Buyers in Singapore Embrace Crypto as 61% Report Holding Digital Belongings: Coinbase

Retail Buyers in Singapore Embrace Crypto as 61% Report Holding Digital Belongings: Coinbase

November 20, 2025
Datagram Airdrop Information | Step-by-step Information

Datagram Airdrop Information | Step-by-step Information

November 20, 2025
Evaluating Greatest Pockets Token and Digitap as Their 2025 Presales Progress

Evaluating Greatest Pockets Token and Digitap as Their 2025 Presales Progress

November 19, 2025

About Us

Welcome to Blog.cryptostudy.net The goal of Blog.cryptostudy.net is to give you the absolute best news sources for any topic! Our topics are carefully curated and constantly updated as we know the web moves fast so we try to as well.

Recent Posts

  • Solana Worth Up 1% As 21Shares Recordsdata SOL ETF, Cboe Approves It
  • Retail Buyers in Singapore Embrace Crypto as 61% Report Holding Digital Belongings: Coinbase
  • Datagram Airdrop Information | Step-by-step Information
  • Home
  • About Us
  • disclaimer
  • Privacy Policy
  • Terms and Conditions
  • Contact Us

Copyright © 2024 Blog.cryptostudy.net | All Rights Reserved.

No Result
View All Result
  • Home
  • Crypto News
  • Team Portofolio (Premium)
  • Member Login

Copyright © 2024 Blog.cryptostudy.net | All Rights Reserved.