Get error "Can not sign for this input with the key" when migrating from TransactionBuilder to Psbt
See original GitHub issueError: Can not sign for this input with the key
I got this error when tried to create a raw transaction with testnet, p2pkh address. Everything works fine if I use TransactionBuilder, except the warning message told me should use Psbt. When using signInput method, my pubkey seems not to match with utxo input.
This is my getPrivateKey function from mnemonic string, works fine with TransactionBuilder
const seed = bip39.mnemonicToSeedSync(mnemonic);
const root = bip32.fromSeed(seed, list_networks['test']);
const child = root
.deriveHardened(44)
.deriveHardened(coin_type['test'].index)
.deriveHardened(0)
.derive(0)
.derive(index = 0);
return bitcoin.ECPair.fromPrivateKey(child.privateKey, { network: list_networks['test'] });
And this is my new createRawTransaction
// Get Private Key From Mnemonic Word Lists
const key = getPrivateKey(mnemonic);
// Create Psbt Instance
const psbt = new bitcoin.Psbt({ network: list_networks['test'] });
// Add Unspent transaction outputs
utxos.forEach(utxo => {
// this object is from getrawtransaction bitcoin-cli
psbt.addInput({
hash: utox.hash,
index: utox.index,
nonWitnessUtxo: Buffer.from(utox.hex, 'hex'),
})
});
// Add Output To Destination address
psbt.addOutput({
address: destination,
value: amount,
});
// Sign utxos Input
for (let i = 0; i < utxos.length; i++) {
psbt.signInput(i, key); // worked with TransactionBuilder.sign
}
What’s missing? Shoud I stay with TransactionBuilder?
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Support Request: Need help migrating from old Txb to Psbt ...
There shouldn't really be a use case for importing a completed raw transaction into PSBT, since you can't sign a completed transaction.
Read more >Cannot sign txn with change address using bitcoinjs-lib psbt
I get Error: cannot sign for this input with the key <value> . The initial transaction works fine, where I generate a transaction...
Read more >how do you create a new PSBT transaction in bitcoinjs-lib?
but I'm getting error: Can not sign for this input with the key 02c4ac... I've made sure that when I decode the tx...
Read more >bitcoinjs-lib | Yarn - Package Manager
It is now fixed. 5.1.5 ... Psbt now has getFee(): number for use when all inputs are finalized. It returns the satoshi fee...
Read more >How to use the bitcoinjs-lib.TransactionBuilder function in ...
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I found out what I been missing. I passed a wrong utxo input index value. Sorry for wasting your time at the weekend. But I knew you’d show up as usual to help wandering people like me.
I did a quick check, the private key is fine with
TransactionBuilder