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

Darma System Indicator (beta) MT4 Indicator

June 17, 2025

The New 15 Minutes: How the Creator Economy Is Speedrunning Fame (and Failure)

June 17, 2025

Earn more with Bonded Earn: Now live in the Kraken app and on Kraken web

June 17, 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»signature – Error: Cannot sign for this input with the key in BitcoinJS transaction
signature – Error: Cannot sign for this input with the key in BitcoinJS transaction
Bitcoin

signature – Error: Cannot sign for this input with the key in BitcoinJS transaction

adminBy adminJuly 9, 2024No Comments1 Min Read
Share
Facebook Twitter LinkedIn Pinterest Email


I’m trying to create and sign a Bitcoin transaction using BitcoinJS on the testnet. However, I’m encountering an error when trying to sign the transaction:

Error: Can not sign for this input with the key 03ac517991619c9413d3f886f62feb41eea6c571c7ab3e3f61ef770f63667dd94f

Below is my code:

import * as bitcoin from "bitcoinjs-lib";
import ECPairFactory from 'ecpair';
import ecc from '@bitcoinerlab/secp256k1';

bitcoin.initEccLib(ecc)
const ECPair = ECPairFactory(ecc);


const network = bitcoin.networks.testnet

async function createTransaction(
    privateKeyWIF: string,
    previousTxid: string,
    receiverAddress: string,
    previousHex: string
) {

    const keyPair = ECPair.fromWIF(privateKeyWIF, network);


    const txb = new bitcoin.Psbt({ network });

    txb.setVersion(2);
    txb.setLocktime(0);

    txb.addInput({
        hash: previousTxid,
        index: 0,
        nonWitnessUtxo: Buffer.from(previousHex, 'hex'),
    });

    txb.addOutput({
        script: Buffer.from(receiverAddress, 'hex'),
        value: 200,
    }); // Sending 0.000002 BTC


    txb.signInput(0, keyPair);
    txb.finalizeAllInputs();

    const tx = txb.extractTransaction();
    return tx.toHex();
}


const main = () => {
    const privateKeyWIF = "..." // my WIF private from UniSat wallet
    const previousTxid = '1e1f8daf5b1c520dbe251e4919d84e105f1a9ac3446e563998e0fca8871c250c'
    const receiver="tb1pfjvvn8x9fy5c5ppzrq729tyhu04pneyumukvmnqw78vwugpyatgq5yvxlw"
    const previosHex = '02000000000101804daa67aaf86c2fb8bb4ec428a2c8bbba1bd8f5e339fc3fb4d833b4322d25050200000000fdffffff092413000000000000225120d8c1604c1fac7bee40557fa76ba914c53136884e53f773440ec07d6415582639401f000000000000160014fdeb0cc3ea41a5ea4d5091081f6ba0af45528de0e80300000000000022512093024cb7d0600390806e993501c0bd1e9d200294a78e8daa79216e85833c45b8e803000000000000160014f0ee163efef8683a698c4646daf43ab71f0ff86c8895842700000000225120e30c3aa0f4b649b92e5e870f25d5c550a5df9f2fa4212ab9855c90c1ef90443cb036000000000000160014d5067f147f863ba8e152e54153c54a395a5baf3ed0070000000000002251204c41cc5cb6714b5b56d98032fa2cae97dfe9cd0da0b8c9b27c1bd1458148cd13a00f000000000000160014e583eec876ac45747804ed04b02fd4d4cd07f49c2413000000000000160014e22059700d76c7b564c9b8d4996d24c0adffaffa01406aab69d3bfdf2877ed12a8ea4f0aae67e4d17df782f827c750e5299a09e171ccea960b6e8ac94916f2083d03321e672ceff4dd6ed33833ef4e1b9662bfa3044b26bf2b00'

    createTransaction(privateKeyWIF, previousTxid, receiver, previosHex)
        .then((transactionHex) => {
            console.log('Transaction Hex:', transactionHex);
        })
        .catch((error) => {
            console.error('Error:', error.message);
        });
}

main()



Source link

BitcoinJS Error input Key sign signature transaction
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
admin
  • Website

Related Posts

Bitcoin Layer 2: Statechains

June 15, 2025

ETH Whales and Sharks Add 1.49M in 30 Days, Now Hold 27% of Total Ether Supply

June 14, 2025

Keeping our platform safe: How we protect against fraud and criminal activity

June 13, 2025

Bitfinex Alpha | BTC at a Crossroads

June 12, 2025
Add A Comment
Leave A Reply Cancel Reply

Top Insights

Darma System Indicator (beta) MT4 Indicator

June 17, 2025

The New 15 Minutes: How the Creator Economy Is Speedrunning Fame (and Failure)

June 17, 2025

Earn more with Bonded Earn: Now live in the Kraken app and on Kraken web

June 17, 2025

5 Common Trading Biases You Might Be Unaware Of

June 16, 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

Darma System Indicator (beta) MT4 Indicator

June 17, 2025

The New 15 Minutes: How the Creator Economy Is Speedrunning Fame (and Failure)

June 17, 2025

Earn more with Bonded Earn: Now live in the Kraken app and on Kraken web

June 17, 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.