MultiversX Tracker is Live!

Easy bitcoin script help (JS)

Bitcoin Reddit

More / Bitcoin Reddit 41 Views

Easy bitcoin script help (JS)

Hello people,

I am a dev trying tonight to write an execute a very stupid bitcoin script.

const bitcoin = require('bitcoinjs-lib'); const NETWORK = bitcoin.networks.regtest; const script = [ bitcoin.script.number.encode(1), bitcoin.script.number.encode(1), bitcoin.opcodes.OP_ADD, bitcoin.script.number.encode(2), bitcoin.opcodes.OP_EQUAL, ]; // Compile the script used in the creation of the P2WSH address const compiledScript = bitcoin.script.compile(script); console.log('Compiled script:', compiledScript.toString('hex')); // Derive the address from the script const p2wsh = bitcoin.payments.p2wsh({ redeem: { output: compiledScript, network: NETWORK }, network: NETWORK }); console.log(`The script address: ${p2wsh.address}`); // Transaction details const TX_HASH = '24fa9287953df68e3aebf53c577eda7ac58f09feb041c4124127a22ca2aafccc'; const TX_INDEX = 0; // Output index const TX_OUTPUT_AMOUNT = 10_000; // Amount in satoshis, adjust accordingly to your scenario const RECEIVER = 'bcrt1q6qzr78af963ztaduu7s4srad6llretjt2u2zet'; // Create a new PSBT const txb = new bitcoin.Psbt({ network: NETWORK }); txb.addInput({ hash: TX_HASH, index: TX_INDEX, witnessUtxo: { script: Buffer.from('0020b819f9dfd2e879473f602e4e6b603872dd439e1cdd0d793288d65f41a86ecc3c', 'hex'), // Script from the transaction hex value: TX_OUTPUT_AMOUNT, // This needs to be the exact amount of the UTXO }, witnessScript: compiledScript // This needs to be provided if the UTXO was locked with a P2WSH }); txb.addOutput({ address: RECEIVER, value: TX_OUTPUT_AMOUNT - 2500, // Subtract the desired fee }); // Ready the PSBT to be signed console.log('PSBT for Bitcoin Core:', txb.toBase64()); 

When I try to sign the PSBT with Core I get this view, anyone knows what I am missing?


submitted by /u/neo69654
[link] [comments]

Get BONUS $200 for FREE!

You can get bonuses upto $100 FREE BONUS when you:
πŸ’° Install these recommended apps:
πŸ’² SocialGood - 100% Crypto Back on Everyday Shopping
πŸ’² xPortal - The DeFi For The Next Billion
πŸ’² CryptoTab Browser - Lightweight, fast, and ready to mine!
πŸ’° Register on these recommended exchanges:
🟑 Binance🟑 Bitfinex🟑 Bitmart🟑 Bittrex🟑 Bitget
🟑 CoinEx🟑🟑🟑 Huobi🟑 Kucoin.