Comments (6)
Then the issue is using the wrong key.
Here's an example. It seems you are doing everything correctly. So the only thing that can be wrong is that you are using the wrong WIF key.
bitcoinjs-lib/test/integration/transactions.spec.ts
Lines 252 to 294 in 4af9317
from bitcoinjs-lib.
The redeemScript
is incorrect.
This is how you would create the redeemScript properly.
const p2shP2wpkh = bitcoin.payments.p2sh({
redeem: bitcoin.payments.p2wpkh({
pubkey: keyPair.publicKey,
network,
}),
network,
});
const redeemScript = p2shP2wpkh.redeem.output;
const previousScriptPubkey = p2shP2wpkh.output; // This is the witnessUtxo.script data. You hard coded it, but this is how you would calculate it.
from bitcoinjs-lib.
Thanks @junderw for supporting me.
now i have put those two value here and my whole code is:-
async function createTransaction()
{
const keyPair = ECPair.fromWIF(privateKeyWIF, network);
const psbt = new bitcoin.Psbt({ network });
const p2shP2wpkh = bitcoin.payments.p2sh({
redeem: bitcoin.payments.p2wpkh({
pubkey: keyPair.publicKey,
network,
}),
network,
});
const redeemScript = p2shP2wpkh.redeem.output;
const previousScriptPubkey = p2shP2wpkh.output;
psbt.addInput({
hash: "155009fe07a45086066843faf90dcb5d541bf7d77d7e3dd0db7707e13947d314",
index: 1,
witnessUtxo: {
script: Buffer.from(previousScriptPubkey, 'hex'),
value: 86141,
},
redeemScript: Buffer.from(redeemScript, 'hex'),
});
psbt.addOutput({
address: receiverAddress,
value: 70000,
});
psbt.signInput(0, keyPair);
psbt.finalizeInput(0);
const tx = psbt.extractTransaction();
console.log(tx.toHex());
//return tx.toHex();
}
After compling it i have get below hex
0200000000010114d34739e10777dbd03d7e7dd7f71b545dcb0df9fa4368068650a407fe095015010000001716001452d9f4cf06defccfacfa0307cd7bab1ac47d4bd5ffffffff01701101000000000017a9146573dbcd80b8b054eca401147c4c4bc19b00b9558702483045022100a76c902171a9ae53b06f0723d0e9ea689fac031b61f5075d2ccaa52956230fe502203000cf23b3633c33ba1c236e54e2d2558c2af263dcf898fbf4ab5d6c7f4ff95601210209ccdaa6f3f34ffeeef4365bdc64c30b3c33887cecf1ac429172565d02885d0500000000
i try to broadcast it and facing a error that is-
Error validating transaction: Error running script for input 0 referencing 155009fe07a45086066843faf90dcb5d541bf7d77d7e3dd0db7707e13947d314 at 1: Script was NOT verified successfully..
Please tell me i am doing any mistake here ?
from bitcoinjs-lib.
Don’t pass Buffers into Buffer.from
they are already Buffers
from bitcoinjs-lib.
Dear @junderw
I have pass Buffers direct like it
witnessUtxo: {
script: previousScriptPubkey,
value: 86141,
},
redeemScript: redeemScript,
But still facing same issue, please provide me reference for any basic transaction example where i could put WIF pvt key, TxID, Vout to get transaction Hex.. or suggest any updation for it so it could be error free.
thanks
from bitcoinjs-lib.
Dear @junderw
Many many thanks my issue has solved :)
from bitcoinjs-lib.
Related Issues (20)
- Stack and Script visualize HOT 1
- [Question] How to watch blocks like viem.watchBlocks? HOT 3
- toASM throws TypeError: Cannot read properties of null (reading 'map') HOT 4
- offline signing with multiple utxos from different addresses HOT 3
- Question: Bitcoinjs-lib will support Testnet4? HOT 4
- Function to determine address type by address or redeemScript HOT 1
- Can't use tiny-secp256k1 (required by bitcoinjs-lib for ECC) in browser: fs_1.readFileSync is not a function HOT 7
- Psbt.signInput Passed but Broadcast Failure with msg `non-mandatory-script-verify-flag (Witness program hash mismatch)` HOT 5
- How to make taproot P2TR multiSig wallet HOT 3
- Error when deserializing a PSBT HOT 6
- Getting non-mandatory-script-verify-flag (Invalid Schnorr signature) on taproot key path spending with LEDGER nano HOT 1
- Tesnet: is not a valid bitcoin testnet address HOT 3
- Faucet for P2PKH testnet HOT 2
- No inputs were signed HOT 6
- Error: Need validator function to validate signatures HOT 11
- Invalid network version from bitcoin.ECPair.fromWIF(senderPrivateKey, network) - bitcoinjs-lib ^5.2.0 HOT 1
- How to combine Blockcypher /txs/new API to do RBF HOT 22
- non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation) HOT 2
- How to sign Psbt with P2WSH(P2MS) Script? HOT 1
- How to get exact tx fee HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bitcoinjs-lib.